This repository is a clean research workspace for a new method for reliable multi-hop question answering over knowledge graphs.
The active experiment separates two jobs:
- A recall-oriented retriever proposes many executable relation paths and returns their union subgraph.
- A compact inverse generator verbalizes what each path means. Its generated question is compared with the user's question to verify the path.
- Candidate paths are ranked by semantic similarity between the reconstructed question and the user's question. The endpoint entities of the selected executable path become the predicted answers.
The retriever uses the released SRTK iterative relation-path implementation and its multi-KG scorer. This is a PullNet-style retrieve-then-reason boundary, not an assertion that we are running PullNet itself: PullNet's source and checkpoint were not publicly released. The inverse verifier is the component under study.
inverse_verifier/contains the one active data, training, and evaluation pipeline.inverse_verifier/retrieval.pyadapts SRTK to local question graphs and emits candidate paths plus a retrieved subgraph.docs/inverse_verifier_generation_report.mdfreezes the generator training, results, and known weaknesses.docs/inverse_verifier_hypothesis.mdstates the mechanism and falsifying experiment.docs/faithful_inverse_training.mddefines the balanced executable corpus and the path-faithfulness objective introduced after the full-pipeline failure analysis.AGENTS.mdanddocs/research_protocol.mddefine the research discipline.data/contains local datasets and is ignored by Git.runs/contains local experimental outputs and is ignored by Git.
The controlled data contains one- to three-relation KQA Pro and WebQSP chains. Intermediate and answer entity names are hidden. KQA relations and relation compositions are withheld for dedicated transfer splits, and official WebQSP test questions remain disjoint from the multi-KG training data.
The current follow-up generates a balanced executable path corpus, optionally naturalizes its controlled questions with a local model, and optimizes both complete intent generation and gold-vs-hard-negative sequence likelihood.
python3 -m inverse_verifier synthesize \
--paths 30000 \
--output runs/inverse_verifier/faithful_data
python3 -m inverse_verifier naturalize \
--data runs/inverse_verifier/faithful_data \
--output runs/inverse_verifier/faithful_data_natural \
--model qwen3:8b
python3 -m inverse_verifier train \
--data runs/inverse_verifier/faithful_data_natural \
--base-model runs/inverse_verifier/joint_ranker_multi_kg_b4/model \
--regime faithful_synthetic \
--objective faithful_inverse \
--output runs/inverse_verifier/faithful_inverse
python3 -m inverse_verifier faithfulness \
--data runs/inverse_verifier/faithful_data_natural/dev_faithful.jsonl \
--model runs/inverse_verifier/faithful_inverse/model \
--output runs/inverse_verifier/faithful_inverse_evalNaturalization can use one independent Ollama server per GPU. Repeat
--ollama-host for every endpoint; batches run concurrently while output rows
remain in source order and the run remains resumable.
python3 -m inverse_verifier naturalize \
--data runs/inverse_verifier/faithful_data \
--output runs/inverse_verifier/faithful_data_natural \
--model qwen3:8b \
--ollama-host http://127.0.0.1:11434 \
--ollama-host http://127.0.0.1:11435For a quick local check, add --limit 128 to training and
--limit-per-split 32 to evaluation. Full outputs are limited to
metrics.json, predictions.jsonl, and report.md.
Install the maintained retrieval dependency:
pip install -e '.[retrieval]'Measure candidate-path and evidence recall without running the verifier:
python3 -m inverse_verifier retrieve \
--limit 100 \
--output runs/inverse_verifier/path_retrieval_100Run retrieval followed by inverse verification. Candidates are checked in batches of five; verification stops when the best semantic similarity reaches 0.85, or after 100 candidates, and otherwise selects the best seen candidate. Scores below 0.5 are logged but deliberately have no fallback yet.
python3 -m inverse_verifier verify \
--model runs/inverse_verifier/joint_ranker_multi_kg_b4/model \
--limit 100 \
--output runs/inverse_verifier/full_pipeline_old_generator_100This run intentionally uses the frozen pre-type-aware generator. Its 100-question controlled run reached 90% candidate-path recall but selected the gold path only 37% of the time. The faithful inverse experiment directly targets the observed hop omission and direction failures before full retrieval is rerun.
The current controlled WebQSP run uses the supplied topic entities and local question neighborhoods. It therefore tests path retrieval and verification, not standalone entity linking or full-Freebase serving.
Before implementation, record:
- The general failure in existing KGQA methods.
- The computational reason for that failure.
- The proposed mechanism and why it should address the cause.
- The strongest matched baselines.
- The smallest experiment that could reject the hypothesis.
- The intermediate and final-answer measurements that determine the result.
Previous experimental methods remain recoverable from Git history, but they are not architectural dependencies or fallbacks for this experiment.
Naturalize a bounded, balanced faithful corpus without exposing canonical questions or entity names to the model. Start with a dry run; it creates request files and prints a conservative cost estimate without submitting them:
python3 -m inverse_verifier naturalize-openai \
--data runs/inverse_verifier/faithful_data \
--output runs/inverse_verifier/faithful_data_openai_3k \
--max-paths 3000 \
--max-negatives 3 \
--dry-runThen export the API key in the shell and rerun without --dry-run. The command submits resumable
OpenAI Batch jobs sequentially, waits for completion, validates outputs, and writes accepted train
and dev JSONL files. It defaults to the fixed gpt-4o-mini-2024-07-18 snapshot and refuses to
proceed when its estimate exceeds $8.
export OPENAI_API_KEY='...'
python3 -m inverse_verifier naturalize-openai \
--data runs/inverse_verifier/faithful_data \
--output runs/inverse_verifier/faithful_data_openai_3k \
--max-paths 3000 \
--max-negatives 3The current production path compiles traversal directions into explicit raw triples, grounds each unique relation with labeled facts from the local KQA Pro and WebQSP graphs, builds a reusable relation glossary with GPT-4o, generates questions from compact logical queries with GPT-4o, and independently verifies exact path meaning with GPT-4o mini. Metadata and low-confidence relation meanings are rejected rather than guessed. Full builds use the OpenAI Batch API internally; small pilots run synchronously. All stages resume from the same output directory.
Run a small dataset build before the full corpus:
export OPENAI_API_KEY='...'
python3 -m inverse_verifier build-naturalized-dataset \
--output runs/inverse_verifier/naturalized_dataset_40 \
--max-paths 40After inspecting that output, build the 3,000-path corpus with a new output directory:
python3 -m inverse_verifier build-naturalized-dataset \
--output runs/inverse_verifier/naturalized_dataset_3000_v8 \
--max-paths 3000The July 2026 build accepted 1,979 validated rows. GPT-4o mini verified the first four final
batches. When the API account reached its billing limit, a calibrated local Qwen 3 8B verifier
completed the fifth batch; its model and pilot agreement are recorded in the manifest. See
docs/inverse_verifier_generation_report.md for the corpus audit and remaining limitations.
The inverse generator and final comparator are separate modules. The generator verbalizes each executable path. The comparator receives a whole candidate set for one original question and learns to assign probability to any valid path with a listwise multi-positive softmax loss.
First materialize the questions produced by the frozen generator. This prevents the comparator from training on oracle paraphrases that it would not observe at inference:
python3 -m inverse_verifier prepare-comparator \
--data runs/inverse_verifier/naturalized_dataset_3000_executable_direction_v1 \
--generator runs/inverse_verifier/faithful_inverse_qwen25_3b_lora_v1/model \
--output runs/inverse_verifier/comparator_data_qwen25_v1 \
--batch-size 8 \
--device cudaTrain the full comparison input with DeBERTa:
python3 -m inverse_verifier train-comparator \
--data runs/inverse_verifier/comparator_data_qwen25_v1 \
--base-model microsoft/deberta-v3-base \
--input-mode question_generated_path \
--output runs/inverse_verifier/deberta_comparator_qgp_v1 \
--device cudaThe two input ablations use the same command with question_generated or
question_path. Evaluate a trained comparator against the unchanged cosine
baseline:
python3 -m inverse_verifier evaluate-comparator \
--data runs/inverse_verifier/comparator_data_qwen25_v1 \
--model runs/inverse_verifier/deberta_comparator_qgp_v1/model \
--semantic-model BAAI/bge-small-en-v1.5 \
--output runs/inverse_verifier/deberta_comparator_qgp_v1_eval \
--device cudaCandidate path serialization includes the start entity, ordered relation traversals and directions, intermediate and answer types, and the concrete endpoint when available. Relation proposal and inverse generation are not changed by comparator training.
Use the trained comparator in the retrieval pipeline with:
python3 -m inverse_verifier verify \
--model runs/inverse_verifier/faithful_inverse_qwen25_3b_lora_v1/model \
--comparison-mode cross_encoder \
--comparator-model runs/inverse_verifier/deberta_comparator_qgp_v1/model \
--output runs/inverse_verifier/full_pipeline_cross_encoder_v1Cross-encoder mode scores every generated candidate up to the existing verification cap before selecting an answer. It does not use the cosine threshold, because raw classifier logits are not calibrated to that threshold.
For held-out generator evaluations that already contain generated candidate
questions, pass their predictions.jsonl directly to prepare-comparator.
The command preserves each recorded evaluation slice and does not regenerate
questions:
python3 -m inverse_verifier prepare-comparator \
--data runs/inverse_verifier/faithful_inverse_qwen25_3b_lora_v1_kqa_eval/predictions.jsonl \
--generator runs/inverse_verifier/faithful_inverse_qwen25_3b_lora_v1/model \
--output runs/inverse_verifier/comparator_kqa_heldout_qwen25_v1Path correctness and question equivalence are different labels. A wrong path can produce a question that is textually equivalent to the original when the generator collapses or repairs its meaning. Build a separate judge-labeled benchmark from the held-out generated questions:
export OPENAI_API_KEY='...'
python3 -m inverse_verifier build-semantic-benchmark \
--data runs/inverse_verifier/comparator_kqa_heldout_qwen25_v1 \
--output runs/inverse_verifier/comparator_kqa_semantic_v1 \
--model gpt-4o-2024-11-20The judge sees only the original question and candidate questions. It never sees paths, path labels, negative categories, or endpoint correctness. Multiple candidates may be equivalent. Candidate sets with no equivalent generated question are saved separately and excluded from comparator ranking. These are silver semantic labels and should be manually audited before being reported as benchmark results.
Evaluate the question-only comparator on the semantic labels:
python3 -m inverse_verifier evaluate-comparator \
--data runs/inverse_verifier/comparator_kqa_semantic_v1 \
--model runs/inverse_verifier/deberta_comparator_question_generated_v1/model \
--semantic-model BAAI/bge-small-en-v1.5 \
--output runs/inverse_verifier/comparator_kqa_semantic_generated_v1_eval \
--split test_kqa_val \
--device cuda