Views
No views yet
indobenchmark/indobert-base-p2| Metric | SmSA Test | News Holdout |
|---|---|---|
| Accuracy | 0.904 | 0.804 |
| Macro F1 | 0.874 | 0.805 |
| Latency (mean) | 9.53 ms | 9.53 ms |
| Model Size | 474.7 MB | - |
1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3
4model_name = "AzrilFahmiardi/sdd-sentiment-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 analyze_sentiment(text: str) -> dict:
2 inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=256).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 "sentiment": predicted_label,
15 "confidence": confidence
16 }
17
18# Example
19text = "Pemerintah berhasil menurunkan inflasi, ekonomi tumbuh positif tahun ini."
20result = analyze_sentiment(text)
21print(f"Sentiment: {result['sentiment']} ({result['confidence']:.2%})")1{
2 "sentiment": "positif",
3 "confidence": 0.9234
4}| Parameter | Type | Example |
|---|---|---|
| Input | str | Indonesian text (news, social media), max 256 tokens |
| Output | dict | {"sentiment": "positif", "confidence": 0.92} |