用外部记忆库修正大模型生成的查询,大幅减少错误链接。
Reducing Hallucinations in Language Model-based SPARQL Query Generation Using Post-Generation Memory Retrieval
- 生成查询时先用占位符,再通过外部记忆库精准填充知识图谱链接。
- 在多个数据集上显著提升查询正确率,几乎消除链接幻觉。
- 适合需要高准确率的问答系统和知识图谱应用开发者。
从自然语言问题生成SPARQL查询对高效、准确地从知识图谱(KG)中检索结构化数据至关重要。尽管大型语言模型(LLMs)已被广泛用于生成SPARQL查询,但它们在基于内部参数化知识生成知识图谱元素(如统一资源标识符,URIs)时,常出现幻觉和分布外错误。我们提出PGMR(后生成记忆检索)框架:先由LLM使用自然语言占位符生成中间查询,再通过非参数化记忆模块检索并解析正确的KG URI。PGMR在多种LLM、数据集及分布偏移条件下显著提升查询正确性(SQM),同时近乎完全抑制了URI幻觉。关键的是,我们证明了PGMR具备更强的安全性和鲁棒性:通过设定检索置信度阈值,可有效拒绝无支持的查询;且检索器对记忆噪声高度鲁棒,即使记忆规模扩大至9倍并混入无关实体,仍保持良好性能。
原文摘要 · Abstract (English)
The ability to generate SPARQL queries from natural language questions is crucial for ensuring efficient and accurate retrieval of structured data from knowledge graphs (KG). While large language models (LLMs) have been widely adopted for SPARQL query generation, they are often susceptible to hallucinations and out-of-distribution errors when generating KG elements, such as Uniform Resource Identifiers (URIs), based on opaque internal parametric knowledge. We propose PGMR (Post-Generation Memory Retrieval), a modular framework where the LLM produces an intermediate query using natural language placeholders for URIs, and a non-parametric memory module is subsequently employed to retrieve and resolve the correct KG URIs. PGMR significantly enhances query correctness (SQM) across various LLMs, datasets, and distribution shifts, while achieving the near-complete suppression of URI hallucinations. Critically, we demonstrate PGMR's superior safety and robustness: a retrieval confidence threshold enables PGMR to effectively refuse to answer queries that lack support, and the retriever proves highly resilient to memory noise, maintaining strong performance even when the non-parametric memory size is scaled up to 9 times with irrelevant, distracting entities.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。