Views
No views yet
bert-base-multilingual-cased (170M parameters)1import torch
2from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
4MODEL_ID = "Rahilgh/model4_1"
5tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
6model = AutoModelForSequenceClassification.from_pretrained(MODEL_ID)
7
8device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
9model.to(device).eval()
10
11LABEL_MAP = {0: "F", 1: "R", 2: "N", 3: "M", 4: "S"}
12LABEL_NAMES = {
13 "F": "Factual",
14 "R": "Reporting",
15 "N": "Non-factual",
16 "M": "Misleading",
17 "S": "Satire"
18}
19
20texts = [
21 "قالك بلي رايحين ينحو الباك هذا العام",
22
23]
24
25for text in texts:
26 inputs = tokenizer(
27 text,
28 return_tensors="pt",
29 max_length=128,
30 truncation=True,
31 padding=True,
32 ).to(device)
33
34 with torch.no_grad():
35 outputs = model(**inputs)
36 probs = torch.softmax(outputs.logits, dim=1)[0]
37 pred_id = probs.argmax().item()
38 confidence = probs[pred_id].item()
39
40 label = LABEL_MAP[pred_id]
41 print(f"Text: {text}")
42 print(f"Prediction: {LABEL_NAMES[label]} ({label}) — {confidence:.2%}\n")