PhantomWiki
PhantomWiki generates on-demand datasets to evaluate reasoning and retrieval capabilities of LLMs.
We provide a single script to evaluate your own model on PhantomWiki via vLLM.
Contents
🚀 Quickstart
First install Prolog on your machine, then PhantomWiki with pip:
pip install phantom-wiki
[!NOTE] This package has been tested with Python 3.12. We require Python 3.10+ to support match statements.
To build from source, you can clone this repository and run pip install ..
Generate PhantomWiki datasets with random generation seed 1:
- In Python:
import phantom_wiki as pw
pw.generate_dataset(
output_dir="/path/to/output",
seed=1,
use_multithreading=True,
)
- In a terminal:
phantom-wiki-generate -od "/path/to/output" --seed 1 --use-multithreading
(You can also use the shorthand alias pw-generate.)
[!NOTE] We do not support
--use-multithreadingon macOS yet, so you should skip this flag (or set it toFalse).
The following generation script creates datasets of various sizes with random generation seed 1:
./data/generate-v1.sh /path/to/output/ 1 --use-multithreading
- Universe sizes 25, 50, 500, ..., 5K, 500K, 1M (number of documents)
- Question template depth 20 (proportional to difficulty)
For example, it executes the following command to generate a size 5K universe (5000 = --max-family-tree-size * --num-family-trees):
pw-generate \
-od /path/to/output/depth_20_size_5000_seed_1 \
--seed 1 \
--question-depth 20 \
--num-family-trees 100 \
--max-family-tree-size 50 \
--max-family-tree-depth 20 \
--article-format json \
--question-format json \
--use-multithreading
Pre-generated PhantomWiki datasets on Huggingface
For convenience of development, we provide pre-generated PhantomWiki datasets on HuggingFace (sizes 50, 500, and 5000 with seeds 1, 2, and 3).
from datasets import load_dataset
# Download the document corpus
ds_corpus = load_dataset("kilian-group/phantom-wiki-v1", "text-corpus")
# Download the question-answer pairs
ds_qa = load_dataset("kilian-group/phantom-wiki-v1", "question-answer")
🔗 Installing dependencies
PhantomWiki uses the Prolog logic programming language, available on all operating systems through SWI-Prolog. We recommend installing SWI-prolog through your distribution or through conda, for example:
# On macOS: with homebrew
brew install swi-prolog
# On Linux: with apt
sudo add-apt-repository ppa:swi-prolog/stable
sudo apt-get update
sudo apt-get install swi-prolog
# On Linux: with conda
conda install conda-forge::swi-prolog
# On Windows: download and install binary from https://www.swi-prolog.org/download/stable
Installing PhantomWiki in development mode
There are 2 options:
-
(Recommended) Install the package in editable mode using pip:
pip install -e .
-
If you use VSCode, you can add to the python path without installing the package:
- Create a file in the repo root called
.env - Add
PYTHONPATH=src - Restart VSCode
- Create a file in the repo root called
🔢 Evaluating LLMs on PhantomWiki
First, install dependencies and vLLM to match your hardware (GPU, CPU, etc.):
pip install phantom-wiki[eval]
If you're installing from source, use pip install -e ".[eval]".
Then run the evaluation script to get F1 scores for your model and PhantomWiki reasoning plots:
# You can modify the script to add more flags to phantom_eval command
./eval/evaluate_with_vllm_on_v1.sh OUTPUT_DIRECTORY MODEL_NAME_OR_PATHS METHODS
# For example, evaluating Qwen/Qwen3-32B, DeepSeek-R1-32B models with Zeroshot, CoT prompt methods and saving in out/ directory,
./eval/evaluate_with_vllm_on_v1.sh out/ "Qwen/Qwen3-32B deepseek-ai/DeepSeek-R1-Distill-Qwen-32B" "zeroshot cot"
The script creates a leaderboard with F1 scores on the PhantomWiki public datasets, and creates the reasoning plot (F1 vs difficulty) at out/figures/difficulty-f1.pdf.
Setting up API keys
Anthropic
- Create an API key at https://console.anthropic.com/settings/keys
- Set your Anthropic API key as an environment variable. Or in your conda environment:
export ANTHROPIC_API_KEY=xxxxx
# or
conda env config vars set ANTHROPIC_API_KEY=xxxxx
Rate limits: https://docs.anthropic.com/en/api/rate-limits#updated-rate-limits
:rotating_light: The Anthropic API has particularly low rate limits so it takes longer to get predictions.
Google Gemini
- Create an API key at https://aistudio.google.com/app/apikey
- Set your Gemini API key as an environment variable. Or in your conda environment:
export GEMINI_API_KEY=xxxx
# or
conda env config vars set GEMINI_API_KEY=xxxxx
Llama API
- Create an API key at https://llama.developer.meta.com/api-keys/?team_id=1032428561758393
- Set you Llama API key as an environment variable. Or in your conda environment:
export LLAMA_API_KEY="xxxx"
# or
conda env config vars set LLAMA_API_KEY="xxxxx"
OpenAI
- Create an API key at https://platform.openai.com/settings/organization/api-keys
- Set your OpenAI API key as an environment variable. Or in your conda environment:
export OPENAI_API_KEY=xxxxx
# or
conda env config vars set OPENAI_API_KEY=xxxxx
TogetherAI
- Register for an account at https://api.together.ai
- Set your TogetherAI API key as an environment variable. Or in your conda environment:
export TOGETHER_API_KEY=xxxxx
# or
conda env config vars set TOGETHER_API_KEY=xxxxx
vLLM
Original setup instructions: https://docs.vllm.ai/en/stable/getting_started/installation.html#install-the-latest-code
Additional notes:
- It's recommended to download the model manually:
huggingface-cli download MODEL_REPO_ID
The models and their configs are downloaded directly from HuggingFace and almost all models on HF are fair game (see also: https://docs.vllm.ai/en/stable/models/supported_models.html#supported-models)
Reproducing LLM evaluation results in the paper
🧪 To generate the predictions from an LLM with a prompting METHOD, run the following command:
python -m phantom_eval --method METHOD --server SERVER --model_name MODEL_NAME_OR_PATH --split_list SPLIT_LIST -od OUTPUT_DIRECTORY
Closed-source LLMs through Anthropic, OpenAI, Gemini etc.
We implement lightweight interfaces to Anthropic, OpenAI, Gemini, and Together APIs, which you can select by specifying SERVER, e.g. anthropic, openai, gemini, together respectively.
Example usages:
METHODcan bezeroshot,fewshot,cot,react,zeroshot-ragetc.- Evaluate GPT-4o through checkpoint names
--server openai --model_name gpt-4o-2024-11-20or with name aliases--server openai --model_name gpt-4o. We pass on the model name to the API, so any LLM name supported by the API is supported by our interface. Similarly for Anthropic, Gemini, and Together.
Open-weights LLMs through vLLM
We also implement an interface to vllm server to evaluate local LLMs on your GPUs.
We use the API server mode by default, but offline batch evaluation can be faster for prompt methods zeroshot, fewshot, and cot.
- API (online) server mode. First, serve the LLM manually with
vllm serve MODEL_NAME_OR_PATHand then runphantom_evalwith flags--server vllm. For example:
python -m phantom_eval --method METHOD --server vllm --model_name MODEL_NAME_OR_PATH --split_list SPLIT_LIST -od OUTPUT_DIRECTORY
- Offline (batch) server mode. Run
phantom_evalwith flags--server vllm --inf_vllm_offline. For example:
python -m phantom_eval --method METHOD --server vllm --inf_vllm_offline --model_name MODEL_NAME_OR_PATH --split_list SPLIT_LIST -od OUTPUT_DIRECTORY
Example usages:
- Evaluate Huggingface LLMs through Model Card name
--server vllm --inf_vllm_offline --model_name deepseek-ai/DeepSeek-R1-Distill-Qwen-32B, or through local weights path--server vllm --inf_vllm_offline --model_name /absolute/path/to/weights/. - Evaluate LoRA weights through Model Card name and path to LoRA
--server vllm --inf_vllm_offline --model_name deepseek-ai/DeepSeek-R1-Distill-Qwen-32B --inf_vllm_lora_path /path/to/lora/weights/.
[!NOTE] For vLLM inference, make sure to request access for Gemma, Llama 3.1, 3.2, and 3.3 models on HuggingFace before proceeding.
[!TIP] To generate a slurm script for clusters at Cornell (g2, empire, aida) with the appropriate GPU allocation, run
bash eval/create_eval.shscript and follow the prompted steps.
Generating tables and figures
📊 To generate the tables and figures, run the following command from the root directory, replacing METHODS with a space-separated list of prompting techniques e.g. "zeroshot cot zeroshot-rag cot-rag react".
./eval/evaluate.sh OUTPUT_DIRECTORY MODEL_NAME_OR_PATH METHODS
# For local datasets, specify the dataset path and add the --from_local flag
DATASET="/path/to/dataset/" ./eval/evaluate.sh OUTPUT_DIRECTORY MODEL_NAME_OR_PATH METHODS --from_local
Here, OUTPUT_DIRECTORY is the same as when generating the predictions. This script will create the following subdirectories in OUTPUT_DIRECTORY: scores/ and figures/.
📃 Citation
@article{gong2025phantomwiki,
title={{PhantomWiki}: On-Demand Datasets for Reasoning and Retrieval Evaluation},
author={Gong, Albert and Stankevi{\v{c}}i{\=u}t{\.e}, Kamil{\.e} and Wan, Chao and Kabra, Anmol and Thesmar, Raphael and Lee, Johann and Klenke, Julius and Gomes, Carla P and Weinberger, Kilian Q},
journal={arXiv preprint arXiv:2502.20377},
year={2025}
}
Metadata
Release files for phantom-wiki 1.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| phantom_wiki-1.0.3.tar.gz | 171.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| phantom_wiki-1.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 340.9 kB
Release files / phantom_wiki-1.0.3.tar.gz
| Download URL | phantom_wiki-1.0.3.tar.gz |
|---|---|
| Size | 171.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2daeb73034fb4e22f00d3f2c2e6991bf8e3a38315c1e12427a4c4d9511bdc27d
|
|
BLAKE2b-256 checksum How to use checksums |
295ab532a7cf795a8e28cad94ef2397cdf5b3e8a97595c94a77b1b65e897b910
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 23, 2026.
Transparency logRelease files / phantom_wiki-1.0.3-py3-none-any.whl
| Download URL | phantom_wiki-1.0.3-py3-none-any.whl |
|---|---|
| Size | 169.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
866b87284c740d0e8d1b6a5b5dfdcf4de8eddedb7eebe063718f428d02429e84
|
|
BLAKE2b-256 checksum How to use checksums |
29d48d3b4324e2ebd3791e0d79e159725e8aeb303156ffab54315e0ea51786f1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 23, 2026.
Transparency log