aasimansari1/fake-news-detector
ุญูู
๐ฐ NLP fake news detector โ TF-IDF + scikit-learn + Flask | 95% accuracy, confidence scores
ุงูุฐูุงุก ุงูุงุตุทูุงุนู ูุชุนููู ุงูุขูุฉู ุง ูู ููู ูุนูู
- ๐ง Multi-Model ML 4 models compared: Passive Aggressive, Naive Bayes, Logistic Regression, Random Forest Best model auto-selected at training time ~91% accuracy on Kaggle Fake News dataset - ๐ Explainable AI Confidence score + fake/real probability Key words that influenced the verdict Per-word influence direction (fake vs real)
- 4 models compared: Passive Aggressive, Naive Bayes, Logistic Regression, Random Forest
- Best model auto-selected at training time
- ~91% accuracy on Kaggle Fake News dataset
ุงููู ู ุงูู ูุงุณ ูููุฌูู
- ุฎูุงู 24 ุณุงุนุฉ
- ู
- ุฎูุงู 7 ุฃูุงู
- ู
- ุฎูุงู 15 ููู ูุง
- +ูก
- ุฎูุงู ุดูุฑ
- ุฌุงุฑู ุฌู ุน ุงูุณุฌู
ุชุบููุฑ ุตุงูู ุงููุฌูู ุฎูุงู ูุชุฑุงุช ู ุชุฏุงุฎูุฉุ ูููุณ ู ุฌู ูุนูุง ููู ููุง. ุชุจูู ุงูููุงุณุงุช ุงูู ูููุฏุฉ ูุงุฑุบุฉ. ุงููุฌูู ุชููุณ ุงูุงูุชู ุงู ูุง ุฌูุฏุฉ ุงูุจุฑู ุฌูุงุช.
README.md
ุงูุฃุตู๐ก๏ธ FakeShield AI โ Fake News Detector
Paste any headline or article. Get an instant REAL / FAKE verdict with confidence score and linguistic evidence.
Misinformation spreads 6x faster than the truth. FakeShield uses NLP and machine learning to classify news articles in milliseconds โ with a confidence score, fake/real probability breakdown, and the exact words that triggered the verdict.
โจ Features
๐ง Multi-Model ML
|
๐ Explainable AI
|
๐ Training Visualisations
|
๐ REST API
|
๐ Quick Start
git clone https://github.com/aasimansari1/fake-news-detector.git
cd fake-news-detector
pip install -r requirements.txt
# Generate sample dataset + download NLTK data
python dataset/create_dataset.py
# Train all 4 models (best one saved automatically)
python train_model.py
# Launch the web app
python app.py
# โ http://localhost:5000
Want better accuracy? Replace
dataset/sample_data.csvwith the Kaggle Fake News dataset (~44K articles). Any CSV withtextandlabelcolumns (REAL/FAKE or 0/1) works.
๐๏ธ How It Works
๐ฐ Article / Headline
โ
โผ
โโโโโโโโโโโโโโโโโโโโโ
โ NLP Pipeline โ
โ lowercase โ โ
โ punctuation โ โ
โ tokenise โ โ
โ stopwords โ โ
โ lemmatise โ
โโโโโโโโโโฌโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโ
โ TF-IDF (bigrams) โ
โ Vectoriser โ
โโโโโโโโโโฌโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโ
โ Best ML Model โ โ Passive Aggressive (~91%)
โโโโโโโโโโฌโโโโโโโโโโโ
โ
โผ
โ
REAL (confidence: 94%)
โ FAKE (confidence: 82%)
+ key words + probabilities
๐ก API
POST /predict
Content-Type: application/json
{"text": "Scientists discover that vaccines cause autism, government hiding truth"}
{
"prediction": "FAKE",
"confidence": 89.4,
"fake_probability": 89.4,
"real_probability": 10.6,
"key_words": [
{"word": "hiding", "score": 0.21, "influence": "fake"},
{"word": "truth", "score": 0.18, "influence": "fake"}
],
"model_name": "Passive Aggressive",
"model_accuracy": 0.907
}
๐ Model Accuracy
| Model | Accuracy | Notes |
|---|---|---|
| Passive Aggressive | ~91% | Best overall โ auto-selected |
| Naive Bayes | ~88% | Fastest inference |
| Logistic Regression | ~86% | Most interpretable |
| Random Forest | ~84% | Most robust to noise |
Accuracy on sample dataset. Use a larger real-world dataset for production-grade results.
๐๏ธ Project Structure
fake-news-detector/
โโโ app.py # Flask web app + /predict API
โโโ train_model.py # Training pipeline, model comparison
โโโ requirements.txt
โ
โโโ src/ # Reusable data science module
โ โโโ preprocessing.py # Text cleaning, label normalisation, dataset loader
โ โโโ features.py # TF-IDF vectoriser builder
โ โโโ models.py # Train all classifiers, pick best, ROC data
โ
โโโ notebooks/ # Jupyter data science pipeline
โ โโโ 01_EDA.ipynb # Exploratory data analysis
โ โโโ 02_Feature_Engineering.ipynb # Preprocessing + TF-IDF
โ โโโ 03_Model_Training.ipynb # Train & compare 4 models
โ โโโ 04_Model_Evaluation.ipynb # Confusion matrix, ROC, feature importance, CV
โ
โโโ data/
โ โโโ raw/ # Source datasets (CSV)
โ โโโ processed/ # Train/test splits + vectoriser (generated)
โ
โโโ models/ # Saved model + vectoriser (generated)
โโโ reports/figures/ # All visualisation outputs (generated)
โ
โโโ dataset/
โ โโโ create_dataset.py # Sample dataset generator
โโโ static/
โ โโโ css/style.css
โ โโโ js/main.js
โ โโโ images/
โโโ templates/
โโโ index.html
Running the Notebooks
pip install -r requirements.txt
jupyter notebook
Run in order: 01_EDA โ 02_Feature_Engineering โ 03_Model_Training โ 04_Model_Evaluation
๐ ๏ธ Tech Stack
| Layer | Technology |
|---|---|
| Backend | Python, Flask, Gunicorn |
| ML / NLP | scikit-learn, NLTK, pandas, numpy |
| Visualisation | matplotlib, seaborn |
| Frontend | Vanilla HTML/CSS/JS, dark mode |
| Server | Nginx + systemd |
๐ค Contributing
Ideas for contributions:
- ๐ Browser extension that checks articles in-page
- ๐ค Fine-tune a BERT/RoBERTa model for better accuracy
- ๐ฑ Mobile-friendly UI improvements
- ๐๏ธ Support for more languages
git checkout -b feature/your-feature
git commit -m 'Add your feature'
git push origin feature/your-feature
# Open a Pull Request
๐ License
MIT ยฉ Mohd Aasim Ansari
Fighting misinformation one article at a time. If this helped, please โญ star the repo!
ุงุณุชูุดู ู ุดุงุฑูุน ู ุดุงุจูุฉ ูู ุฑุชุจุทุฉ
ุฌุงุฑู ุงูุชุญู ููโฆ