Downloads · 30 days
5
7% of all-time downloads
harshaojha/distilbert-emotion-finetuned
distilbert-emotion-finetuned is a text classification model from harshaojha. Use it when you need a label for a piece of text. It is set up for transformers. The card lists the license as apache-2.0.
Fine-tuned distilbert-base-uncased on the emotion dataset for 6-class emotion classification.
Downloads · 30 days
5
7% of all-time downloads
All-time downloads
76
Public
Parameters
67M
268 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors268 MB · 100%
From the Hugging Face model README
Fine-tuned distilbert-base-uncased on the emotion dataset for 6-class emotion classification.
Validation accuracy: 93.3% (1,000-sample validation subset, 3 epochs, Colab CPU).
The model predicts one of six emotions:
| ID | Label |
|---|---|
| 0 | sadness |
| 1 | joy |
| 2 | love |
| 3 | anger |
| 4 | fear |
| 5 | surprise |
id2label and label2id are baked into config.json, so pipeline(...) returns string labels directly.
Quick start with pipeline:
from transformers import pipeline
clf = pipeline("text-classification", model="harshaojha/distilbert-emotion-finetuned")
clf("I'm so excited about my new job!")
# [{'label': 'joy', 'score': 0.998...}]
For full probability distributions across all 6 classes:
import torch
import torch.nn.functional as F
from transformers import AutoTokenizer, AutoModelForSequenceClassification
REPO = "harshaojha/distilbert-emotion-finetuned"
tok = AutoTokenizer.from_pretrained(REPO)
mdl = AutoModelForSequenceClassification.from_pretrained(REPO)
mdl.eval()
inputs = tok("I miss my grandmother so much.", return_tensors="pt", truncation=True, max_length=64)
with torch.no_grad():
probs = F.softmax(mdl(**inputs).logits, dim=-1)[0]
for i, p in enumerate(probs):
print(f"{mdl.config.id2label[i]}: {p.item():.3f}")
dair-ai/emotionmax_length=64| Hyperparameter | Value |
|---|---|
| Base model | distilbert-base-uncased |
| Optimizer | AdamW (Trainer default) |
| Learning rate | 3e-5 |
| Batch size (train) | 32 |
| Batch size (eval) | 64 |
| Epochs | 3 |
| Weight decay | 0.01 |
| Max sequence length | 64 |
| Mixed precision | None (CPU) |
| Best checkpoint strategy | load_best_model_at_end=True |
Trained on a Google Colab CPU runtime in ~90 minutes.
| Epoch | Training Loss | Validation Loss | Accuracy |
|---|---|---|---|
| 1 | 0.7161 | 0.4197 | 0.8830 |
| 2 | 0.2607 | 0.2323 | 0.9220 |
| 3 | 0.1385 | 0.2097 | 0.9330 |
Both training and validation loss were still decreasing at epoch 3, suggesting more epochs (or full data) would push accuracy higher.
emotion dataset is dominated by joy and sadness. The model can over-predict joy on indirect or sarcastic phrasings — e.g. "I can't believe they would do this to me" may be classified as joy rather than anger due to surface-pattern overlap with positively-toned "I can't believe …" sentences in the training data.disappointment, annoyance, or disapproval. For finer-grained emotion classification, see go_emotions (27 labels) as a base.go_emotions for fine-grained labels (multi-label, sigmoid + threshold).Apache-2.0 (inherits from the base model and dataset).