Introduction
Knowledge Base Question Answering (KBQA) involves answering natural language questions by querying structured data, typically represented as triples (Subject-Relation-Object). A significant challenge in this field is multi-hop reasoning, where the answer is not directly linked to the subject but requires traversing multiple relationships (e.g., "Who directed the film starring the actor born in Hawaii?").
Existing approaches often struggle with a trade-off between accuracy and transparency. Information Retrieval (IR) methods frequently operate as "black boxes," providing answers without explaining the underlying logic. Conversely, Semantic Parsing methods that translate questions into complex languages like SPARQL can be overly verbose and difficult for models to generate accurately for multi-step queries. This paper introduces LLMProKBQA, a framework designed to bridge this gap by combining the linguistic capabilities of Large Language Models (LLMs) with the rigorous, interpretable logic of the Prolog programming language.
The LLMProKBQA Framework
The authors propose a "generation-retrieval" framework that prioritizes both accuracy and traceability. The process is divided into three distinct stages:
- Topic Entity Masking: To ensure the model focuses on logical structure rather than specific names, a BERT-CRF model identifies entities and replaces them with a generic
[ENT]token. - Logical Form Generation: Open-source LLMs, such as ChatGLM2-6B and Baichuan2-7B, are fine-tuned using Parameter-Efficient Fine-Tuning (PEFT/QLoRA). The models are trained to translate masked natural language questions into concise Prolog queries. For example, a question about a sibling's name is transformed into a multi-step Prolog rule incorporating relationship and gender filters.
- Prolog-based Answer Retrieval: The Knowledge Base is converted into Prolog facts, and the generated query is executed via the SWI-Prolog engine. Crucially, the engine returns not just the answer, but the specific triples traversed, providing a clear visualization of the reasoning path.
To address potential data gaps in the Knowledge Base, the framework incorporates logic rules for reversibility and transitivity, enabling the system to infer missing links during the reasoning process.
Datasets and Evaluation
The model was evaluated using two primary benchmarks:
- MetaQA: A large-scale dataset in the movie domain containing over 400,000 questions across 1-hop, 2-hop, and 3-hop complexity levels.
- WebQSP: A complex dataset based on Freebase, featuring real-world natural language questions.
- One-Shot MetaQA: A specialized subset designed to test the model's ability to generalize from a single example of a question template.
Key Results
The LLMProKBQA method demonstrated state-of-the-art performance across all tested benchmarks. On the MetaQA dataset, the model achieved near-perfect accuracy, significantly outperforming established baselines like NSM and EmbedKGQA.
On the WebQSP dataset, the framework reached 79.9% Hit@1, representing a substantial improvement over the previous best-performing baseline (NSM at 68.7%). Furthermore, in "one-shot" testing, the LLM+Prolog approach maintained high accuracy on complex 3-hop questions where traditional models typically fail, proving its superior ability to grasp underlying logic from minimal data.
Discussion and Insights
The success of LLMProKBQA highlights several key insights:
- Prolog as a Logical Bridge: Prolog's conciseness makes it an ideal target for LLM generation compared to more verbose languages like SPARQL. It maps more naturally to the way both humans and LLMs structure logical sequences.
- Decoupling Language from Logic: By masking entities, the LLM learns the "grammar" of the query rather than memorizing facts. This allows relatively small 7B parameter models to outperform much larger or more specialized architectures.
- Traceability and Reliability: Because the final step is a symbolic logic execution, the reasoning path is a literal map of the data used. This eliminates "hallucinations" in the reasoning process; if a path is incorrect, it is immediately visible to human auditors.
Limitations and Future Work
Despite its strengths, the current framework relies on templated training data for Prolog generation. Future research will focus on handling more diverse, non-templated natural language and optimizing the retrieval module for billion-triple datasets like Wikidata. Additionally, improving the system's ability to handle highly ambiguous or noisy natural language remains a priority.
Summary updated