Few-shot In-context Learning on Knowledge Base Question Answering

Tianle Li, Xueguang Ma, Alex Zhuang, Yu Gu, Yu Su, Wenhu Chen

Abstract

Knowledge Base Question Answering (KBQA) traditionally requires large-scale, task-specific datasets to map natural language to complex database schemas. We present KB-BINDER, a "generate-then-bind" framework that enables Large Language Models (LLMs) to perform KBQA with minimal supervision. By using an LLM to generate a structural "draft" of a query and subsequently grounding it in a real-world knowledge base, KB-BINDER achieves state-of-the-art performance on multiple benchmarks, often outperforming fully supervised models.

Introduction

Translating a natural language question into a structured query (e.g., SPARQL) for a Knowledge Base (KB) like Freebase is a challenging task. Historically, models have been "data-hungry," requiring tens of thousands of annotated examples to learn specific machine identifiers (MIDs) and relations. These models often overfit to specific schemas, failing to generalize across different domains.

While LLMs possess impressive general reasoning capabilities, they cannot ingest massive KBs into their context windows. This limitation prevents them from generating executable queries that use exact, correct IDs. KB-BINDER addresses this by decoupling logical reasoning from schema-specific grounding.

The KB-BINDER Framework

KB-BINDER breaks the KBQA process into two distinct stages: Draft Generation and Knowledge Base Binding.

The KB-BINDER architecture: Exemplars guide an LLM to generate drafts, which are then grounded via Entity and Relation Binders.

1. Draft Generation

The LLM (e.g., Codex) is provided with a few "exemplars"—pairs of questions and logical forms. Crucially, machine-readable IDs (like m.0279m) are replaced with "friendly" surface names (like "data compression"). This allows the LLM to leverage its internal semantic knowledge to generate a draft logical form. This draft represents the logical structure of the query but may contain "hallucinated" or slightly inaccurate relation names.

2. Knowledge Base Binding

This stage grounds the draft into the actual KB schema:

  • Entity Binder: Extracts surface names from the draft and uses lexicon-based search (e.g., BM25) to identify the most likely real-world entity IDs.
  • Relation Binder: Searches the KB for actual relations connected to the bound entities. It identifies relations that are semantically similar to the LLM's "hallucinated" guesses (e.g., mapping drug.shape to the official drug_form.shape).

To enhance robustness, KB-BINDER(K) employs majority voting across multiple generated drafts, while KB-BINDER-R uses a retrieval step to select the most relevant exemplars for the input question.

Experimental Evaluation

The framework was evaluated on four diverse KBQA datasets: GrailQA (compositional generalization), WebQSP (simple I.I.D. questions), GraphQA (complex multi-domain queries), and MetaQA (multi-hop reasoning).

Key Results

KB-BINDER demonstrates that high performance is achievable with very few examples:

  • Superior Generalization: On GraphQA, KB-BINDER achieved a 39.5 F1 score, surpassing the previous fully-supervised state-of-the-art by 7.7 points.
  • Scaling Efficiency: On GrailQA, the model matched the performance of a BERT-based ranker fine-tuned on 45,000 annotations using only 40 examples.
  • Multi-hop Reasoning: It reached 99.5% Hits@1 on 3-hop MetaQA, setting a new benchmark for the dataset.
Performance scaling of KB-BINDER on GrailQA, showing coverage and EM score improvements as the number of shots increases.

Discussion and Insights

The success of KB-BINDER highlights that structure is more important than syntax for LLMs in KBQA. By allowing the LLM to focus on the logical structure of a question rather than the exact vocabulary of a database, the system combines flexible reasoning with factual accuracy. Furthermore, using human-readable names in prompts is essential for the LLM to apply its pre-trained knowledge effectively.

Limitations and Future Work

While effective, KB-BINDER introduces higher latency and API costs due to multiple draft generations and KB lookups. Additionally, the system's success is heavily dependent on the quality of the initial draft; if the LLM fails to capture the correct logical structure, the binding stage cannot recover. Future research may explore "Chain-of-Thought" prompting to further refine the drafting phase.

Summary updated

BibTeX
@inproceedings{li2023few,
  author = {Tianle Li and Xueguang Ma and Alex Zhuang and Yu Gu and Yu Su and Wenhu Chen},
  title = {{Few-shot In-context Learning on Knowledge Base Question Answering}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2023},
  doi = {10.18653/v1/2023.acl-long.385},
}
Figure