arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2605.17029cs.SEcs.AI
收藏

大型语言模型在代码生成中的任务回避

Task Abstention for Large Language Models in Code Generation

Yanke Zhou, Yuhao Tan, Senrong Xu, Zenan Li, Yuan Yao, Taolue Chen, Xiaoxing Ma

AI总结:

本文研究了大型语言模型在代码生成任务中是否应回避生成可能产生幻觉的代码,提出了一种基于多重假设检验原理的校准回避规则,通过代码执行结果评估生成一致性,无需依赖Oracle测试用例或外部数据库,提供了一种可靠的安全且稳健的代码生成机制。

摘要:

大型语言模型(LLMs)已经革新了自动化代码生成。然而,一个严重的问题是所谓的'幻觉',即LLMs可能生成看似合理但功能上错误的代码。在本文中,我们研究了任务回避问题,即确定给定的LLM是否应回避执行特定的代码生成任务以避免可能的幻觉。我们的方法特征是一种校准的回避规则,基于多重假设检验原理。该规则通过代码执行结果评估生成一致性,使其能够处理语义等价代码的语法多样性,而无需依赖Oracle测试用例或外部数据库。我们证明了我们的方法在其回避决策上提供了一种严格且分布无关的理论保证。我们使用几个开源代码LLMs在基准数据集上评估了我们的方法。结果表明,我们的方法使生成模型能够更准确且高效地识别并回避导致幻觉的任务,提供了一种可靠的安全且稳健的代码生成机制。

英文摘要:

Large language models (LLMs) have revolutionized automated code generation. One serious concern, however, is the so-called ``hallucination'', i.e., LLMs may generate seemingly plausible but functionally incorrect code. In this paper, we study the task abstention problem, i.e., determining whether a given LLM should abstain from performing a specific code generation task to avoid likely hallucination. Our approach features a calibrated abstention rule, grounded in the principles of multiple hypothesis testing. The rule assesses generation consistency through code execution outcomes, allowing it to handle syntactic diversity of semantically equivalent code without reliance on oracle test cases or external databases. We prove that our approach provides a rigorous, distribution-free theoretical guarantee on its abstention decisions. We evaluate our method on benchmark datasets using several open-source code LLMs. Results show that our method allows generative models to more accurately and efficiently identify and abstain from tasks that induce hallucination compared to existing techniques, providing a reliable mechanism for safer and more robust code generation.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