Text Classification
Transformers
Safetensors
PyTorch
English
Hindi
distilbert
emotion-detection
sentiment-analysis
mental-health
emotion-classification
hinglish
Eval Results (legacy)
text-embeddings-inference
Instructions to use Fynman-stack/raven-emotion-distilbert with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Fynman-stack/raven-emotion-distilbert with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="Fynman-stack/raven-emotion-distilbert")# Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("Fynman-stack/raven-emotion-distilbert") model = AutoModelForSequenceClassification.from_pretrained("Fynman-stack/raven-emotion-distilbert") - Notebooks
- Google Colab
- Kaggle
Soumyadip Raha commited on
Add model card, weights, and tokenizer
Browse files
README.md
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
- hi
|
| 6 |
+
library_name: transformers
|
| 7 |
+
pipeline_tag: text-classification
|
| 8 |
+
tags:
|
| 9 |
+
- emotion-detection
|
| 10 |
+
- distilbert
|
| 11 |
+
- sentiment-analysis
|
| 12 |
+
- mental-health
|
| 13 |
+
- emotion-classification
|
| 14 |
+
- text-classification
|
| 15 |
+
- transformers
|
| 16 |
+
- pytorch
|
| 17 |
+
- hinglish
|
| 18 |
+
base_model: distilbert-base-uncased
|
| 19 |
+
datasets:
|
| 20 |
+
- google-research-datasets/go_emotions
|
| 21 |
+
metrics:
|
| 22 |
+
- accuracy
|
| 23 |
+
- f1
|
| 24 |
+
- precision
|
| 25 |
+
- recall
|
| 26 |
+
model-index:
|
| 27 |
+
- name: raven-emotion-distilbert
|
| 28 |
+
results:
|
| 29 |
+
- task:
|
| 30 |
+
type: text-classification
|
| 31 |
+
name: Emotion Classification
|
| 32 |
+
dataset:
|
| 33 |
+
name: Custom Indian + International Dataset
|
| 34 |
+
type: custom
|
| 35 |
+
metrics:
|
| 36 |
+
- name: Accuracy
|
| 37 |
+
type: accuracy
|
| 38 |
+
value: 0.9762
|
| 39 |
+
- name: F1
|
| 40 |
+
type: f1
|
| 41 |
+
value: 0.9762
|
| 42 |
+
- name: Precision
|
| 43 |
+
type: precision
|
| 44 |
+
value: 0.9762
|
| 45 |
+
- name: Recall
|
| 46 |
+
type: recall
|
| 47 |
+
value: 0.9762
|
| 48 |
+
- task:
|
| 49 |
+
type: text-classification
|
| 50 |
+
name: Emotion Classification
|
| 51 |
+
dataset:
|
| 52 |
+
name: GoEmotions (Balanced 300 samples)
|
| 53 |
+
type: google-research-datasets/go_emotions
|
| 54 |
+
metrics:
|
| 55 |
+
- name: Accuracy
|
| 56 |
+
type: accuracy
|
| 57 |
+
value: 0.7733
|
| 58 |
+
- name: F1
|
| 59 |
+
type: f1
|
| 60 |
+
value: 0.7724
|
| 61 |
+
widget:
|
| 62 |
+
- text: "I'm so stressed about my exam tomorrow, I can't sleep"
|
| 63 |
+
example_title: Anxious
|
| 64 |
+
- text: "Just got promoted at work, feeling on top of the world!"
|
| 65 |
+
example_title: Happy
|
| 66 |
+
- text: "I don't understand why this code keeps throwing errors"
|
| 67 |
+
example_title: Confused
|
| 68 |
+
- text: "I lost my best friend over a stupid argument"
|
| 69 |
+
example_title: Sad
|
| 70 |
+
- text: "This is absolutely unacceptable, I'm furious right now"
|
| 71 |
+
example_title: Angry
|
| 72 |
+
- text: "Nothing much going on today, just chilling at home"
|
| 73 |
+
example_title: Neutral
|
| 74 |
+
---
|
| 75 |
+
|
| 76 |
+
# Raven Emotion DistilBERT
|
| 77 |
+
|
| 78 |
+
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.
|
| 79 |
+
|
| 80 |
+
This model classifies text into **6 emotions**: `happy`, `sad`, `anxious`, `angry`, `confused`, `neutral`.
|
| 81 |
+
|
| 82 |
+
## Performance
|
| 83 |
+
|
| 84 |
+
| Model / Method | Dataset | Accuracy | F1 Score |
|
| 85 |
+
|---|---|---|---|
|
| 86 |
+
| Zero-Shot LLM (LLama 3.3 70B) | GoEmotions | 66.67% | 0.6691 |
|
| 87 |
+
| Few-Shot LLM (LLama 3.3 70B) | GoEmotions | 73.00% | 0.7331 |
|
| 88 |
+
| **This model** (initial training) | GoEmotions | **77.33%** | **0.7724** |
|
| 89 |
+
| **This model** (after domain adaptation) | Custom Dataset | **97.62%** | **0.9762** |
|
| 90 |
+
|
| 91 |
+
**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.
|
| 92 |
+
|
| 93 |
+
## Quick Start
|
| 94 |
+
|
| 95 |
+
```python
|
| 96 |
+
from transformers import pipeline
|
| 97 |
+
|
| 98 |
+
classifier = pipeline("text-classification", model="SoumyaCodes/raven-emotion-distilbert", top_k=None)
|
| 99 |
+
|
| 100 |
+
result = classifier("I'm so stressed about my exam tomorrow")
|
| 101 |
+
print(result)
|
| 102 |
+
# [[{'label': 'anxious', 'score': 0.95}, {'label': 'sad', 'score': 0.02}, ...]]
|
| 103 |
+
```
|
| 104 |
+
|
| 105 |
+
Or load the model directly:
|
| 106 |
+
|
| 107 |
+
```python
|
| 108 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 109 |
+
import torch
|
| 110 |
+
|
| 111 |
+
tokenizer = AutoTokenizer.from_pretrained("SoumyaCodes/raven-emotion-distilbert")
|
| 112 |
+
model = AutoModelForSequenceClassification.from_pretrained("SoumyaCodes/raven-emotion-distilbert")
|
| 113 |
+
|
| 114 |
+
EMOTIONS = ["happy", "sad", "anxious", "angry", "confused", "neutral"]
|
| 115 |
+
|
| 116 |
+
def detect_emotion(text):
|
| 117 |
+
inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=128, padding=True)
|
| 118 |
+
with torch.no_grad():
|
| 119 |
+
outputs = model(**inputs)
|
| 120 |
+
return EMOTIONS[torch.argmax(outputs.logits, dim=1).item()]
|
| 121 |
+
|
| 122 |
+
print(detect_emotion("I just cleared my exam!")) # happy
|
| 123 |
+
print(detect_emotion("I'm furious at this situation")) # angry
|
| 124 |
+
```
|
| 125 |
+
|
| 126 |
+
## Labels
|
| 127 |
+
|
| 128 |
+
| ID | Label | Description |
|
| 129 |
+
|---|---|---|
|
| 130 |
+
| 0 | `happy` | Joy, excitement, gratitude, love, pride, amusement |
|
| 131 |
+
| 1 | `sad` | Sadness, grief, disappointment, remorse |
|
| 132 |
+
| 2 | `anxious` | Fear, nervousness, worry, stress |
|
| 133 |
+
| 3 | `angry` | Anger, annoyance, frustration, disgust |
|
| 134 |
+
| 4 | `confused` | Confusion, surprise, curiosity, realization |
|
| 135 |
+
| 5 | `neutral` | Neutral, calm, indifferent |
|
| 136 |
+
|
| 137 |
+
## Training Details
|
| 138 |
+
|
| 139 |
+
### Phase 1: Initial Training on GoEmotions
|
| 140 |
+
|
| 141 |
+
- **Base model**: `distilbert-base-uncased` (67M parameters)
|
| 142 |
+
- **Dataset**: [GoEmotions](https://huggingface.co/datasets/google-research-datasets/go_emotions) β Google's 28-emotion dataset, mapped to 6 categories
|
| 143 |
+
- **Epochs**: 3 | **Batch size**: 16 | **Learning rate**: 2e-5 | **Optimizer**: AdamW (weight decay 0.01)
|
| 144 |
+
|
| 145 |
+
| Epoch | Train Loss | Val Accuracy | Val F1 |
|
| 146 |
+
|---|---|---|---|
|
| 147 |
+
| 1 | 1.1599 | 66.93% | 0.6671 |
|
| 148 |
+
| 2 | 0.8031 | 67.37% | 0.6737 |
|
| 149 |
+
| 3 | 0.6494 | 67.64% | 0.6747 |
|
| 150 |
+
|
| 151 |
+
### Phase 2: Domain Adaptation on Custom Dataset
|
| 152 |
+
|
| 153 |
+
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.
|
| 154 |
+
|
| 155 |
+
- **Learning rate**: 5e-6 (reduced to prevent catastrophic forgetting)
|
| 156 |
+
- **Early stopping**: Patience of 2 epochs
|
| 157 |
+
- **Warmup**: 10% of total training steps
|
| 158 |
+
- **Gradient clipping**: 1.0
|
| 159 |
+
|
| 160 |
+
| Epoch | Train Loss | Val Accuracy | Val F1 |
|
| 161 |
+
|---|---|---|---|
|
| 162 |
+
| 1 | 0.6765 | 90.99% | 0.9093 |
|
| 163 |
+
| 2 | 0.2549 | 93.15% | 0.9311 |
|
| 164 |
+
| 3 | 0.1625 | 94.08% | 0.9406 |
|
| 165 |
+
| 4 | 0.1147 | 94.46% | 0.9444 |
|
| 166 |
+
| 5 | 0.0940 | 94.65% | 0.9463 |
|
| 167 |
+
|
| 168 |
+
**Domain adaptation impact**: Accuracy jumped from 64.38% to 97.62% (+33.24%) on the target domain.
|
| 169 |
+
|
| 170 |
+
## GoEmotions Label Mapping
|
| 171 |
+
|
| 172 |
+
The original 28 GoEmotions labels were mapped to 6 categories:
|
| 173 |
+
|
| 174 |
+
| Raven Label | GoEmotions Labels |
|
| 175 |
+
|---|---|
|
| 176 |
+
| `happy` | joy, amusement, excitement, gratitude, love, optimism, pride, relief, admiration, approval, caring |
|
| 177 |
+
| `sad` | sadness, grief, disappointment, remorse, embarrassment |
|
| 178 |
+
| `anxious` | fear, nervousness |
|
| 179 |
+
| `angry` | anger, annoyance, disgust |
|
| 180 |
+
| `confused` | confusion, surprise, realization, curiosity |
|
| 181 |
+
| `neutral` | neutral, desire |
|
| 182 |
+
|
| 183 |
+
## Use Cases
|
| 184 |
+
|
| 185 |
+
- **Emotionally aware chatbots** β Adjust response tone based on user emotion
|
| 186 |
+
- **Mental health applications** β Detect distress, anxiety, or anger in user messages
|
| 187 |
+
- **Customer support** β Route frustrated or confused customers to appropriate agents
|
| 188 |
+
- **Social media monitoring** β Track emotional sentiment across conversations
|
| 189 |
+
- **Education platforms** β Detect student frustration or confusion in real-time
|
| 190 |
+
|
| 191 |
+
## About Raven AI
|
| 192 |
+
|
| 193 |
+
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.
|
| 194 |
+
|
| 195 |
+
- **Live app**: [raven-ai-new.streamlit.app](https://raven-ai-new.streamlit.app)
|
| 196 |
+
- **GitHub**: [github.com/Soumyacodes1/raven-ai](https://github.com/Soumyacodes1/raven-ai)
|
| 197 |
+
|
| 198 |
+
## Model Architecture
|
| 199 |
+
|
| 200 |
+
- **Base**: DistilBERT (6 layers, 12 attention heads, 768 hidden dim)
|
| 201 |
+
- **Parameters**: 67M
|
| 202 |
+
- **Task head**: Sequence classification (6 classes)
|
| 203 |
+
- **Max sequence length**: 128 tokens
|
| 204 |
+
- **Format**: Safetensors (FP32)
|
| 205 |
+
|
| 206 |
+
## Limitations
|
| 207 |
+
|
| 208 |
+
- Trained primarily on English and Hinglish text β may not generalize well to other languages
|
| 209 |
+
- Emotion categories are coarse-grained (6 classes) β may miss nuanced emotional states
|
| 210 |
+
- Performance on formal/academic text may differ from conversational text
|
| 211 |
+
- Not a diagnostic tool β should not be used as a substitute for professional mental health assessment
|
| 212 |
+
|
| 213 |
+
## Citation
|
| 214 |
+
|
| 215 |
+
```bibtex
|
| 216 |
+
@misc{raha2026raven,
|
| 217 |
+
title={Raven AI: An Emotionally Aware AI Assistant with Fine-tuned DistilBERT},
|
| 218 |
+
author={Soumyadip Raha},
|
| 219 |
+
year={2026},
|
| 220 |
+
url={https://huggingface.co/SoumyaCodes/raven-emotion-distilbert}
|
| 221 |
+
}
|
| 222 |
+
```
|
| 223 |
+
|
| 224 |
+
## License
|
| 225 |
+
|
| 226 |
+
MIT
|