File size: 5,793 Bytes
e727f4c
cbea9fe
 
e727f4c
cbea9fe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e727f4c
cbea9fe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
---
language:
- en
license: mit
library_name: transformers
pipeline_tag: text-classification
tags:
- emotion-classification
- natural-language-processing
- roberta
- transformers
- pytorch
- goemotions
- ekman-emotions
- sentiment-analysis
- text-classification
datasets:
- go_emotions
metrics:
- accuracy
- precision
- recall
- f1
model-index:
- name: EmotionSense
  results:
  - task:
      type: text-classification
      name: Emotion Classification
    dataset:
      name: Customized GoEmotions (Ekman Mapping)
      type: go_emotions
    metrics:
    - type: Accuracy
      value: 0.903
    - type: Precision
      value: 0.901
    - type: Recall
      value: 0.894
    - type: Weighted F1
      value: 0.891
---

# 🧠 EmotionSense
### Fine-Grained Emotion Classification using RoBERTa

<p align="center">

πŸ€— <b>Hugging Face</b> β€’ πŸ”₯ <b>RoBERTa</b> β€’ πŸ’¬ <b>Emotion AI</b> β€’ πŸš€ <b>Production Ready</b>

</p>

EmotionSense is a **RoBERTa-base** model fine-tuned for **emotion classification**. The model predicts **seven human emotions** from English text using a cleaned and simplified version of the GoEmotions dataset.

Unlike the original GoEmotions dataset containing 28 fine-grained emotion labels, this work reorganizes emotions according to the **Ekman Emotion Framework**, improving interpretability while maintaining strong predictive performance.

---

# ✨ Highlights

- πŸ”₯ Fine-tuned **RoBERTa-base**
- 🧠 Context-aware emotion recognition
- πŸ“Š Class-balanced training using Weighted Cross Entropy Loss
- ⚑ Early stopping for improved generalization
- 🎯 Optimized using Weighted F1 Score
- πŸ€— Compatible with Hugging Face Transformers Pipeline

---

# 🎯 Supported Emotion Classes

| Label | Description |
|--------|------------|
| πŸ˜€ Joy | Positive emotions, happiness, gratitude, love |
| 😒 Sadness | Grief, disappointment, remorse |
| 😑 Anger | Anger, annoyance, disapproval |
| 😨 Fear | Fear and nervousness |
| 🀒 Disgust | Disgust |
| 😲 Surprise | Surprise, curiosity, realization |
| 😐 Neutral | Emotionally neutral statements |

---

# πŸ“š Dataset

The model was trained using a **customized version of the GoEmotions dataset**.

The original dataset contains approximately **58,000 Reddit comments** annotated with **28 fine-grained emotion labels**.

To improve annotation quality:

- βœ” Majority Voting was applied.
- βœ” Samples without annotator agreement were removed.
- βœ” Multi-label ambiguity was eliminated.
- βœ” Fine-grained emotions were mapped into **Ekman's seven universal emotion categories**.

### Emotion Mapping

| Ekman Category | Original GoEmotions Labels |
|---------------|----------------------------|
| Anger | anger, annoyance, disapproval |
| Disgust | disgust |
| Fear | fear, nervousness |
| Joy | joy, amusement, admiration, approval, caring, desire, excitement, gratitude, love, optimism, pride, relief |
| Sadness | sadness, disappointment, embarrassment, grief, remorse |
| Surprise | surprise, realization, curiosity, confusion |
| Neutral | neutral |

---

# πŸ— Model Architecture

| Property | Value |
|----------|------|
| Base Model | RoBERTa-base |
| Framework | Hugging Face Transformers |
| Language | English |
| Task | Emotion Classification |
| Max Sequence Length | 128 |
| Batch Size | 16 |
| Learning Rate | 2e-5 |
| Epochs | 5 |
| Optimizer | AdamW |
| Loss Function | Weighted Cross Entropy |
| Early Stopping | Enabled |

---

# πŸ“ˆ Performance

EmotionSense achieved the best performance among all evaluated models.

| Model | Accuracy | Weighted F1 |
|-------|---------:|------------:|
| Logistic Regression | 0.59 | 0.57 |
| Random Forest | 0.61 | 0.59 |
| Linear SVM | 0.63 | 0.61 |
| DistilBERT | 0.68 | 0.67 |
| **EmotionSense (RoBERTa)** | **0.903** | **0.891** |

### Final Evaluation

| Metric | Score |
|---------|------:|
| Accuracy | **90.3%** |
| Precision | **90.1%** |
| Recall | **89.4%** |
| Weighted F1 | **89.1%** |

---

# πŸš€ Quick Start

Install Transformers

```bash
pip install transformers torch
```

Load the model

```python
from transformers import pipeline

classifier = pipeline(
    "text-classification",
    model="SobanHM/EmotionSense"
)

classifier("I finally got my dream job today!")
```

Example Output

```python
[
    {
        "label": "joy",
        "score": 0.997
    }
]
```

---

# πŸ’‘ Applications

- Conversational AI
- Emotion-aware Chatbots
- Mental Health Support Systems
- Customer Feedback Analysis
- Social Media Analytics
- Human-Computer Interaction
- Intelligent Virtual Assistants

---

# ⚠ Limitations

- Supports English language only.
- Performance may decrease on domain-specific text.
- Sarcasm and irony remain challenging.
- Emotion recognition is probabilistic and should not be used for clinical diagnosis or psychological assessment.

---

# πŸ‘¨β€πŸ’» About the Author

**Soban Hussain**

AI Engineer β€’ Machine Learning Researcher β€’ Computer Vision & NLP

πŸ€— **Hugging Face:** https://huggingface.co/SobanHM

πŸ’Ό **LinkedIn:** https://www.linkedin.com/in/sobanhussain

πŸ’» **GitHub:** https://github.com/SobanHM

---

# πŸ™Œ Acknowledgements

This project was built using:

- Hugging Face Transformers
- PyTorch
- GoEmotions Dataset
- RoBERTa

Special thanks to the open-source AI community for providing exceptional tools and resources.

---

# πŸ“– Citation

If you use this model in your research, please cite both this repository and the GoEmotions dataset.

```bibtex
@inproceedings{demszky2020goemotions,
  title={GoEmotions: A Dataset of Fine-Grained Emotions},
  author={Demszky, Dorottya and others},
  booktitle={Proceedings of ACL},
  year={2020}
}
```

---

## ⭐ If you find this model useful, consider giving it a Like on Hugging Face and sharing your feedback!