Downloads · 30 days
25
35% of all-time downloads
hrshlgunjal/emotion-classifier-roberta-base
emotion-classifier-roberta-base is a text classification model from hrshlgunjal. Use it when you need a label for a piece of text. The card lists the license as apache-2.0.
This model classifies text into 5 emotion categories: anger, fear, joy, sadness, and surprise.
Downloads · 30 days
25
35% of all-time downloads
All-time downloads
72
Public
Parameters
125M
499 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors499 MB · 99%
From the Hugging Face model README
This model classifies text into 5 emotion categories: anger, fear, joy, sadness, and surprise.
N/A
N/A
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
import numpy as np
# Load model and tokenizer
model = AutoModelForSequenceClassification.from_pretrained("hrshlgunjal/emotion-classifier-roberta-base")
tokenizer = AutoTokenizer.from_pretrained("hrshlgunjal/emotion-classifier-roberta-base")
# Optimized thresholds (use these for best results)
thresholds = np.array([0.5, 0.5, 0.5, 0.5, 0.5])
labels = ['anger', 'fear', 'joy', 'sadness', 'surprise']
# Predict emotions
def predict_emotions(text):
inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=128)
with torch.no_grad():
outputs = model(**inputs)
probs = torch.sigmoid(outputs.logits).cpu().numpy()[0]
predictions = (probs >= thresholds).astype(int)
return {label: (pred, prob) for label, pred, prob in zip(labels, predictions, probs)}
# Example
text = "I am so excited about this amazing opportunity!"
result = predict_emotions(text)
print(result)
hrshlgunjal
For questions or feedback, please open an issue in the model repository.