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
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.
This project leverages a powerful stack of modern NLP tools and libraries.
Follow these steps to set up and run the project locally within the provided Docker environment.
- Docker: You must have Docker installed and running.
- WDPS Docker Image: The project is designed to run inside the
karmaresearch/wdps2Docker container. Ensure you have this container running.docker ps
- Clone the Repository:
git clone https://github.com/dettinjo/LLM-Fact-Auditor.git cd LLM-Fact-Auditor - 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
- 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
- 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
The main script is designed to read questions from standard input and write the processed output to standard output.
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.txtFor 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.txtInput 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.
- 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).
Distributed under the MIT License. See LICENSE for more information.
This project was created for the Web Data Processing Systems course (XM_40020) at Vrije Universiteit Amsterdam.
Group Members:
- Joel Dettinger - j.dettinger@student.vu.nl
- Ruida Zhou - r.zhou4@student.vu.nl
- Hongqian Xia - h.xia@student.vu.nl
- Angelo De Nadai - a.denadai@student.vu.nl
Project Link: https://github.com/dettinjo/LLM-Fact-Auditor
- Vrije Universiteit Amsterdam
- Hugging Face for the incredible
transformerslibrary and model hosting. - The developers of spaCy, Stanza, and the Wikidata platform.
- Othneil Drew's Best-README-Template