Rakshi1/fake-news-detector
048
๐ฐ Fake News Detection Using Deep Learning (LSTM)
  
๐ Live Interactive Web App: https://huggingface.co/spaces/Rakshi1/fake-news-detector-app
NLP โข Supervised Learning โข Binary Text Classification โข Long Short-Term Memory
This repository hosts a production-grade Deep Learning text classification model that reads news headlines and body text to classify whether an article is Fake News (0) or Real News (1).
๐ Model Evaluation Performance
Evaluated on a 20% stratified test split from the ISOT Fake and Real News Dataset:
Confusion Matrix
- True Fake Detected: 283 / 300 (94.3%)
- True Real Detected: 268 / 300 (89.3%)
๐ง Neural Network Architecture
Input News Headline & Article Body
โ
โผ
Text Preprocessing (Lowercasing, symbol removal, whitespace normalization)
โ
โผ
Tokenizer (Vocab size: 20,000, Sequence length: 300)
โ
โผ
Embedding Layer (dim=128, mask_zero=True)
โ
โผ
LSTM Layer (units=64, return_sequences=False)
โ
โผ
Dropout Layer (rate=0.3)
โ
โผ
Dense Layer (units=1, activation='sigmoid')
โ
โผ
Output: Fake News (0) [< 0.5] or Real News (1) [>= 0.5]๐ How to Test & Predict Using this Hugging Face Model
You can load and test this model directly in Python or Google Colab with 4 lines of code:
import pickle
from huggingface_hub import hf_hub_download
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing.sequence import pad_sequences
# 1. Download model weights and tokenizer from Hugging Face
model_file = hf_hub_download(repo_id="Rakshi1/fake-news-detector", filename="models/fake_news_lstm.keras")
tok_file = hf_hub_download(repo_id="Rakshi1/fake-news-detector", filename="models/tokenizer.pickle")
# 2. Load artifacts
model = load_model(model_file)
with open(tok_file, 'rb') as f:
tokenizer = pickle.load(f)['tokenizer']
# 3. Test on any news text
def predict(title, text):
content = f"{title} {text}".lower().strip()
seq = tokenizer.texts_to_sequences([content])
padded = pad_sequences(seq, maxlen=300, padding='post', truncating='post')
prob = float(model.predict(padded)[0][0])
label = "Real News" if prob >= 0.5 else "Fake News"
conf = (prob if prob >= 0.5 else 1.0 - prob) * 100
return label, round(conf, 2)
# Quick Test Example
label, confidence = predict(
title="White House signs executive order on cybersecurity",
text="WASHINGTON (Reuters) - Government announces new infrastructure regulations."
)
print(f"Prediction: {label} ({confidence}% confidence)")๐ Repository Contents
models/fake_news_lstm.keras: Trained Keras neural network weights.models/tokenizer.pickle: Fitted tokenizer dictionary.notebooks/fake_news_detection.ipynb: Complete 12-step notebook for Google Colab and Jupyter.src/: Complete source code (model.py,preprocessor.py,train.py,evaluate.py,predict.py).app/app.py: Interactive Streamlit web interface.reports/: Confusion matrix heatmap and training curves.requirements.txt: Environment dependencies.
