Views
No views yet
1from transformers import pipeline
2
3model_name = "arifa-batool/urdu-sentiment-analysis-mbert"
4
5classifier = pipeline(
6 "text-classification",
7 model=model_name,
8 tokenizer=model_name
9)
10
11text = "یہ فلم بہت اچھی تھی"
12result = classifier(text)
13
14print(result)1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3
4model_name = "arifa-batool/urdu-sentiment-analysis-mbert"
5
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7model = AutoModelForSequenceClassification.from_pretrained(model_name)
8
9text = "یہ بہت بری خبر ہے"
10
11inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
12
13with torch.no_grad():
14 outputs = model(**inputs)
15
16probs = torch.softmax(outputs.logits, dim=1)
17
18pred_id = torch.argmax(probs, dim=1).item()
19confidence = torch.max(probs).item()
20
21label = model.config.id2label[pred_id]
22
23print(label, confidence)