arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2405.00253cs.CLcs.SE
收藏

CodeHalu:通过基于执行的验证调查大语言模型中的代码幻觉

CodeHalu: Investigating Code Hallucinations in LLMs via Execution-based Verification

Hong Kong Baptist University(香港浸会大学);UC Santa Barbara(加州大学圣巴巴拉分校);UC Berkeley(加州大学伯克利分校);Alibaba Group(阿里巴巴集团);The University of Tokyo(东京大学);University of Alberta(阿尔伯塔大学)

Yuchen Tian, Weixiang Yan, Qian Yang, Xuandong Zhao, Qian Chen, Wen Wang, Ziyang Luo, Lei Ma, Dawn Song

AI总结:

本文提出代码幻觉概念及基于执行验证的分类方法,并开发CodeHalu检测算法和含8,883个样本的基准,评估17个LLM以提升代码生成可靠性。

摘要:

大语言模型(LLMs)在代码生成方面取得了显著进展,为开发者提供了突破性的自动化编程支持。然而,LLMs经常生成语法正确甚至语义上看似合理的代码,但这些代码可能无法按预期执行或满足特定需求。代码领域中这种幻觉现象尚未被系统性地探索。为了推进社区对这一问题的理解和研究,我们引入了代码幻觉的概念,并提出了一种基于执行验证的代码幻觉分类方法。我们将代码幻觉分为四大类:映射幻觉、命名幻觉、资源幻觉和逻辑幻觉,每个类别进一步细分为不同的子类别,以便以更细粒度理解和解决LLMs在代码生成中面临的独特挑战。此外,我们提出了一种名为CodeHalu的动态检测算法,旨在检测和量化代码幻觉。我们还引入了CodeHaluEval基准,该基准包含来自699个任务的8,883个样本,用于系统性地定量评估代码幻觉。通过使用该基准评估17个流行的LLMs,我们揭示了它们在代码生成准确性和可靠性方面的显著差异,为进一步提升LLMs的代码生成能力提供了详细见解。CodeHalu基准和代码可在https://github.com/yuchen814/CodeHalu公开获取。

英文摘要:

Large Language Models (LLMs) have made significant progress in code generation, offering developers groundbreaking automated programming support. However, LLMs often generate code that is syntactically correct and even semantically plausible, but may not execute as expected or fulfill specified requirements. This phenomenon of hallucinations in the code domain has not been systematically explored. To advance the community's understanding and research on this issue, we introduce the concept of code hallucinations and propose a classification method for code hallucination based on execution verification. We categorize code hallucinations into four main types: mapping, naming, resource, and logic hallucinations, with each category further divided into different subcategories to understand and address the unique challenges faced by LLMs in code generation with finer granularity. Additionally, we present a dynamic detection algorithm called CodeHalu designed to detect and quantify code hallucinations. We also introduce the CodeHaluEval benchmark, which includes 8,883 samples from 699 tasks, to systematically and quantitatively evaluate code hallucinations. By evaluating 17 popular LLMs using this benchmark, we reveal significant differences in their accuracy and reliability in code generation, offering detailed insights for further improving the code generation capabilities of LLMs. The CodeHalu benchmark and code are publicly available at https://github.com/yuchen814/CodeHalu.

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

↑