HarshShaha/hallucination-detector-news

Python

0

4 commits

updated Apr 5, 2026

See the code

README

🧠 Hallucination Detection System (News Domain)

πŸš€ Overview

This project presents a Context-Aware Hallucination Detection System designed to identify factual inconsistencies in LLM-generated text.

Unlike generic approaches, this system uses a news-domain knowledge base built from the CNN/DailyMail dataset, making it more robust for real-world scenarios.

The system combines:

  • πŸ”Ž Retrieval (FAISS + semantic embeddings)
  • 🧠 Natural Language Inference (NLI)
  • ⚑ GPU-accelerated batch processing

🎯 Problem Statement

Large Language Models (LLMs) often generate fluent but factually incorrect (hallucinated) content. This project aims to:

Detect whether a given text contains hallucinated claims by verifying it against trusted knowledge sources.


πŸ—οΈ System Architecture

LLM Output
    ↓
Claim Extraction
    ↓
Evidence Retrieval (FAISS + Sentence Transformers)
    ↓
NLI Verification (Transformer Model)
    ↓
Hallucination Classification

🧠 Key Features

  • βœ… Domain-specific (News-based verification)
  • βœ… Hybrid retrieval using semantic embeddings
  • βœ… Transformer-based fact verification (NLI)
  • βœ… GPU optimization for fast inference
  • βœ… Separation of training and inference pipelines
  • βœ… Flask-based web interface
  • βœ… Modular and scalable design

πŸ“Š Dataset

  • Primary Dataset:

    • CNN/DailyMail

The dataset is used to:

  • Build a knowledge base of factual sentences
  • Train a retrieval system for grounding claims

βš™οΈ Tech Stack

  • Language: Python
  • Frameworks: PyTorch, HuggingFace Transformers
  • Embeddings: SentenceTransformers
  • Retrieval: FAISS
  • Backend: Flask
  • NLP Tools: NLTK

πŸ“ Project Structure

hallucination_detector/
β”‚
β”œβ”€β”€ training/
β”‚   └── build_kb_and_index.py
β”‚
β”œβ”€β”€ inference/
β”‚   β”œβ”€β”€ verifier_pipeline.py
β”‚   └── app.py
β”‚
β”œβ”€β”€ saved/
β”‚   β”œβ”€β”€ faiss.index
β”‚   └── documents.pkl
β”‚
β”œβ”€β”€ templates/
β”‚   └── index.html
β”‚
β”œβ”€β”€ requirements.txt
└── README.md

πŸš€ Setup Instructions

1️⃣ Clone the Repository

git clone https://github.com/yourusername/hallucination-detector-news.git
cd hallucination-detector-news

2️⃣ Install Dependencies

pip install -r requirements.txt

3️⃣ Build Knowledge Base (One-Time Training)

python training/build_kb_and_index.py

This will:

  • Load news dataset
  • Create sentence-level knowledge base
  • Build FAISS index
  • Save artifacts in /saved/

4️⃣ Run the Application

cd inference
python app.py

Open in browser:

http://127.0.0.1:5000

🌐 Web Interface

  • Enter any text (e.g., LLM output)

  • System detects:

    • βœ… FACTUAL
    • ❌ HALLUCINATED
    • ⚠️ UNCERTAIN

πŸ“Έ Demo

(Add screenshots here)

Example:
"The Eiffel Tower is in Berlin"
β†’ HALLUCINATED ❌

⚑ Performance Optimizations

  • GPU-based inference using PyTorch
  • Batch processing for NLI
  • Precomputed FAISS index
  • Efficient sentence embeddings

πŸ§ͺ Future Work

  • πŸ”₯ Fine-tune NLI model on FEVER
  • 🌐 Real-time news API integration
  • πŸ“Š Evaluation metrics (F1, ROC curves)
  • 🧠 Multi-hop reasoning
  • 🎨 Advanced UI (React/Angular)

πŸ“Œ Applications

  • Fact-checking systems
  • AI content validation
  • News verification platforms
  • Responsible AI systems

πŸ‘¨β€πŸ’» Author

Harsh Shaha

  • Final Year Computer Engineering Student
  • Interested in NLP, Deep Learning, and High-Performance Computing

⭐ Contribute

Feel free to fork, improve, and submit pull requests!


πŸ“œ License

This project is for academic and research purposes.

