FacTool is an innovative framework designed for detecting factual errors in texts generated by large language models, including ChatGPT. In this article, we will walk you through the installation process, quick start guide, and how to leverage its capabilities for various tasks such as knowledge-based QA, code generation, mathematical reasoning, and scientific literature reviews.
Installation Guide
Before diving into using FacTool, you’ll need to set it up correctly. Here’s how you can do it:
- For General Users:
bash pip install factool - For Developers:
bash git clone git@github.com:GAIR-NLPfactool.git cd factool pip install -e .
Quick Start
Get your API keys ready to interact with FacTool effectively. Follow these steps:
- Obtain your OpenAI API key from here.
- For knowledge-based QA, you need a Serper API key from Serper.
- For scientific literature reviews, acquire a Scraper API key from ScraperAPI.
With the keys in hand, you can begin implementing FacTool. The following overview explains what to do next:
Understanding the Code
To help you visualize, let’s liken using FacTool to preparing a meal where different ingredients correspond to APIs and specific tasks.
- Gather Ingredients: This step involves obtaining your API keys, just as you would gather necessary ingredients for a recipe.
- Mixing Ingredients: The main function combines these keys with the FacTool class initiation—like mixing ingredients together to create your dish.
- Cooking Time: Execution of the model is where the actual cooking happens. You input your prompts and receive evaluations of your initial “dish”—the output from FacTool.
- Tasting and Adjusting: You assess the output, just like tasting your food to adjust seasonings—if the factuality isn’t right, you’ll know something needs to change.
Here’s a quick usage example:
python
from factool import Factool
# Initialize a Factool instance with your keys.
factool_instance = Factool("gpt-4")
inputs = [
{
"prompt": "Introduce Graham Neubig",
"response": "Graham Neubig is a professor at MIT",
"category": "kbqa"
}
]
response_list = factool_instance.run(inputs)
print(response_list)
Troubleshooting
If you encounter issues while using FacTool, consider these common pitfalls and solutions:
- Missing API keys: Ensure all required API keys are correctly set up in your environment variables.
- Invalid input format: Double-check your input structure against the expected format; errors often stem from simple misconfigurations.
- Dependency errors: Make sure all necessary dependencies are installed as specified in the installation instructions.
For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.
Understanding Output Structure
The response from FacTool includes a detailed summary of the factuality checks, similar to receiving a detailed review after your meal preparation. Here’s an example structure:
python
{
"average_claim_level_factuality": ...,
"average_response_level_factuality": ...,
"detailed_information": [
{
"prompt": ...,
"response": ...,
"category": ...,
"claims": [...],
"queries": [...],
"evidences": [...],
"claim_level_factuality": [...],
"response_level_factuality": ...
}
]
}
Conclusion
FacTool provides a comprehensive framework for verifying the factuality of AI-generated outputs across multiple domains. By following this guide, you’re well on your way to utilizing this tool effectively, ushering in a new level of accuracy in AI-generated text.
At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

