CoolFace
Modelpublic

Rakshi1/fake-news-detector

sourceHugging Facemitupdated 2d agoView on Hugging Face
0likes48downloads
Model Card

๐Ÿ“ฐ Fake News Detection Using Deep Learning (LSTM)

![Open In Colab](https://colab.research.google.com/github/Rakshi1) ![Hugging Face Space](https://huggingface.co/spaces/Rakshi1/fake-news-detector-app) ![Hugging Face Model](https://huggingface.co/Rakshi1/fake-news-detector)

๐Ÿš€ 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:

MetricScoreDescription
Accuracy91.83%Overall percentage of correct classifications across test set
Precision94.04%Of all articles predicted as Real, 94.04% were actually Real
Recall89.33%Of all actual Real articles, 89.33% were successfully detected
F1-Score91.62%Balance between precision and recall

Confusion Matrix

  • โ€”True Fake Detected: 283 / 300 (94.3%)
  • โ€”True Real Detected: 268 / 300 (89.3%)

๐Ÿง  Neural Network Architecture

text
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:

python
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.