Views
No views yet

1>>> import torch
2>>> from transformers import pipeline
3>>> model_name = "roberta-large-emopillars-contextless-isear"
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>>> emotion_to_isear = {
13>>> "anger": "anger",
14>>> "disgust": "disgust",
15>>> "fear": "fear",
16>>> "sadness": "sadness",
17>>> "joy": "joy",
18>>> "embarrassment": "shame",
19>>> "remorse": "guilt"
20>>> }
21>>> device = torch.device("cuda" if torch.cuda.is_available() else "CPU")
22>>> pipe = pipeline("text-classification", model=model_name, truncation=True,
23>>> return_all_scores=True, device=-1 if device.type=="cpu" else 0)
24>>> # input in a format f"{text}"
25>>> utterances = [
26>>> "Ok is it just me or is anyone else getting goosebumps too???",
27>>> "Don’t know what to do",
28>>> "When a car is overtaking another and I am forced to drive off the road."
29>>> ]
30>>> outcome = pipe(utterances)
31>>> dominant_classes = [
32>>> [prediction for prediction in example if prediction['score'] >= threshold and
33>>> label_to_emotion[int(prediction['label'])] in emotion_to_isear]
34>>> for example in outcome
35>>> ]
36>>> for example in dominant_classes:
37>>> print(", ".join([
38>>> "%s: %.2lf" % (emotion_to_isear[label_to_emotion[int(prediction['label'])]], prediction['score'])
39>>> for prediction in sorted(example, key=lambda x: x['score'], reverse=True)
40>>> ]))
41fear: 0.90
42sadness: 0.91
43anger: 1.00| class | precision | recall | f1-score | support |
|---|---|---|---|---|
| anger | 0.67 | 0.65 | 0.66 | 209 |
| disgust | 0.75 | 0.72 | 0.74 | 232 |
| fear | 0.88 | 0.81 | 0.84 | 205 |
| sadness | 0.71 | 0.78 | 0.74 | 198 |
| joy | 0.93 | 0.93 | 0.93 | 219 |
| shame | 0.64 | 0.66 | 0.65 | 222 |
| guilt | 0.75 | 0.72 | 0.73 | 218 |
| micro avg | 0.76 | 0.75 | 0.76 | 1503 |
| macro avg | 0.76 | 0.75 | 0.76 | 1503 |
| weighted avg | 0.76 | 0.75 | 0.76 | 1503 |
| samples avg | 0.75 | 0.75 | 0.75 | 1503 |
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}