Running on WSL/Linux is recommended.
Install uv if it is not already available:
pip install uvInstall dependencies:
uv syncActivate the environment:
source .venv/bin/activateDue to the size of the dataset, I just upload some small size dataset, for full dataset link here (https://huggingface.co/datasets/megagonlabs/cypherbench)
There are 2 ways to run data processing.
Process split train:
python3 process_data.py \
--data-dir benchmarks/Cypherbench \
--processed-data-dir processed_data/benchmarks/Cypherbench \
--model-path Qwen/Qwen3-0.6B \
--model-type qwen \
--data-process-workers 8 \
--max-prompt-length 797 --dev-num 1 --split trainProcess split valid:
python3 process_data.py \
--data-dir benchmarks/Cypherbench \
--processed-data-dir processed_data/benchmarks/Cypherbench \
--model-path Qwen/Qwen3-0.6B \
--model-type qwen \
--data-process-workers 8 \
--max-prompt-length 797 --dev-num 1 --split validProcess split test:
python3 process_data.py \
--data-dir benchmarks/Cypherbench \
--processed-data-dir processed_data/benchmarks/Cypherbench \
--model-path Qwen/Qwen3-0.6B \
--model-type qwen \
--data-process-workers 8 \
--max-prompt-length 947 --dev-num 1 --split testbash scripts/process_cypherbench_qwen3_0.6B.shThis script runs train, valid, then test sequentially.
Run the Finetune LoRA script for the teacher model:
bash scripts/teacher_lora/lora_qwen3_4B.shThe LoRA checkpoint will be saved under results/finetune/qwen3/sft_4B/.... Use the final checkpoint path as the teacher adapter path for the CypherKD step.
Run CypherKD with the teacher-peft-path produced by the previous step:
TEACHER_PEFT_PATH="results/finetune/qwen3/sft_4B/<your-run>/<checkpoint-step>" \
bash scripts/cypherkd/cypherkd_qwen3_0.6B_4B.shReplace <your-run>/<checkpoint-step> with the actual teacher LoRA adapter path.
Run inference with the student model and the trained LoRA checkpoint:
python3 infer.py \
--benchmark Cypherbench \
--data_source local \
--model Qwen/Qwen3-0.6B \
--ckpt_path results/qwen3/<cypherkd-run>/<checkpoint-step> \
--device cuda \
--batch-size 1 \
--max-length 1034 \
--output_path results/Cypherbench/cypherkd_predictions.jsonFor a quick debug run on a small subset:
python3 infer.py \
--benchmark Cypherbench \
--data_source local \
--model Qwen/Qwen3-0.6B \
--ckpt_path results/qwen3/<cypherkd-run>/<checkpoint-step> \
--device cuda \
--batch-size 1 \
--max-length 1034 \
--limit 10 \
--output_path results/Cypherbench/cypherkd_predictions_debug.jsonSet Neo4j credentials before running evaluation:
export NEO4J_USERNAME=neo4j
export NEO4J_PASSWORD="<your-neo4j-password>"Run Neo4j locally and create/load one database per Cypherbench graph. The scorer defaults to neo4j://127.0.0.1:7687 and expects database names such as:
nbacompanygeographymoviepoliticsfictional.characterflight.accident
Import Cypherbench graphs into Neo4j:
python3 import_db_to_neo4j.py --graphs all --overwriteTo import only selected graphs:
python3 import_db_to_neo4j.py --graphs nba company geography --overwriteThe import script reads graph files from:
benchmarks/Cypherbench/graphs/simplekg/<graph_name>_simplekg.jsonIf your Neo4j server is not running on the default host/port, override them:
python3 import_db_to_neo4j.py \
--graphs nba \
--overwrite \
--host neo4j://127.0.0.1 \
--port 7687The inference output must be a JSON file containing graph, gold_cypher, and pred_cypher fields. The examples below assume the inference output was saved to:
results/Cypherbench/cypherkd_predictions.jsonCypherbench example:
python3 src/calculate_scores_cypherbench.py \
--input results/Cypherbench/cypherkd_predictions.json \
--output_dir results/Cypherbench/calculated_scores_Qwen3_0.6B_cypherkd \
--subset nbaRun the same command for other Cypherbench subsets by changing --subset, for example company, geography, movie, politics, fictional_character, or flight_accident.
Useful options:
--limit N: evaluate only the firstNsamples for the selected graph--metrics execution_accuracy psjs executable: choose which metrics to compute--host,--port,--database,--username,--password: override Neo4j connection settings
Aggregate one scored graph file:
python3 src/calculate_scores_json.py \
--input results/Cypherbench/calculated_scores_Qwen3_0.6B_cypherkd/nba_cyphers_result.json \
--output results/Cypherbench/calculated_scores_Qwen3_0.6B_cypherkd/nba_summary.jsonThis reports the average of:
execution_accuracypsjsexecutable