Emotion Classifier (RoBERTa-large)

Fine-tuned roberta-large that classifies text into one of six core emotions: joy, sadness, anger, fear, surprise, disgust.

Try it directly in the widget on the right โ†’

Model description

This model maps GoEmotions' 27 fine-grained emotions (+ neutral) onto Paul Ekman's 6 core emotions, then fine-tunes roberta-large as a single-label, 6-way classifier. It was compared against three custom sequence models (LSTM, GRU, BiLSTM + Attention) trained on the same split โ€” roberta-large came out ahead on every metric. Full training code, data pipeline, and comparison are in the GitHub repo .

Intended uses & limitations

  • Intended for short, English, first-person emotional text (the training data is Reddit comments and self-reported emotional narratives).
  • Not intended for clinical, diagnostic, or high-stakes decisions.
  • disgust is the weakest class (fewest training examples even after augmentation) โ€” expect more mistakes on it than the other five emotions.
  • Inputs are truncated to 64 tokens.

Training data

  • GoEmotions: labels mapped to the 6 Ekman emotions; examples with no target emotion are dropped, and examples spanning more than one target emotion are resolved towards the rarer emotion in the training split only (validation/test keep dropping them, so the evaluation ground truth stays unambiguous).
  • ISEAR: real (not duplicated) disgust and fear examples added to the training split only, since those are the rarest classes in GoEmotions.

Training procedure

  • Base model: roberta-large
  • Batch size 8, gradient accumulation 4 (effective batch 32)
  • Learning rate 1e-5, linear warmup, EarlyStoppingCallback on validation macro F1
  • Class-weighted loss, damped with alpha=0.5 (โˆšcount rather than raw inverse-frequency) โ€” full inverse-frequency weighting over-corrected disgust in earlier experiments (very high recall, very low precision)

Evaluation results

Evaluated on a held-out GoEmotions test split (ambiguous/neutral-only examples dropped, never resolved):

Metric Score
Accuracy 0.813
Macro F1 0.716
Emotion Precision Recall F1
joy 0.92 0.89 0.90
sadness 0.64 0.72 0.68
anger 0.72 0.69 0.71
fear 0.68 0.76 0.72
surprise 0.72 0.77 0.74
disgust 0.51 0.58 0.55

How to use

from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch

tokenizer = AutoTokenizer.from_pretrained("Ahmed-Tarek0/emotion-roberta-large")
model = AutoModelForSequenceClassification.from_pretrained("Ahmed-Tarek0/emotion-roberta-large")

text = "I can't believe you did this!"
inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=64)
with torch.no_grad():
    probs = torch.softmax(model(**inputs).logits, dim=-1)[0]

id2label = model.config.id2label
for i, p in sorted(enumerate(probs.tolist()), key=lambda x: -x[1]):
    print(f"{id2label[i]:10s} {p:.2%}")

Or with a pipeline:

from transformers import pipeline

clf = pipeline("text-classification", model="Ahmed-Tarek0/emotion-roberta-large", top_k=None)
clf("I can't believe you did this!")

Limitations

See Intended uses & limitations above. This is a student/research project, not a production-grade moderation or clinical tool.

Downloads last month
33
Safetensors
Model size
0.4B params
Tensor type
F32
ยท
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Dataset used to train Ahmed-Tarek0/emotion-roberta-large

Evaluation results

  • accuracy on GoEmotions (mapped to 6 Ekman emotions) + ISEAR
    self-reported
    0.813
  • Macro F1 on GoEmotions (mapped to 6 Ekman emotions) + ISEAR
    self-reported
    0.716