BERT Fine-Tuned for Fake News Detection
Model Description
This is a sequence classification model designed to detect fake news articles. It was built by fine-tuning the 110-million parameter bert-base-uncased model on a balanced dataset of real and fake news.
The model outputs binary predictions:
- 0: Fake News
- 1: Real News
Training Procedure
The model was fine-tuned using the Hugging Face Trainer API with the following hyperparameters:
- Learning Rate: 2e-5
- Train/Eval Batch Size: 8
- Epochs: 3
- Weight Decay: 0.01
- Max Sequence Length: 512 tokens (strict truncation)
Evaluation Metrics
During training, the model was evaluated using a custom compute metric function. It tracks:
- Accuracy
- F1-Score
How to Use
You can easily load and test this model using the transformers library:
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
# Load the model and tokenizer
model_id = "ahmednawaz8813/BERT_Fine_Tuned"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForSequenceClassification.from_pretrained(model_id)
# Test with an article snippet
article_text = "Scientists have discovered a new species of deep-sea jellyfish."
inputs = tokenizer(article_text, return_tensors="pt", truncation=True, max_length=512, padding="max_length")
# Get prediction
with torch.no_grad():
logits = model(**inputs).logits
predicted_class_id = logits.argmax().item()
label_map = {0: "Fake News", 1: "Real News"}
print(f"Prediction: {label_map[predicted_class_id]}")