Views
No views yet
| Emotion | Sentiment | F1 | Cohen’s Kappa |
|---|---|---|---|
| admiration | positive | 0.64 | 0.601 |
| amusement | positive | 0.78 | 0.767 |
| anger | negative | 0.38 | 0.358 |
| annoyance | negative | 0.27 | 0.229 |
| approval | positive | 0.34 | 0.293 |
| caring | positive | 0.38 | 0.365 |
| confusion | negative | 0.40 | 0.378 |
| curiosity | positive | 0.51 | 0.486 |
| desire | positive | 0.39 | 0.387 |
| disappointment | negative | 0.19 | 0.170 |
| disapproval | negative | 0.32 | 0.286 |
| disgust | negative | 0.41 | 0.395 |
| embarrassment | negative | 0.37 | 0.367 |
| excitement | positive | 0.35 | 0.339 |
| fear | negative | 0.59 | 0.584 |
| gratitude | positive | 0.89 | 0.882 |
| grief | negative | 0.31 | 0.307 |
| joy | positive | 0.51 | 0.499 |
| love | positive | 0.73 | 0.721 |
| nervousness | negative | 0.28 | 0.276 |
| optimism | positive | 0.53 | 0.512 |
| pride | positive | 0.30 | 0.299 |
| realization | positive | 0.17 | 0.150 |
| relief | positive | 0.27 | 0.266 |
| remorse | negative | 0.55 | 0.545 |
| sadness | negative | 0.50 | 0.488 |
| surprise | neutral | 0.53 | 0.514 |
| neutral | neutral | 0.60 | 0.410 |
1import pandas as pd
2from transformers import pipeline
3
4# Example texts
5texts = [
6 "Ich fühle mich heute exzellent! Ich freue mich schon auf die Zeit mit meinen Freunden.",
7 "Ich bin heute total müde und hab auf gar nichts Lust.",
8 "Boah, das ist mir so peinlich.",
9 "Hahaha, das ist so lustig."
10]
11
12# Create DataFrame
13df = pd.DataFrame({"text": texts})
14
15# Set labels
16emotion_labels = ['admiration', 'amusement', 'anger', 'annoyance', 'approval', 'caring',
17 'confusion', 'curiosity', 'desire', 'disappointment', 'disapproval', 'disgust',
18 'embarrassment', 'excitement', 'fear', 'gratitude', 'grief', 'joy', 'love',
19 'nervousness', 'optimism', 'pride', 'realization', 'relief', 'remorse',
20 'sadness', 'surprise', 'neutral']
21
22# Load emotion classifier pipeline
23emo_pipe = pipeline(
24 "text-classification",
25 model="ChrisLalk/German-Emotions", # or local model path
26 tokenizer="ChrisLalk/German-Emotions",
27 return_all_scores=True,
28 truncation=True,
29 top_k=None
30)
31
32# Infer the probability scores
33prob_results = []
34for text in df["text"]:
35 scores = emo_pipe(text)[0]
36 result_dict = {item["label"]: item["score"] for item in scores}
37 result_dict_sort = {label: result_dict[label] for label in emotion_labels}
38 prob_results.append(result_dict_sort)
39
40# Add emotion scores to DataFrame
41df_probs = pd.DataFrame(prob_results, columns=emotion_labels)
42df_final = pd.concat([df, df_probs], axis=1)