dair-ai/emotion
Viewer β’ Updated β’ 437k β’ 33.7k β’ 440
Fine-tuned version of DistilBERT for 6-class emotion classification using the dair-ai/emotion dataset.
| Format | Accuracy | F1 Macro |
|---|---|---|
| FP32 | 92.50% | 0.8799 |
| INT8* | 91.95% | 0.8659 |
*INT8 is applied at runtime via quantize_dynamic β see usage below.
| ID | Emotion |
|---|---|
| 0 | sadness |
| 1 | joy |
| 2 | love |
| 3 | anger |
| 4 | fear |
| 5 | surprise |
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification
repo_id = "Sukuna404/distilbert-emotion-fp32"
tokenizer = AutoTokenizer.from_pretrained(repo_id)
model = AutoModelForSequenceClassification.from_pretrained(repo_id)
# Optional: apply INT8 quantization at runtime for faster CPU inference
model = torch.quantization.quantize_dynamic(
model,
{torch.nn.Linear},
dtype=torch.qint8
)
model.eval()
model.cpu()
def predict(text: str) -> str:
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding="longest")
with torch.no_grad():
outputs = model(**inputs)
pred_id = outputs.logits.argmax().item()
return model.config.id2label[pred_id]
print(predict("I am so happy today!")) # joy
print(predict("I am really angry!")) # anger
Base model
distilbert/distilbert-base-uncased