Views
No views yet
vinai/phobert-base-v2.RobertaForSequenceClassification)vinai/phobert-base-v2text-classificationAutoTokenizer, AutoModelForSequenceClassification, and a custom WeightedTrainer(Trainer) that applies class-weighted cross entropy.config.json) is:| id | label |
|---|---|
| 0 | COMPARISON |
| 1 | FACTOID |
| 2 | SUMMARY |
| 3 | VERIFICATION |
pip install -U "transformers" "torch" "sentencepiece"1import torch
2from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
4MODEL_ID = "tiam4tt/PhoBERT-VFQT-Cls" # or a local path to this folder
5
6tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
7model = AutoModelForSequenceClassification.from_pretrained(MODEL_ID)
8model.eval()
9
10text = "Tăng trưởng GDP quý này so với quý trước như thế nào?"
11
12inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=256)
13with torch.no_grad():
14 logits = model(**inputs).logits
15
16pred_id = int(torch.argmax(logits, dim=-1).item())
17id2label = model.config.id2label
18pred_label = id2label.get(pred_id, id2label.get(str(pred_id), f"LABEL_{pred_id}"))
19
20print(pred_label)
21
22# Expects: "COMPARISON"| label | precision | recall | f1 |
|---|---|---|---|
| COMPARISON | 0.9576 | 0.9480 | 0.9528 |
| FACTOID | 0.9153 | 0.9080 | 0.9116 |
| SUMMARY | 0.9506 | 0.9620 | 0.9563 |
| VERIFICATION | 0.9784 | 0.9864 | 0.9824 |
config.json)