Skip to content

dettinjo/LLM-Fact-Auditor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


LLM Fact Auditor

A post-processing pipeline to fact-check, entity-link, and verify answers from Large Language Models.

About the Project · Getting Started · Usage

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Roadmap
  5. License
  6. Contact
  7. Acknowledgments

About The Project

Large Language Models (LLMs) are powerful, but they can produce factually incorrect or unverifiable information—a phenomenon often called "hallucination." This project, LLM Fact Auditor, serves as a robust post-processing pipeline designed to address this challenge. It takes a question and a raw LLM-generated answer, then enriches and verifies it through a multi-stage process.

Here's what it does:

  • Entity Linking: It identifies named entities (like people, places, and organizations) in the text and links them to their corresponding Wikipedia pages, grounding the response in factual data.
  • Answer Extraction: It distills the often verbose LLM response into a concise, direct answer, such as a "yes/no" or a specific entity.
  • Fact-Checking: It verifies the extracted answer's correctness by cross-referencing it with structured knowledge from Wikidata and the content of the linked Wikipedia pages.

This system was developed as a university project to create a practical tool for improving the reliability of AI-generated content.

(back to top)

Built With

This project leverages a powerful stack of modern NLP tools and libraries.

Python Docker Llama PyTorch Transformers spaCy

(back to top)

Getting Started

Follow these steps to set up and run the project locally within the provided Docker environment.

Prerequisites

  • Docker: You must have Docker installed and running.
  • WDPS Docker Image: The project is designed to run inside the karmaresearch/wdps2 Docker container. Ensure you have this container running.
    docker ps

Installation

  1. Clone the Repository:
    git clone https://github.com/dettinjo/LLM-Fact-Auditor.git
    cd LLM-Fact-Auditor
  2. Copy Project Files to Docker: From your host machine's terminal, copy the entire project directory into your running Docker container.
    docker cp ./ <container_id>:/home/user/submission
  3. Access the Container and Set Up Environment:
    # Enter the container's shell
    docker exec -it <container_id> bash
    
    # Navigate to the project directory
    cd /home/user/submission
    
    # Switch to root user to install dependencies
    sudo su
    
    # Create and activate a virtual environment
    python3 -m venv virtual_env
    source virtual_env/bin/activate
  4. Install Dependencies: Install all required Python packages and download the necessary NLP models. This step may take some time.
    # Install Python packages
    pip install -r requirements.txt
    
    # Run the setup script to download all models
    python src/setup.py

(back to top)

Usage

The main script is designed to read questions from standard input and write the processed output to standard output.

Running with Llama 2 (Default)

This command reads questions from test_data/input.txt and saves the structured output to test_data/output.txt.

python3 main.py < ./test_data/input.txt > ./test_data/output.txt

Running with Llama 3

For higher quality answers and faster performance, you can use the Llama 3 model by adding the --llama_ver=3 flag.

python3 main.py --llama_ver=3 < ./test_data/input.txt > ./test_data/output.txt

Example Input & Output

Input Question in input.txt:

question-001	Is Managua the capital of Nicaragua?

Corresponding Output in output.txt:

question-001	R"Yes, Managua is the capital and largest city of Nicaragua."
question-001	A"yes"
question-001	C"correct"
question-001	E"Managua"	"https://en.wikipedia.org/wiki/Managua"
question-001	E"Nicaragua"	"https://en.wikipedia.org/wiki/Nicaragua"

The output format includes the raw Response, extracted Answer, Correctness check, and linked Entities.

(back to top)

Roadmap

  • Implement a more robust relation extraction module.
  • Add support for additional knowledge bases beyond Wikidata.
  • Develop a simple web interface for interactive demonstrations.
  • Expand fact-checking capabilities to handle more complex and nuanced claims.

See the open issues for a full list of proposed features (and known issues).

(back to top)

License

Distributed under the MIT License. See LICENSE for more information.

(back to top)

Contact

This project was created for the Web Data Processing Systems course (XM_40020) at Vrije Universiteit Amsterdam.

Group Members:

Project Link: https://github.com/dettinjo/LLM-Fact-Auditor

(back to top)

Acknowledgments

  • Vrije Universiteit Amsterdam
  • Hugging Face for the incredible transformers library and model hosting.
  • The developers of spaCy, Stanza, and the Wikidata platform.
  • Othneil Drew's Best-README-Template

(back to top)

About

A post-processing pipeline to fact-check, entity-link, and verify answers from Large Language Models (LLMs). Developed for the Web Data Processing Systems course at Vrije Universiteit Amsterdam.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors