Views
No views yet
distilbert-base-uncasedtransformers and use it for inference as shown below:1from transformers import DistilBertTokenizerFast, DistilBertForSequenceClassification
2import torch
3
4tokenizer = DistilBertTokenizerFast.from_pretrained("your-model-id")
5model = DistilBertForSequenceClassification.from_pretrained("your-model-id")
6
7def predict(text):
8 inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=512)
9 outputs = model(**inputs)
10 probs = torch.nn.functional.softmax(outputs.logits, dim=-1)
11 return "Fake News" if torch.argmax(probs) == 1 else "Real News"
12
13text = "Breaking: Scientists discover a new element!"
14print(predict(text))DistilBertTokenizerFastdistilbert-base-uncased| Metric | Score |
|---|---|
| Accuracy | 92% |
| F1 Score | 90% |
| Precision | 91% |
| Recall | 89% |
transformerstorchdatasetsscikit-learn1@misc{DhruvPal2025FakeNewsDetection,
2 title={Fake News Detection with DistilBERT},
3 author={Dhruv Pal},
4 year={2025},
5 howpublished={\url{https://huggingface.co/your-model-id}}
6}