CoolFace
Modelpublic

VanshajR/roberta-emotion-7class

sourceHugging Facemitupdated 10mo agoView on Hugging Face
1likes8downloads
Model Card

RoBERTa Emotion Classifier (7-class)

Fine-tuned RoBERTa model for emotion classification on 7 emotions: happy, sad, angry, fear, disgust, surprise, neutral.

Model Details

  • Developed by: VanshajR
  • Base Model: roberta-base (125M parameters)
  • Task: Multi-class emotion classification
  • Dataset: GoEmotions (27 emotions mapped to 7)
  • Training Samples: ~58,000
  • Language: English
  • License: MIT

Performance

Evaluated on GoEmotions test set:

MetricScore
Accuracy57.77%
Macro F10.4787
Precision0.5289
Recall0.4958

Per-Class Performance

EmotionPrecisionRecallF1-ScoreSupport
Happy0.620.670.642,362
Sad0.540.510.521,210
Angry0.580.430.491,145
Fear0.420.310.36428
Disgust0.480.260.34361
Surprise0.430.430.43623
Neutral0.640.860.738,711

Usage

python
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch

# Load model and tokenizer
tokenizer = AutoTokenizer.from_pretrained("VanshajR/roberta-emotion-7class")
model = AutoModelForSequenceClassification.from_pretrained("VanshajR/roberta-emotion-7class")

# Classify emotion
text = "I'm so excited about this project!"
inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=128)

with torch.no_grad():
    outputs = model(**inputs)
    predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
    predicted_class = torch.argmax(predictions, dim=-1).item()

# Emotion labels
emotions = ["happy", "sad", "angry", "fear", "disgust", "surprise", "neutral"]
print(f"Predicted emotion: {emotions[predicted_class]}")
print(f"Confidence: {predictions[0][predicted_class].item():.2%}")

Training Details

Training Data

  • Dataset: GoEmotions (Google Research)
  • Emotion Mapping: 27 fine-grained emotions → 7 basic emotions
  • Training Samples: ~58,000 Reddit comments
  • Preprocessing: Truncation to 128 tokens, lowercase normalization

Training Procedure

  • Optimizer: AdamW (lr=2e-5, weight_decay=0.01)
  • Batch Size: 16 (train), 32 (eval)
  • Epochs: 3
  • Max Length: 128 tokens
  • Training Regime: fp32

Compute Infrastructure

  • Hardware: NVIDIA RTX 3070 (8GB VRAM)
  • Training Time: ~2 hours
  • Framework: PyTorch 2.1.0, Transformers 4.35.0

Limitations and Bias

  • Language: English only
  • Domain: Primarily trained on Reddit comments (may not generalize to formal text)
  • Class Imbalance: Better performance on frequent emotions (happy, neutral) vs rare emotions (fear, disgust)
  • Subjective Task: Human annotators often disagree on emotions (~25-30% disagreement rate)

Intended Use

Recommended:

  • Emotion detection in conversational text
  • Evaluating emotion-controlled text generation
  • Research on emotion understanding in dialogue
  • Sentiment analysis applications

Not Recommended:

  • Clinical diagnosis or mental health assessment
  • High-stakes decision making
  • Non-English languages

Citation

bibtex
@misc{vanshajr2024roberta,
  author = {Vanshaj R},
  title = {RoBERTa Emotion Classifier for 7-Class Emotion Detection},
  year = {2024},
  publisher = {HuggingFace},
  url = {https://huggingface.co/VanshajR/roberta-emotion-7class}
}

Related Work

Part of the Emotion-Controlled Response Generation project: