Views
No views yet
xlm-roberta-base| Metric | Value |
|---|---|
| Accuracy (EmoT test) | 0.7364 |
| Macro F1 | 0.7423 |
| Latency (mean) | 10.5 ms |
| Model Size | 7.5 GB |
1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3
4model_name = "AzrilFahmiardi/sdd-emotion-general"
5tokenizer = AutoTokenizer.from_pretrained(model_name)
6model = AutoModelForSequenceClassification.from_pretrained(model_name)
7
8device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
9model = model.to(device)1def detect_emotion(text: str) -> dict:
2 inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=128).to(device)
3
4 with torch.no_grad():
5 outputs = model(**inputs)
6 logits = outputs.logits
7
8 probabilities = torch.softmax(logits, dim=-1)[0].cpu()
9 predicted_class = logits.argmax(-1).item()
10 predicted_label = model.config.id2label[predicted_class]
11 confidence = probabilities[predicted_class].item()
12
13 return {
14 "emotion": predicted_label,
15 "confidence": confidence
16 }
17
18# Example
19text = "Saya sangat senang bisa bersama keluarga hari ini!"
20result = detect_emotion(text)
21print(f"Emotion: {result['emotion']} ({result['confidence']:.2%})")1{
2 "emotion": "happy",
3 "confidence": 0.8934
4}| Parameter | Type | Example |
|---|---|---|
| Input | str | Indonesian text, max 128 tokens |
| Output | dict | {"emotion": "happy", "confidence": 0.89} |