Official repository for the research paper: "Automating Mathematical Proof Generation Using Large Language Model Agents and Knowledge Graphs"
- First download elan
- Clone and build the repository:
git clone --recurse-submodules https://github.com/vinli0921/LLM-proof.git
cd LLM-proof
cd mathlib4
lake buildCreate a virtual environment in the root directory of the repository:
python -m venv venvOn macOS and Linux:
source venv/bin/activateOn Windows:
venv\Scripts\activateInstall all required packages and dependencies:
pip install -r requirements.txt- Create a
.envfile in the root directory of the repository - Copy the content from
.env.exampleinto the newly created.envfile - Configure the variables with appropriate values
- Download the latest XML dump from: https://proofwiki.org/xmldump/latest.xml.gz
- Extract the file to obtain
latest.xml - Move
latest.xmlto the root directory of the repository
Run the extraction script:
python Graph_Creation/extract_proofs_XML.py latest.xmlRun the database upload script:
python neo4j_kg.pyThis should successfully upload approximately 60,000 nodes and 300,000 relationships.
If you're creating the graph from scratch:
-
Delete the existing graph (optional):
python Knowledge_Graph/neo4j_delete.py
-
Initialize constraints and load data in Python:
from Knowledge_Graph.neo4j_kg import gds, create_constraints, load_nodes, load_relationships, append_embeddings with gds.session() as session: create_constraints(session) load_nodes(session, 'nodes.csv') load_relationships(session, 'relationships.csv') append_embeddings(session, 'embeddings.csv')
There are two ways to create node embeddings:
-
From the
nodes.csvfile:from Graph_Creation.embedding_chunks import generate_embeddings generate_embeddings('nodes.csv', 'embeddings.csv')
-
From Neo4j:
from Graph_Creation.embedding_chunks import generate_neo4j_embeddings generate_neo4j_embeddings('embeddings.csv')
After generating embeddings with either method, upload them in Python:
from Knowledge_Graph.neo4j_kg import gds, append_embeddings
with gds.session() as session:
append_embeddings(session, 'embeddings.csv')Create a vector index for fast cosine similarity in Python:
from Graph_Creation.vector_functions import gds, create_vector_index
with gds.session() as session:
create_vector_index(session)- Edit
retrieval_agent_RAG.pyandretrieval_agent.pyto configure:- The LLM model for the Proof Generation agent (default is GPT-4o)
- The dataset by changing the dataset name in the
load_test_datafunction
Three datasets are currently available in this repository:
datasets/minif2f.jsonldatasets/proofnet.jsonldatasets/mustard_short.jsonl
Remember to rename both the logging and results files to match your test configuration.
We provide three LLM testing frameworks:
-
Default RAG + Knowledge Graph
- Location:
algos_retrieval - Base:
retrieval_agent.py - RAG:
retrieval_agent_RAG.py - Graph + RAG:
retrieval_agent_graph_RAG.py
- Location:
-
Best-of-N
- Built on top of the RAG + Knowledge Graph setup
- Location:
algos_best_of_n
-
Tree Search
- Built on top of the Best-of-N framework
- Location:
algos_tree_search
Each folder contains two versions: one adapted for the OpenAI API and one for the TogetherAI API (for open-source models). Feel free to adapt them to other inference APIs such as Anthropic or Hugging Face.
Before running the file: ensure that your system has the killall command.
You can check by running:
which killallIf the command doesn't exist, install it:
sudo apt-get update
sudo apt-get install psmiscNow you can run the retrieval agent:
python retrieval_agent.pyor
python3 retrieval_agent.pyTo use multiple GPUs (NVIDIA):
CUDA_VISIBLE_DEVICES=0,1 python3 retrieval_agent.py