Skip to content

About

Why do fake news models hit 99% on the Kaggle dataset? A leakage analysis showing they learn publisher style, not truthfulness. LSTM, BERT, RoBERTa, scikit-learn.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Fake News Detection: What Is the Model Really Learning?

I trained several models (Bidirectional LSTM, Random Forest, Logistic Regression, BERT/RoBERTa) on the popular Kaggle "Fake and Real News" dataset and got around 99% accuracy. That number looked too good, so I investigated it.

Finding: on this dataset, near-perfect accuracy does not mean the model detects fake news. A single rule, "does the article contain the word '(Reuters)'?", already reaches 99.6%. The models mostly learn where an article was published and how it is written, not whether it is true.

Key results

All experiments use the same TF-IDF + Logistic Regression baseline, with exact duplicate articles removed before splitting (the raw dataset contains about 6,000 duplicates, which otherwise leak between train and test).

Experiment Accuracy F1
One-line rule: text contains "(Reuters)" 99.6%
Raw text 99.1% 0.992
Reuters dateline, URLs, Twitter handles, image credits removed 98.6% 0.988
... plus blog phrases removed ("read more", "watch", "via") 98.7% 0.988

Reproduce with:

python leakage_analysis.py

Why accuracy stays high after cleaning

Removing the obvious markers barely changes accuracy. Looking at the features the model relies on explains why:

  • "Real" signals: said, said on, on tuesday, on wednesday, president donald
  • "Fake" signals: this, just, gop, president trump, obama, you

These are differences in writing style: every "real" article comes from Reuters (neutral wire style, attributed quotes, weekday datelines), while the "fake" articles come from partisan blogs (informal tone, direct address, nicknames). The dataset therefore separates two publishers. A model trained on it would likely mislabel a true story written in blog style, or a false story written in news-agency style.

What I take from this

  • High accuracy on a benchmark is a reason to check for leakage, not a result by itself.
  • Removing duplicates before splitting matters: otherwise the same article appears in train and test.
  • Feature inspection (here, the strongest Logistic Regression coefficients) is a cheap and effective way to see what a model actually uses.
  • A credible evaluation would test on a different dataset than the one used for training (for example, train on this dataset and test on LIAR or WELFake).

Original models

machine_learning_Train.ipynb contains the original experiments (Bidirectional LSTM in PyTorch, Random Forest, Logistic Regression), and transformer_comparison.py fine-tunes BERT and RoBERTa. They were trained on the raw text, so their ~99% scores are affected by the leakage described above and should be read in that light.

Setup

The dataset is not included in this repository. Download it from Kaggle: Fake and Real News Dataset and place True.csv and Fake.csv in the repository root.

git clone https://github.com/efedemirc/Machine_Learning_Fake_News_Detector.git
cd Machine_Learning_Fake_News_Detector
pip install -r requirements.txt

python leakage_analysis.py          # leakage analysis (CPU, about a minute)
jupyter notebook machine_learning_Train.ipynb   # original LSTM experiments
python transformer_comparison.py    # BERT / RoBERTa (GPU recommended)

Next steps

  • Cross-dataset evaluation (train on this dataset, test on LIAR / WELFake)
  • Re-run the LSTM and transformer models on the cleaned, deduplicated text
  • Compare against a style-only baseline (function words, punctuation) to measure how much is pure style

Tech

Python, PyTorch, scikit-learn, Hugging Face Transformers, pandas, Matplotlib

License

MIT, see LICENSE.

About

Why do fake news models hit 99% on the Kaggle dataset? A leakage analysis showing they learn publisher style, not truthfulness. LSTM, BERT, RoBERTa, scikit-learn.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages