Code-Style In-Context Learning for Knowledge-Based Question Answering
Zhijie Nie, Richong Zhang, Zhongyuan Wang, Xudong Liu
Abstract
Current methods for Knowledge-Based Question Answering (KBQA) usually rely on complex training techniques and model frameworks, leading to many limitations in practical applications. Recently, the emergence of In-Context Learning (ICL) capabilities in Large Language Models (LLMs) provides a simple and training-free semantic parsing paradigm for KBQA: Given a small number of questions and their labeled logical forms as demo examples, LLMs can understand the task intent and generate the logic form for a new question. However, current powerful LLMs have little exposure to logic forms during pre-training, resulting in a high format error rate. To solve this problem, we propose a code-style in-context learning method for KBQA, which converts the generation process of unfamiliar logical form into the more familiar code generation process for LLMs. Experimental results on three mainstream datasets show that our method dramatically mitigated the formatting error problem in generating logic forms while realizing a new SOTA on WebQSP, GrailQA, and GraphQ under the few-shot setting. The code and supplementary files are released at https://github.com/ Arthurizijar/KB-Coder.
Ask about this paper
Your agent reads all of it.
Lune indexed this paper to the last equation, along with the top-tier papers that cite it. Ask a question and the answer quotes them.
Your agent calls
Luneget_paper_fulltext
Free to start. No credit card required.
Terminal
Install the CLIlune papers fulltext d0cb45c8-63b8-41cb-9af2-357ca6b01e18Cited by top-tier papers16
- Enhancing Complex Question Answering over Knowledge Graphs through Evidence Pattern RetrievalWentao Ding, Jinmao Li, Liangchuan Luo, Yuzhong QuWWW 2024 · 32 citations
- Middleware for LLMs: Tools Are Instrumental for Language Agents in Complex EnvironmentsYu Gu, Yiheng Shu, Hao Yu, Xiao Liu et al.EMNLP 2024 · 11 citations
- Debate on Graph: A Flexible and Reliable Reasoning Framework for Large Language ModelsJie Ma, Zhitao Gao, Qi Chai, Wangchun Sun et al.AAAI 2025 · 8 citations
- QueryAgent: A Reliable and Efficient Reasoning Framework with Environmental Feedback based Self-CorrectionXiang Huang, Sitao Cheng, Shanshan Huang, Jiayu Shen et al.ACL 2024 · 3 citations
- Privacy-protected Retrieval-Augmented Generation for Knowledge Graph Question AnsweringYunfeng Ning, Mayi Xu, Jintao Wen, Qiankun Pi et al.AAAI 2026 · 3 citations
Builds on14
- Chain-of-Thought Prompting Elicits Reasoning in Large Language ModelsJason Wei, Xuezhi Wang, Dale Schuurmans, Maarten Bosma et al.NeurIPS 2022 · 22,562 citations
- SimCSE: Simple Contrastive Learning of Sentence EmbeddingsTianyu Gao, Xingcheng Yao, Danqi ChenEMNLP 2021 · 2,496 citations
- Self-Consistency Improves Chain of Thought Reasoning in Language ModelsXuezhi Wang, Jason Wei, Dale Schuurmans, Quoc V. Le et al.ICLR 2023 · 681 citations
- Least-to-Most Prompting Enables Complex Reasoning in Large Language ModelsDenny Zhou, Nathanael Schärli, Le Hou, Jason Wei et al.ICLR 2023 · 318 citations
- Beyond I.I.D.: Three Levels of Generalization for Question Answering on Knowledge BasesYu Gu, Sue Kase, Michelle Vanni, Brian M. Sadler et al.WWW 2021 · 304 citations
Related papers
- Few-shot In-context Learning on Knowledge Base Question AnsweringTianle Li, Xueguang Ma, Alex Zhuang, Yu Gu et al.ACL 2023 · 55 citations
- SymKGQA: Few-Shot Knowledge Graph Question Answering via Symbolic Program Generation and ExecutionPrerna Agarwal, Nishant Kumar, Srikanta BedathurACL 2024 · 6 citations
- Promoting Knowledge Base Question Answering by Directing LLMs to Generate Task-relevant Logical FormsJianqi Gao, Jian Cao, Ranran Bu, Nengjun Zhu et al.AAAI 2025 · 6 citations
- CompKBQA: Component-wise Task Decomposition for Knowledge Base Question AnsweringYuhang Tian, Dandan Song, Zhijing Wu, Pan Yang et al.EMNLP 2025 · 1 citation
- Interactive-KBQA: Multi-Turn Interactions for Knowledge Base Question Answering with Large Language ModelsGuanming Xiong, Junwei Bao, Wen ZhaoACL 2024
