File size: 8,055 Bytes
2c87bdb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
093fd17
2c87bdb
 
 
 
 
 
 
 
 
 
 
 
093fd17
 
2c87bdb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
093fd17
f301641
093fd17
2c87bdb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
093fd17
2c87bdb
 
 
 
 
 
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
---
license: mit
language:
  - en
  - hi
library_name: transformers
pipeline_tag: text-classification
tags:
  - emotion-detection
  - distilbert
  - sentiment-analysis
  - mental-health
  - emotion-classification
  - text-classification
  - transformers
  - pytorch
  - hinglish
base_model: distilbert-base-uncased
datasets:
  - google-research-datasets/go_emotions
metrics:
  - accuracy
  - f1
  - precision
  - recall
model-index:
  - name: raven-emotion-distilbert
    results:
      - task:
          type: text-classification
          name: Emotion Classification
        dataset:
          name: Custom Indian + International Dataset
          type: custom
        metrics:
          - name: Accuracy
            type: accuracy
            value: 0.9762
          - name: F1
            type: f1
            value: 0.9762
          - name: Precision
            type: precision
            value: 0.9762
          - name: Recall
            type: recall
            value: 0.9762
      - task:
          type: text-classification
          name: Emotion Classification
        dataset:
          name: GoEmotions (Balanced 300 samples)
          type: google-research-datasets/go_emotions
        metrics:
          - name: Accuracy
            type: accuracy
            value: 0.7733
          - name: F1
            type: f1
            value: 0.7724
widget:
  - text: "I'm so stressed about my exam tomorrow, I can't sleep"
    example_title: Anxious
  - text: "Just got promoted at work, feeling on top of the world!"
    example_title: Happy
  - text: "I don't understand why this code keeps throwing errors"
    example_title: Confused
  - text: "I lost my best friend over a stupid argument"
    example_title: Sad
  - text: "This is absolutely unacceptable, I'm furious right now"
    example_title: Angry
  - text: "Nothing much going on today, just chilling at home"
    example_title: Neutral
---

# Raven Emotion DistilBERT

