dair-ai/emotion
Viewer • Updated • 437k • 33.8k • 440
How to use serverdaun/emotion-distilbert-finetuned with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-classification", model="serverdaun/emotion-distilbert-finetuned") # Load model directly
from transformers import AutoTokenizer, AutoModelForSequenceClassification
tokenizer = AutoTokenizer.from_pretrained("serverdaun/emotion-distilbert-finetuned")
model = AutoModelForSequenceClassification.from_pretrained("serverdaun/emotion-distilbert-finetuned")A fine-tuned DistilBERT model for emotion classification trained on the dair-ai/emotion dataset. This model classifies text into 6 emotion categories: sadness, joy, love, anger, fear, and surprise.
distilbert-base-uncasedThe model classifies text into the following 6 emotions:
dair-ai/emotionfrom transformers import pipeline
# Using the pipeline
classifier = pipeline("text-classification", model="your-username/emotion-distilbert-finetuned")
result = classifier("I feel great today!")
print(result)
# Output: [{'label': 'joy', 'score': 0.9876}]
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
# Load model and tokenizer
tokenizer = AutoTokenizer.from_pretrained("your-username/emotion-distilbert-finetuned")
model = AutoModelForSequenceClassification.from_pretrained("your-username/emotion-distilbert-finetuned")
# Emotion labels
emotion_labels = {
0: "sadness",
1: "joy",
2: "love",
3: "anger",
4: "fear",
5: "surprise"
}
# Classify emotion
text = "I feel great today!"
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
with torch.no_grad():
outputs = model(**inputs)
predicted_class = torch.argmax(outputs.logits, dim=1).item()
print(f"Predicted emotion: {emotion_labels[predicted_class]}")
# Get all probabilities
with torch.no_grad():
outputs = model(**inputs)
probabilities = torch.softmax(outputs.logits, dim=1).squeeze()
for i, prob in enumerate(probabilities):
print(f"{emotion_labels[i]}: {prob:.4f}")
If you use this model, please cite the original dataset:
@inproceedings{saravia-etal-2018-carer,
title = "{CARER}: Contextualized Affect Representations for Emotion Recognition",
author = "Saravia, Elvis and
Liu, Hsien-Chi Toby and
Huang, Yen-Hao and
Wu, Junlin and
Chen, Yi-Shin",
booktitle = "Proceedings of the 2018 Conference on Empirical Methods in Natural Language Processing",
month = oct # "-" # nov,
year = "2018",
address = "Brussels, Belgium",
publisher = "Association for Computational Linguistics",
url = "https://www.aclweb.org/anthology/D18-1404",
doi = "10.18653/v1/D18-1404",
pages = "3687--3697"
}
Base model
distilbert/distilbert-base-uncased