Skip to content

Fake News Detection System using a fine tuned BERT. Has semantic understanding of text input, thus, has a lot higher accuracy than non NLP ML models

License

Notifications You must be signed in to change notification settings

ItsTSH/Fake-News-Detection-System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

55 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ” Fake News Detection System

License: MIT Python FastAPI React BERT

A modern web application leveraging deep learning to detect fake news from legitimate content with up to 90% accuracy.

preview.mp4
Fake News Detection System Preview

๐Ÿ“‹ Table of Contents

๐ŸŒŸ Overview

This project implements a Fake News Detection System using a fine-tuned BERT architecture. The system analyzes news content and classifies it as either legitimate or fake news with high accuracy, helping users identify misinformation in digital content.

โœจ Features

  • High Accuracy Detection: Custom BERT model with 90% classification accuracy
  • User-Friendly Interface: Modern React frontend
  • API Integration: Well-documented FastAPI backend for easy integration
  • Reproducible Research: Complete Jupyter notebook with model training process

๐Ÿ› ๏ธ Tech Stack

Backend

  • Model: Custom BERT architecture based on bert-base-uncased from Huggingface
  • Framework: FastAPI
  • Language: Python 3.8+
  • ML Libraries: PyTorch, Transformers, Scikit-learn

Frontend

  • Framework: React 18+ with Vite
  • UI Components: Shadcn UI
  • Styling: Tailwind CSS
  • HTTP Client: Axios
  • State Management: React Context API

Development & Deployment

  • Version Control: Git
  • Documentation: Jupyter Notebooks
  • Package Management: npm, pip

๐Ÿ“ Project Structure

fake-news-detection/
โ”œโ”€โ”€ README.md                             # Project documentation
โ”œโ”€โ”€ LICENSE                               # Project License
โ”œโ”€โ”€ backend/                              # FastAPI server
โ”‚   โ”œโ”€โ”€ app.py                            # API entry point
โ”‚   โ”œโ”€โ”€ model_download_helper.py          # Script to automatically download model files from cloud storage
โ”‚   โ”œโ”€โ”€ notebook/                         # Jupyter Notebook
โ”‚   โ”œโ”€โ”€ models/                           # ML model definitions
โ”‚   โ””โ”€โ”€ requirements.txt                  # Python dependencies
โ”œโ”€โ”€ images/                               # Project Screenshots
โ”‚   โ””โ”€โ”€ screenshot.jpeg                   # UI Preview
โ””โ”€โ”€ frontend/                             # Vite-React application
    โ”œโ”€โ”€ src/
    โ”‚   โ”œโ”€โ”€ components/                   # UI components
    โ”‚   โ”œโ”€โ”€ pages/                        # Application pages
    โ”‚   โ”œโ”€โ”€ ui/                           # ShadCN UI
    โ”‚   โ”œโ”€โ”€ context/                      # React Context for Manual Theme Switching
    โ”‚   โ”œโ”€โ”€ lib/                          # TW Library
    โ”‚   โ”œโ”€โ”€ App.jsx                       # Application
    โ”‚   โ”œโ”€โ”€ App.css                       # Application CSS
    โ”‚   โ”œโ”€โ”€ index.css                     # Main CSS file
    โ”‚   โ””โ”€โ”€ main.jsx                      # Main React Component
    โ”œโ”€โ”€ package.json                      # JS dependencies
    โ””โ”€โ”€ tailwind.config.js                # Tailwind configuration

๐Ÿš€ Installation

Prerequisites

  • Python 3.8+
  • Node.js 16+
  • npm or yarn
  • Git

Clone the Repository

git clone https://github.com/ItsTSH/Fake-News-Detection-System
cd fake-news-detection-system

Backend Setup

cd backend
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install -r requirements.txt

Frontend Setup

cd frontend
npm install  # or yarn install

๐Ÿ’ป Usage

Start the Backend Server

cd backend
uvicorn app.main:app --reload

Start the Frontend Development Server

cd frontend
npm run dev  # or yarn dev

Access the application at http://localhost:5173

Main Endpoint

Endpoint Method Description
/predict POST Submit text for fake news analysis

๐Ÿง  Model Architecture

The fake news detection model is based on the BERT base architecture from Huggingface with the following modifications:

  1. Pre-trained Base: bert-base-uncased from Huggingface
  2. Layer Freezing: Most BERT layers are frozen during training for transfer learning efficiency
  3. Custom Classification Head: Additional layers for the specific task of fake news detection
  4. Hyperparameter Tuning: Optimized learning rate, batch size, and training epochs

For detailed architecture and training process, refer to the Jupyter notebook in the model/notebooks/ directory.

๐Ÿ“Š Performance

  • Accuracy: upto 90% on test dataset
  • F1 Score: 0.86
  • Precision: 0.91
  • Recall: 0.91

๐Ÿ—ƒ๏ธ Dataset

๐Ÿ”ฎ Future Work

  • Support for multi-language fake news detection
  • Support for news content along with the title
  • Integration with browser extensions for real-time checking
  • Explainable AI features to highlight suspicious text segments
  • Model versioning and A/B testing infrastructure
  • User feedback loop for continuous model improvement

๐Ÿ‘ฅ Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


โญ If you find this project helpful, please consider starring the repository! ๐ŸŒŸ


Made with โค๏ธ by Tejinder Singh Hunjan

About

Fake News Detection System using a fine tuned BERT. Has semantic understanding of text input, thus, has a lot higher accuracy than non NLP ML models

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Contributors 2

  •  
  •