RoBERTa-base fine-tuned on GoEmotions (28 labels, multi-label)
Detects which of 27 emotions + neutral a short English text expresses. A text can have several emotions at once, so each label has its own sigmoid output and its own decision threshold.
- Base model:
FacebookAI/roberta-base - Dataset: GoEmotions (
simplified, 43.4k Reddit comments) - Training: lr 5e-5, batch size 16, 4 epochs, max length 64, fp16. Learning rate and batch size chosen by a grid search on a sample.
- Thresholds: one threshold per emotion, tuned on the validation split and stored in
thresholds.json.
Test results (5,427 comments)
| Metric | Value |
|---|---|
| Micro-F1 (per-emotion thresholds) | 0.603 |
| Macro-F1 (per-emotion thresholds) | 0.523 |
| Macro-F1 (single threshold 0.35) | 0.509 |
| Baseline TF-IDF + logistic regression (macro-F1) | 0.420 |
| Baseline always 'neutral' (macro-F1) | 0.018 |
Usage
import json, torch
from huggingface_hub import hf_hub_download
from transformers import AutoTokenizer, AutoModelForSequenceClassification
repo = "jeffespejo/roberta-base-goemotions-udea"
tok = AutoTokenizer.from_pretrained(repo)
model = AutoModelForSequenceClassification.from_pretrained(repo)
thresholds = json.load(open(hf_hub_download(repo, "thresholds.json")))
text = "Thank you so much for helping me with my thesis, you are amazing!"
with torch.no_grad():
probs = torch.sigmoid(model(**tok(text, return_tensors="pt")).logits)[0]
print({model.config.id2label[i]: round(p.item(), 2) for i, p in enumerate(probs)
if p >= thresholds[model.config.id2label[i]]})
Limitations
Trained on Reddit comments in English; very rare emotions (grief, relief) are still hard to detect. Built as a university course project (Fundamentos de Procesamiento de Lenguaje Natural · Universidad de Antioquia) by Jefferson Espejo. Code: https://github.com/AndiEspejo/emotions-skills-detox-nlp