A fine-tuned **DistilBERT** model for 6-class emotion classification, built for [Raven AI](https://raven-ai-new.streamlit.app) β€” an emotionally aware AI assistant.

This model classifies text into **6 emotions**: `happy`, `sad`, `anxious`, `angry`, `confused`, `neutral`.

## Performance

| Model / Method | Dataset | Accuracy | F1 Score |
|---|---|---|---|
| Zero-Shot LLM (LLama 3.3 70B) | GoEmotions | 66.67% | 0.6691 |
| Few-Shot LLM (LLama 3.3 70B) | GoEmotions | 73.00% | 0.7331 |
| **This model** (initial training) | GoEmotions | **77.33%** | **0.7724** |
| **This model** (after domain adaptation) | Custom Dataset | **97.62%** | **0.9762** |

**Key result**: This 67M parameter model outperforms a 70B parameter LLM by +4.33% on emotion classification, proving that task-specific fine-tuning beats general-purpose prompting.

## Quick Start

```python
from transformers import pipeline

classifier = pipeline("text-classification", model="Fynman-stack/raven-emotion-distilbert", top_k=None)

result = classifier("I'm so stressed about my exam tomorrow")
print(result)
# [[{'label': 'anxious', 'score': 0.95}, {'label': 'sad', 'score': 0.02}, ...]]
```

Or load the model directly:

```python
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch

tokenizer = AutoTokenizer.from_pretrained("Fynman-stack/raven-emotion-distilbert")
model = AutoModelForSequenceClassification.from_pretrained("Fynman-stack/raven-emotion-distilbert")

EMOTIONS = ["happy", "sad", "anxious", "angry", "confused", "neutral"]

def detect_emotion(text):
    inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=128, padding=True)
    with torch.no_grad():
        outputs = model(**inputs)
    return EMOTIONS[torch.argmax(outputs.logits, dim=1).item()]

print(detect_emotion("I just cleared my exam!"))  # happy
print(detect_emotion("I'm furious at this situation"))  # angry
```

## Labels

| ID | Label | Description |
|---|---|---|
| 0 | `happy` | Joy, excitement, gratitude, love, pride, amusement |
| 1 | `sad` | Sadness, grief, disappointment, remorse |
| 2 | `anxious` | Fear, nervousness, worry, stress |
| 3 | `angry` | Anger, annoyance, frustration, disgust |
| 4 | `confused` | Confusion, surprise, curiosity, realization |
| 5 | `neutral` | Neutral, calm, indifferent |

## Training Details

### Phase 1: Initial Training on GoEmotions

- **Base model**: `distilbert-base-uncased` (67M parameters)
- **Dataset**: [GoEmotions](https://huggingface.co/datasets/google-research-datasets/go_emotions) β€” Google's 28-emotion dataset, mapped to 6 categories
- **Epochs**: 3 | **Batch size**: 16 | **Learning rate**: 2e-5 | **Optimizer**: AdamW (weight decay 0.01)

| Epoch | Train Loss | Val Accuracy | Val F1 |
|---|---|---|---|
| 1 | 1.1599 | 66.93% | 0.6671 |
| 2 | 0.8031 | 67.37% | 0.6737 |
| 3 | 0.6494 | 67.64% | 0.6747 |

### Phase 2: Domain Adaptation on Custom Dataset

The model was further trained on ~12,343 samples of Indian English, Hinglish (Hindi-English), American English, and British English conversational text to adapt it for real-world student conversations.

- **Learning rate**: 5e-6 (reduced to prevent catastrophic forgetting)
- **Early stopping**: Patience of 2 epochs
- **Warmup**: 10% of total training steps
- **Gradient clipping**: 1.0

| Epoch | Train Loss | Val Accuracy | Val F1 |
|---|---|---|---|
| 1 | 0.6765 | 90.99% | 0.9093 |
| 2 | 0.2549 | 93.15% | 0.9311 |
| 3 | 0.1625 | 94.08% | 0.9406 |
| 4 | 0.1147 | 94.46% | 0.9444 |
| 5 | 0.0940 | 94.65% | 0.9463 |

**Domain adaptation impact**: Accuracy jumped from 64.38% to 97.62% (+33.24%) on the target domain.

## GoEmotions Label Mapping

The original 28 GoEmotions labels were mapped to 6 categories:

| Raven Label | GoEmotions Labels |
|---|---|
| `happy` | joy, amusement, excitement, gratitude, love, optimism, pride, relief, admiration, approval, caring |
| `sad` | sadness, grief, disappointment, remorse, embarrassment |
| `anxious` | fear, nervousness |
| `angry` | anger, annoyance, disgust |
| `confused` | confusion, surprise, realization, curiosity |
| `neutral` | neutral, desire |

## Use Cases

- **Emotionally aware chatbots** β€” Adjust response tone based on user emotion
- **Mental health applications** β€” Detect distress, anxiety, or anger in user messages
- **Customer support** β€” Route frustrated or confused customers to appropriate agents
- **Social media monitoring** β€” Track emotional sentiment across conversations
- **Education platforms** β€” Detect student frustration or confusion in real-time

## About Raven AI

This model powers [Raven AI](https://raven-ai-new.streamlit.app), an emotionally aware AI assistant that adapts its tone, persona, and response style based on detected user emotion. Raven includes crisis detection, multi-chat management, image understanding, voice input, document processing, and 20+ other features.

- **Try it live (HuggingFace Space)**: [huggingface.co/spaces/Fynman-stack/raven-ai](https://huggingface.co/spaces/Fynman-stack/raven-ai)
- **Streamlit Cloud**: [raven-ai-new.streamlit.app](https://raven-ai-new.streamlit.app)
- **GitHub**: [github.com/Fynman-stack/raven-ai](https://github.com/Fynman-stack/raven-ai)

## Model Architecture

- **Base**: DistilBERT (6 layers, 12 attention heads, 768 hidden dim)
- **Parameters**: 67M
- **Task head**: Sequence classification (6 classes)
- **Max sequence length**: 128 tokens
- **Format**: Safetensors (FP32)

## Limitations

- Trained primarily on English and Hinglish text β€” may not generalize well to other languages
- Emotion categories are coarse-grained (6 classes) β€” may miss nuanced emotional states
- Performance on formal/academic text may differ from conversational text
- Not a diagnostic tool β€” should not be used as a substitute for professional mental health assessment

## Citation

```bibtex
@misc{raha2026raven,
  title={Raven AI: An Emotionally Aware AI Assistant with Fine-tuned DistilBERT},
  author={Soumyadip Raha},
  year={2026},
  url={https://huggingface.co/Fynman-stack/raven-emotion-distilbert}
}
```

## License

MIT