Views
No views yet

1>>> import torch
2>>> from transformers import pipeline
3>>> model_name = "roberta-large-emopillars-contextual"
4>>> threshold = 0.5
5>>> emotions = [
6>>> "admiration", "amusement", "anger", "annoyance", "approval", "caring", "confusion",
7>>> "curiosity", "desire", "disappointment", "disapproval", "disgust", "embarrassment",
8>>> "excitement", "fear", "gratitude", "grief", "joy", "love", "nervousness", "optimism",
9>>> "pride", "realization", "relief", "remorse", "sadness", "surprise", "neutral"
10>>> ]
11>>> label_to_emotion = dict(zip(list(range(len(emotions))), emotions))
12>>> device = torch.device("cuda" if torch.cuda.is_available() else "CPU")
13>>> pipe = pipeline("text-classification", model=model_name, truncation=True,
14>>> return_all_scores=True, device=-1 if device.type=="cpu" else 0)
15>>> # input in a format f"{context} {character}: \"{utterance}\""
16>>> utterances_in_contexts = [
17>>> "A user watched a video of a musical performance on YouTube. This user expresses an opinion and thoughts. User: \"Ok is it just me or is anyone else getting goosebumps too???\"",
18>>> "User: \"Sorry\", Conversational agent: \"Sorry for what??\", User: \"Don’t know what to do\""
19>>> ]
20>>> outcome = pipe(utterances_in_contexts)
21>>> dominant_classes = [
22>>> [prediction for prediction in example if prediction['score'] >= threshold]
23>>> for example in outcome
24>>> ]
25>>> for example in dominant_classes:
26>>> print(", ".join([
27>>> "%s: %.2lf" % (label_to_emotion[int(prediction['label'])], prediction['score'])
28>>> for prediction in sorted(example, key=lambda x: x['score'], reverse=True)
29>>> ]))
30surprise: 0.99, amusement: 0.87, curiosity: 0.60, nervousness: 0.58
31confusion: 0.97, nervousness: 0.76, embarrassment: 0.65| class | precision | recall | f1-score | support |
|---|---|---|---|---|
| admiration | 0.72 | 0.68 | 0.70 | 635 |
| amusement | 0.79 | 0.63 | 0.70 | 211 |
| anger | 0.86 | 0.82 | 0.84 | 1155 |
| annoyance | 0.80 | 0.76 | 0.78 | 865 |
| approval | 0.58 | 0.42 | 0.49 | 250 |
| caring | 0.66 | 0.60 | 0.63 | 485 |
| confusion | 0.76 | 0.78 | 0.77 | 1283 |
| curiosity | 0.83 | 0.79 | 0.81 | 780 |
| desire | 0.80 | 0.75 | 0.77 | 864 |
| disappointment | 0.79 | 0.80 | 0.80 | 1264 |
| disapproval | 0.55 | 0.47 | 0.51 | 445 |
| disgust | 0.73 | 0.60 | 0.66 | 320 |
| embarrassment | 0.65 | 0.50 | 0.57 | 116 |
| excitement | 0.74 | 0.71 | 0.73 | 685 |
| fear | 0.87 | 0.85 | 0.86 | 990 |
| gratitude | 0.79 | 0.74 | 0.76 | 155 |
| grief | 0.79 | 0.71 | 0.75 | 133 |
| joy | 0.80 | 0.78 | 0.79 | 668 |
| love | 0.70 | 0.61 | 0.65 | 254 |
| nervousness | 0.81 | 0.80 | 0.80 | 1368 |
| optimism | 0.82 | 0.76 | 0.79 | 506 |
| pride | 0.85 | 0.82 | 0.83 | 497 |
| realization | 0.74 | 0.57 | 0.64 | 120 |
| relief | 0.76 | 0.67 | 0.71 | 211 |
| remorse | 0.59 | 0.53 | 0.56 | 206 |
| sadness | 0.80 | 0.79 | 0.79 | 922 |
| surprise | 0.80 | 0.78 | 0.79 | 852 |
| neutral | 0.67 | 0.57 | 0.61 | 392 |
| micro avg | 0.78 | 0.74 | 0.76 | 16632 |
| macro avg | 0.75 | 0.69 | 0.72 | 16632 |
| weighted avg | 0.78 | 0.74 | 0.76 | 16632 |
| samples avg | 0.79 | 0.76 | 0.75 | 16632 |
| task | precision | recall | f1-score |
|---|---|---|---|
| EmoContext (dev) | 0.81 | 0.83 | 0.82 |
| EmoContext (test) | 0.76 | 0.78 | 0.77 |
1@misc{shvets2025emopillarsknowledgedistillation,
2 title={Emo Pillars: Knowledge Distillation to Support Fine-Grained Context-Aware and Context-Less Emotion Classification},
3 author={Alexander Shvets},
4 year={2025},
5 eprint={2504.16856},
6 archivePrefix={arXiv},
7 primaryClass={cs.CL},
8 url={https://arxiv.org/abs/2504.16856}
9}