Views
No views yet
1from transformers import pipeline
2
3classifier = pipeline(
4 "text-classification",
5 model="WishAshake/XLM-Roberta"
6)
7
8# Classify text
9result = classifier("your roman urdu text here")
10print(result)1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3
4tokenizer = AutoTokenizer.from_pretrained("WishAshake/XLM-Roberta")
5model = AutoModelForSequenceClassification.from_pretrained("WishAshake/XLM-Roberta")
6
7# Tokenize and predict
8text = "your roman urdu text here"
9inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=128)
10
11with torch.no_grad():
12 outputs = model(**inputs)
13 predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
14
15label = "Toxic" if predictions[0][1] > 0.5 else "Safe"
16confidence = predictions[0][1].item() if predictions[0][1] > 0.5 else predictions[0][0].item()
17print(f"Label: {label}, Confidence: {confidence:.4f}")1@misc{xlm-roberta-roman-urdu-hate-speech,
2 title={XLM-RoBERTa for Roman Urdu Hate Speech Detection},
3 author={Wisha Zahid},
4 year={2024},
5 howpublished={\url{https://huggingface.co/WishAshake/XLM-Roberta}}
6}