HarshShaha/hallucination-detector-news

Python

0

4 commits

updated Apr 5, 2026

See the code

README

🧠 Hallucination Detection System (News Domain)

πŸš€ Overview

This project presents a Context-Aware Hallucination Detection System designed to identify factual inconsistencies in LLM-generated text.

Unlike generic approaches, this system uses a news-domain knowledge base built from the CNN/DailyMail dataset, making it more robust for real-world scenarios.

The system combines:

  • πŸ”Ž Retrieval (FAISS + semantic embeddings)
  • 🧠 Natural Language Inference (NLI)
  • ⚑ GPU-accelerated batch processing

🎯 Problem Statement

Large Language Models (LLMs) often generate fluent but factually incorrect (hallucinated) content. This project aims to:

Detect whether a given text contains hallucinated claims by verifying it against trusted knowledge sources.


πŸ—οΈ System Architecture

LLM Output
    ↓
Claim Extraction
    ↓
Evidence Retrieval (FAISS + Sentence Transformers)
    ↓
NLI Verification (Transformer Model)
    ↓
Hallucination Classification

🧠 Key Features

  • βœ… Domain-specific (News-based verification)
  • βœ… Hybrid retrieval using semantic embeddings
  • βœ… Transformer-based fact verification (NLI)
  • βœ… GPU optimization for fast inference
  • βœ… Separation of training and inference pipelines
  • βœ… Flask-based web interface
  • βœ… Modular and scalable design

πŸ“Š Dataset

  • Primary Dataset:

    • CNN/DailyMail

The dataset is used to:

  • Build a knowledge base of factual sentences
  • Train a retrieval system for grounding claims

βš™οΈ Tech Stack

  • Language: Python
  • Frameworks: PyTorch, HuggingFace Transformers
  • Embeddings: SentenceTransformers
  • Retrieval: FAISS
  • Backend: Flask
  • NLP Tools: NLTK

πŸ“ Project Structure

hallucination_detector/
β”‚
β”œβ”€β”€ training/
β”‚   └── build_kb_and_index.py
β”‚
β”œβ”€β”€ inference/
β”‚   β”œβ”€β”€ verifier_pipeline.py
β”‚   └── app.py
β”‚
β”œβ”€β”€ saved/
β”‚   β”œβ”€β”€ faiss.index
β”‚   └── documents.pkl
β”‚
β”œβ”€β”€ templates/
β”‚   └── index.html
β”‚
β”œβ”€β”€ requirements.txt
└── README.md

πŸš€ Setup Instructions

1️⃣ Clone the Repository

git clone https://github.com/yourusername/hallucination-detector-news.git
cd hallucination-detector-news

2️⃣ Install Dependencies

pip install -r requirements.txt

3️⃣ Build Knowledge Base (One-Time Training)

python training/build_kb_and_index.py

This will:

  • Load news dataset
  • Create sentence-level knowledge base
  • Build FAISS index
  • Save artifacts in /saved/

4️⃣ Run the Application

cd inference
python app.py

Open in browser:

http://127.0.0.1:5000

🌐 Web Interface

  • Enter any text (e.g., LLM output)

  • System detects:

    • βœ… FACTUAL
    • ❌ HALLUCINATED
    • ⚠️ UNCERTAIN

πŸ“Έ Demo

(Add screenshots here)

Example:
"The Eiffel Tower is in Berlin"
β†’ HALLUCINATED ❌

⚑ Performance Optimizations

  • GPU-based inference using PyTorch
  • Batch processing for NLI
  • Precomputed FAISS index
  • Efficient sentence embeddings

πŸ§ͺ Future Work

  • πŸ”₯ Fine-tune NLI model on FEVER
  • 🌐 Real-time news API integration
  • πŸ“Š Evaluation metrics (F1, ROC curves)
  • 🧠 Multi-hop reasoning
  • 🎨 Advanced UI (React/Angular)

πŸ“Œ Applications

  • Fact-checking systems
  • AI content validation
  • News verification platforms
  • Responsible AI systems

πŸ‘¨β€πŸ’» Author

Harsh Shaha

  • Final Year Computer Engineering Student
  • Interested in NLP, Deep Learning, and High-Performance Computing

⭐ Contribute

Feel free to fork, improve, and submit pull requests!


πŸ“œ License

This project is for academic and research purposes.