emotion-distilbert
DistilBERT-based emotion classifier
2 min readupdated
This model detects Ekman's six basic emotions (joy, sadness, anger, fear, surprise, and disgust) in English text. Built on the lightweight, efficient distilbert-base-uncased base model, it was fine-tuned on Reddit comments from the GoEmotions dataset. Compared to standard LSTM networks and GloVe-embedding models, this fine-tune delivers higher classification accuracy. It is well-suited for chatbot developers, sentiment researchers, and user feedback analysts.
Key features
- Detects joy, sadness, anger, fear, surprise, and disgust.
- Uses the DistilBERT architecture with class balancing to offset data imbalance.
- Reaches 0.7934 Accuracy on the test split.
- Integrates out of the box via the standard
transformerslibrary pipeline.
What you can do
- Automatically detect the emotional tone of user comments and messages across your apps.
- Adapt chatbot responses dynamically based on the user's mood.
- Quickly sort streams of short English texts into emotional categories.
Example
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification
name = "mai-data-ai/emotion-distilbert"
tok = AutoTokenizer.from_pretrained(name)
model = AutoModelForSequenceClassification.from_pretrained(name).eval()
enc = tok("Stop wasting my time, this is so annoying", return_tensors="pt",
truncation=True, max_length=64)
with torch.no_grad():
probs = torch.softmax(model(**enc).logits, dim=-1)[0]
print({model.config.id2label[i]: round(p.item(), 3) for i, p in enumerate(probs)})
Read more
DetailsBenchmarks: 0.7934 Accuracy and 0.6962 Macro F1 on a test dataset of 3,539 comments.
Training: 4 epochs, batch size 32, 2e-5 learning rate with early stopping on validation macro-F1.
Limitations: trained on English text (Reddit); underrepresented classes like disgust are detected less reliably due to fewer training samples; the model always assigns one of the 6 emotions (there is no neutral class).










Comments