Downloads · 30 days
14
2% of all-time downloads
nicolay-r/flan-t5-emotion-cause-thor-base
flan-t5-emotion-cause-thor-base is a text generation model from nicolay-r. Use it when you need the model to write or continue text. It is set up for transformers. The card lists the license as mit.
Update February 23 2025: 🔥 BATCHING MODE SUPPORT. See 🌌 Flan-T5 provider for bulk-chain project. Test is available here
Downloads · 30 days
14
2% of all-time downloads
All-time downloads
853
Public
Parameters
248M
496 MB on disk
Likes
1
Public
Click a slice to open those files.
.safetensors495 MB · 99%
From the Hugging Face model README
Update February 23 2025: 🔥 BATCHING MODE SUPPORT. See 🌌 Flan-T5 provider for bulk-chain project. Test is available here
This model represent a fine-tuned version on the Emotion-Cause Analysis in Context (ECAC) data and aimed at answering the following problems:
This model choses the answers according to the following list of choices:
["anger", "disgust", "fear", "joy", "sadness", "surprise", "neutral"]
This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
Please proceed the following example that purely relies on tranformers and torch.
This example could be found on google colab at the related Github repo page
You can still use the code below for a custom start by being independent from the THoR engine.
Here are the 4 steps for direct model use:
def ask(prompt):
inputs = tokenizer(prompt, return_tensors="pt", add_special_tokens=False)
inputs.to(device)
output = model.generate(**inputs, max_length=320, temperature=1)
return tokenizer.batch_decode(output, skip_special_tokens=True)[0]
def emotion_extraction_chain(context, target):
# Setup labels.
labels_list = ["anger", "disgust", "fear", "joy", "sadness", "surprise", "neutral"]
# Setup Chain-of-Thought
step1 = f"Given the conversation {context}, which text spans are possibly causes emotion on {target}?"
span = ask(step1)
step2 = f"{step1}. The mentioned text spans are about {span}. Based on the common sense, what " + f"is the implicit opinion towards the mentioned text spans that causes emotion on {target}, and why?"
opinion = ask(step2)
step3 = f"{step2}. The opinion towards the text spans that causes emotion on {target} is {opinion}. " + f"Based on such opinion, what is the emotion state of {target}?"
emotion_state = ask(step3)
step4 = f"{step3}. The emotion state is {emotion_state}. Based on these contexts, summarize and return the emotion cause only." + "Choose from: {}.".format(", ".join(labels_list))
# Return the final response.
return ask(step4)
device, model and tokenizer as follows:from transformers import AutoTokenizer, T5ForConditionalGeneration
model_path = "nicolay-r/flan-t5-emotion-cause-thor-base"
device = "cuda:0"
model = T5ForConditionalGeneration.from_pretrained(model_path)
tokenizer = AutoTokenizer.from_pretrained(model_path)
model.to(device)
# setup history context (conv_turn_1)
conv_turn_1 = "John: ohh you made up!"
# setup utterance.
conv_turn_2 = "Jake: yaeh, I could not be mad at him for too long!"
context = conv_turn_1 + conv_turn_2
# Target is considered as the whole conv-turn mentioned in context.
target = conv_turn_2
flant5_response = emotion_extraction_chain(context, target)
print(f"Emotion state of the speaker of `{target}` is: {flant5_response}")
The response is as follows:
Emotion state of the speaker of
Jake: yaeh, I could not be mad at him for too long!is: anger
The details of the downstream usage could be found in the related section of the project on Github or within the related notebook on GoogleColab
This model represent a fine-tuned version of the Flan-T5 on ECAC-2024 competition dataset of conversations from the F.R.I.E.N.D.S. TV Show. Since dataset represent three-scale output answers ["anger", "disgust", "fear", "joy", "sadness", "surprise", "neutral"] the behavior in general might be biased to this particular task.
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
Simply follow the Direct Use secion or proceed with the following GoogleColab notebook.
We purely rely on the data provided by ECAC-2024 competition organizers.
Here is the related information from the github repository.
And here is the code related to data convesations preparation intented for compiling input data.
Model has been fine-tuned in two stages:

[More Information Needed]
[More Information Needed]
Results are depicted in image below in a gray-highlighted row.
