RoBERTa fine-tuned for emotion detection

This is roberta-base fine-tuned to classify English text into six emotions: anger, fear, joy, love, sadness and surprise.

It is one of four models compared in the paper:

Comparative Analysis of DistilBERT, XLNet, RoBERTa & BigBird for Emotion Detection in Conversational Text Arslan Ahmed, Barkha, Tushar Kanjwani, Shahzad Nasim. ILMA Journal of Technology & Software Management (IJTSM), Vol. 6, Issue 1, pp. 1–12, 2025. 📄 Paper · 💻 Code, notebooks & web demo

Results (test set, 2,000 samples)

Accuracy Macro F1 Weighted F1
93.15 % 0.89 0.93

Strengths: most balanced precision/recall across all six classes; highest validation accuracy (94.20 %). Like every model in the study, it is weakest on surprise, the rarest class.

Other models from the paper: DistilBERT · XLNet · RoBERTa · BigBird

Labels

id 0 1 2 3 4 5
label anger fear joy love sadness surprise

Usage

# pip install "transformers>=4.50,<5" tensorflow tf-keras sentencepiece
import tensorflow as tf
from transformers import RobertaTokenizer, TFRobertaForSequenceClassification

repo = "arslanahmed3/emotion-roberta"
tokenizer = RobertaTokenizer.from_pretrained(repo)
model = TFRobertaForSequenceClassification.from_pretrained(repo)

inputs = tokenizer("i feel so lucky to have friends like you", return_tensors="tf", truncation=True, max_length=128)
probs = tf.nn.softmax(model(**inputs).logits, axis=-1)[0].numpy()
print(model.config.id2label[int(probs.argmax())], float(probs.max()))

Transformers 5.x removed the TensorFlow model classes, so use transformers<5.

Training

Dataset Emotions Dataset for NLP (16,000 train / 2,000 val / 2,000 test)
Framework TensorFlow
Optimizer / LR 5e-5 (Adam)
Batch size 32
Max sequence length 128
Epochs 20
Hardware Google Colab GPU

The training notebook is in the GitHub repo.

Citation

@article{ahmed2025emotion,
  title   = {Comparative Analysis of DistilBERT, XLNet, RoBERTa \& BigBird for Emotion Detection in Conversational Text},
  author  = {Ahmed, Arslan and Barkha and Kanjwani, Tushar and Nasim, Shahzad},
  journal = {ILMA Journal of Technology \& Software Management (IJTSM)},
  volume  = {6},
  number  = {1},
  pages   = {1--12},
  year    = {2025},
  url     = {https://ijtsm.ilmauniversity.edu.pk/arc/Vol6/i1p1}
}
Downloads last month
6
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for arslanahmed3/emotion-roberta

Finetuned
(2381)
this model