Views
No views yet
negativeneutralpositive1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3
4model_id = "Bangkah/atha-text-classifier"
5tokenizer = AutoTokenizer.from_pretrained(model_id)
6model = AutoModelForSequenceClassification.from_pretrained(model_id)
7
8text = "produk ini bagus dan pengirimannya cepat"
9inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=128)
10with torch.no_grad():
11 logits = model(**inputs).logits
12
13probs = torch.softmax(logits, dim=-1)[0]
14label_id = int(torch.argmax(probs).item())
15label = model.config.id2label[label_id]
16score = float(probs[label_id].item())
17print({"label": label, "confidence": round(score, 4)})| true\pred | negative | neutral | positive |
|---|---|---|---|
| negative | 100 | 0 | 0 |
| neutral | 0 | 100 | 0 |
| positive | 0 | 0 | 100 |
1 precision recall f1-score support
2
3 negative 1.0000 1.0000 1.0000 100
4 neutral 1.0000 1.0000 1.0000 100
5 positive 1.0000 1.0000 1.0000 100
6
7 accuracy 1.0000 300
8 macro avg 1.0000 1.0000 1.0000 300
9weighted avg 1.0000 1.0000 1.0000 300
10