Views
No views yet
vinai/phobert-base1from transformers import AutoModelForSequenceClassification, AutoTokenizer
2
3model = AutoModelForSequenceClassification.from_pretrained("thecuong/PhoBERT-Specialty-ClassificationBC")
4tokenizer = AutoTokenizer.from_pretrained("thecuong/PhoBERT-Specialty-ClassificationBC")
5mlb_path = hf_hub_download(repo_id="thecuong/PhoBERT-Specialty-ClassificationBC", filename="mlb.pkl")
6
7# Load mlb.pkl
8with open(mlb_path, "rb") as f:
9 mlb = pickle.load(f)
10
11text = "u tuyến tiền liệt"
12tokens = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=128)
13outputs = model(**tokens)
14
15print(outputs.logits)
16optimal_thresholds = [0.2985745668411255,
17 0.2442353218793869,
18 0.460119366645813,
19 0.25225114822387695,
20 0.4248329699039459,
21 0.4668178856372833,
22 0.2842218279838562,
23 0.43041494488716125,
24 0.32972779870033264,
25 0.36232128739356995,
26 0.26634153723716736,
27 0.24046610295772552,
28 0.34447458386421204,
29 0.2602587640285492,
30 0.30732235312461853,
31 0.34195464849472046,
32 0.43998637795448303,
33 0.1687939465045929,
34 0.39311549067497253]
35binary_preds_thresh = (probs > optimal_thresholds).astype(int)
36predicted_labels = mlb.inverse_transform(binary_preds_thresh){
"0": "Chưa rõ ràng triệu chứng cần hỏi lại",
"1": "Cơ Xương Khớp",
"3": "Tim mạch",
"4": "Tai Mũi Họng",
"5": "Nhi khoa",
"11": "Da liễu",
"15": "Ung bướu",
"17": "Nội khoa",
"18": "Thần kinh",
"19": "Sản Phụ khoa",
"21": "Tiểu đường - Nội tiết",
"22": "Tiêu hóa",
"24": "Cột sống",
"26": "Nam học",
"27": "Sức khỏe tâm thần",
"28": "Bệnh Viêm gan",
"29": "Chuyên khoa Mắt",
"31": "Khám tổng quát",
"32": "Thận - Tiết niệu",
"33": "Nha khoa",
"43": "Hô hấp - Phổi",
"67": "Vô sinh - Hiếm muộn"
}