Downloads · 30 days
12
6% of all-time downloads
planghimire/nepali-english-fake-news-detector
nepali-english-fake-news-detector is a text classification model from planghimire. Use it when you need a label for a piece of text. It is set up for transformers.
This model is a fine-tuned version of XLM-RoBERTa-base optimized for detecting fake news in the bilingual (Nepali and English) media landscape. It specifically addresses challenges in low-resource NLP such as morpholo…
Downloads · 30 days
12
6% of all-time downloads
All-time downloads
216
Public
Parameters
278M
1.1 GB on disk
Likes
2
Public
Click a slice to open those files.
.safetensors1.1 GB · 98%
From the Hugging Face model README
This model is a fine-tuned version of XLM-RoBERTa-base optimized for detecting fake news in the bilingual (Nepali and English) media landscape. It specifically addresses challenges in low-resource NLP such as morphological complexity and code-switching.
xlm-roberta-baseThis model is intended for the classification of news articles and social media posts into "Real" or "Fake." It is specifically trained to handle:
The model should not be used as the sole arbiter of truth without human oversight, particularly in sensitive political contexts. It is not designed for languages other than Nepali and English.
The authors recommend using SHAP (SHapley Additive exPlanations) alongside the model to visualize token-level contributions, ensuring that the classification is based on credible linguistic patterns rather than dataset artifacts.
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch.nn.functional as F
DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
MODEL_NAME = "planghimire/nepali-english-fake-news-detector"
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
model = AutoModelForSequenceClassification.from_pretrained(MODEL_NAME).to(DEVICE)
model.eval()
def predict_news(text: str):
inputs = tokenizer(
text,
return_tensors="pt",
truncation=True,
max_length=512,
padding=True
).to(DEVICE)
with torch.no_grad():
probs = F.softmax(model(**inputs).logits, dim=-1)[0]
fake_prob, real_prob = probs.tolist()
is_real = real_prob > fake_prob
print(
f"Prediction: {'REAL' if is_real else 'FAKE'} | "
f"Confidence: {max(real_prob, fake_prob):.2%} | "
f"Real: {real_prob:.3f} | Fake: {fake_prob:.3f}"
)
return {
"label": "Real" if is_real else "Fake",
"confidence": max(real_prob, fake_prob),
"real_prob": real_prob,
"fake_prob": fake_prob
}
# Test
text = "आर्थिकतामा पर्याप्त ध्यान नदिएको भन्दै आएका गुनासोलाई बेवास्ता गर्न खोज्दै ट्रम्पले डिसेम्बर ९ मा सभामा कडा आलोचना गरे।"
predict_news(text)