Views
No views yet
distilbert-base-uncased for multilabel emotion classification. It can predict multiple emotions simultaneously from text input across 14 different emotion categories.1from transformers import AutoTokenizer, AutoModel
2import torch
3
4# Load model and tokenizer
5tokenizer = AutoTokenizer.from_pretrained("your-username/emotion-multilabel-distilbert")
6model = AutoModel.from_pretrained("your-username/emotion-multilabel-distilbert")
7
8# Example usage
9text = "I'm so happy and excited about this project!"
10inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=128)
11
12with torch.no_grad():
13 outputs = model(**inputs)
14 predictions = torch.sigmoid(outputs.logits)
15
16# Get emotions above threshold (0.5)
17emotions = []
18for i, prob in enumerate(predictions[0]):
19 if prob > 0.5:
20 emotions.append(emotion_columns[i])
21
22print(f"Predicted emotions: {', '.join(emotions)}")