Dynamic Few-Shot Learning for Knowledge Graph Question Answering
Jacopo D'Abramo, Andrea Zugarini, Paolo Torroni
TL;DR
This paper tackles the KGQA problem by focusing on the query generation step and proposing Dynamic Few-Shot Learning (DFSL), which combines in-context learning with semantic retrieval to dynamically select $k$ similar training examples and enrich prompts. DFSL uses a three-part method: dynamic retrieval of demonstrations, an in-context prompt that incorporates gold entities/relations, and multi-query generation with answer selection to mitigate triple-flip errors and model uncertainty. The approach achieves state-of-the-art or near state-of-the-art results across four KGQA benchmarks (QALD-9 DB, QALD-9 plus, QALD-10, LC-QuAD 2.0) using three backbones (Mixtral, Llama-3, CodeLlama) without fine-tuning, supported by comprehensive ablations. The work highlights the practical impact of dynamic demonstrations and beam-based query generation for scalable, robust KGQA in real-world KG settings, with broad potential for extension to cognate domains such as Text-to-SQL.
Abstract
Large language models present opportunities for innovative Question Answering over Knowledge Graphs (KGQA). However, they are not inherently designed for query generation. To bridge this gap, solutions have been proposed that rely on fine-tuning or ad-hoc architectures, achieving good results but limited out-of-domain distribution generalization. In this study, we introduce a novel approach called Dynamic Few-Shot Learning (DFSL). DFSL integrates the efficiency of in-context learning and semantic similarity and provides a generally applicable solution for KGQA with state-of-the-art performance. We run an extensive evaluation across multiple benchmark datasets and architecture configurations.
