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

61 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

πŸ‘₯ 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

  •  
  •