通过双阶段元测试检测基于大语言模型的文本到SQL生成中的幻觉
Hallucination Detection for LLM-based Text-to-SQL Generation via Two-Stage Metamorphic Testing
AI总结:
通过双阶段元测试方法检测基于大语言模型的文本到SQL生成中的幻觉,无需地面真实数据,提升检测性能。
摘要:
在文本到SQL生成中,大型语言模型(LLMs)已显示出强大的泛化和适应能力。然而,LLMs有时会生成幻觉,即不现实或不合逻辑的内容,这会导致错误的SQL查询,并对下游应用产生负面影响。检测这些幻觉尤其具有挑战性。现有的文本到SQL错误检测方法,专为传统深度学习模型设计,在应用于LLMs时面临显著限制。这主要是由于地面真实数据的稀缺性。为了解决这一挑战,我们提出了SQLHD,一种基于元测试(MT)的新型幻觉检测方法,无需标准答案。SQLHD将检测任务分为两个连续的阶段:通过八个结构感知的元测试关系(MRs)进行模式链接幻觉检测,这些MRs扰动比较词、实体、句子结构或数据库模式;并通过九个逻辑感知的MRs进行逻辑综合幻觉检测,这些MRs突变前缀词、极值表达、比较范围或整个数据库。在每个阶段,LLM被单独调用以生成模式映射或SQL制品;后续输出通过相应的MRs与源对应物交叉检查,任何违反均被标记为幻觉,而无需地面真实SQL。实验结果表明,我们的方法在F1分数方面表现优异,范围从69.36%到82.76%。此外,SQLHD在LLM自我评估方法上表现更优,有效识别了文本到SQL任务中的幻觉。
英文摘要:
In Text-to-SQL generation, large language models (LLMs) have shown strong generalization and adaptability. However, LLMs sometimes generate hallucinations, i.e.,unrealistic or illogical content, which leads to incorrect SQL queries and negatively impacts downstream applications. Detecting these hallucinations is particularly challenging. Existing Text-to-SQL error detection methods, which are tailored for traditional deep learning models, face significant limitations when applied to LLMs. This is primarily due to the scarcity of ground-truth data. To address this challenge, we propose SQLHD, a novel hallucination detection method based on metamorphic testing (MT) that does not require standard answers. SQLHD splits the detection task into two sequentiial stages: schema-linking hallucination detection via eight structure-aware Metamorphic Relations (MRs) that perturb comparative words, entities, sentence structure or database schema, and logical-synthesis hallucination detection via nine logic-aware MRs that mutate prefix words, extremum expressions, comparison ranges or the entire database. In each stage the LLM is invoked separately to generate schema mappings or SQL artefacts; the follow-up outputs are cross-checked against their source counterparts through the corresponding MRs, and any violation is flagged as a hallucination without requiring ground-truth SQL. The experimental results demonstrate our method's superior performance in terms of the F1-score, which ranges from 69.36\% to 82.76\%. Additionally, SQLHD demonstrates superior performance over LLM Self-Evaluation methods, effectively identifying hallucinations in Text-to-SQL tasks.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。