Views
No views yet
1import torch
2from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
4tok = AutoTokenizer.from_pretrained("Bahar-82/parsbert-persian-absa")
5mdl = AutoModelForSequenceClassification.from_pretrained(
6 "Bahar-82/parsbert-persian-absa").eval()
7
8text = "صفحه نمایش خوبه ولی باتری ضعیفه"
9aspect = "باتری و شارژ"
10
11enc = tok(aspect, text, truncation=True, padding="max_length",
12 max_length=96, return_tensors="pt")
13with torch.no_grad():
14 pred = mdl(**enc).logits.argmax(-1).item()
15print(mdl.config.id2label[pred]) # NegativeStratifiedGroupKFold (grouped by review text, so no
review appears in both train and test) on 1038 samples:| Metric | Value |
|---|---|
| Accuracy | 89.3% ± 3.1% |
| F1-macro | 0.892 |
| Class | Precision | Recall | F1 | Support |
|---|---|---|---|---|
| Negative | 0.873 | 0.889 | 0.881 | 316 |
| Neutral | 0.930 | 0.890 | 0.910 | 328 |
| Positive | 0.878 | 0.896 | 0.887 | 394 |