arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2406.10279cs.SEcs.AIcs.CRcs.LG
收藏

我们有一个包给你!代码生成LLM中包幻觉的全面分析

We Have a Package for You! A Comprehensive Analysis of Package Hallucinations by Code Generating LLMs

University of Texas at San Antonio(德克萨斯大学圣安东尼奥分校);University of Oklahoma(俄克拉荷马大学);Virginia Tech(弗吉尼亚理工大学)

Joseph Spracklen, Raveen Wijewickrama, A H M Nazmus Sakib, Anindya Maiti, Bimal Viswanath, Murtuza Jadliwala

AI总结:

本文全面评估了代码生成LLM中的包幻觉现象,发现商业模型平均幻觉率为5.2%,开源模型为21.7%,并提出了有效的缓解策略以在保持代码质量的同时显著减少幻觉。

摘要:

Python和JavaScript等流行编程语言对集中式包仓库和开源软件的依赖,结合代码生成大型语言模型(LLMs)的出现,对软件供应链造成了一种新型威胁:包幻觉。这些幻觉源于使用LLMs生成代码时的事实冲突错误,代表了一种新型的包混淆攻击,对软件供应链的完整性构成了关键威胁。本文对不同编程语言、设置和参数下的包幻觉进行了严格且全面的评估,探讨了多种模型和配置如何影响生成错误包推荐的可能性,并识别了该现象的根本原因。使用16个流行的代码生成LLMs和两个独特的提示数据集,我们生成了576,000个代码样本,涵盖两种编程语言,并对其进行了包幻觉分析。我们的发现表明,商业模型的包幻觉平均百分比至少为5.2%,开源模型为21.7%,包含惊人的205,474个独特的幻觉包名示例,进一步突显了该威胁的严重性和普遍性。为解决此问题,我们实施了多种幻觉缓解策略,并表明它们能够在保持代码质量的同时显著减少包幻觉的数量。我们的实验和发现突显了包幻觉作为使用最先进LLMs进行代码生成时的一个持续且系统性的现象,以及一个值得研究界紧急关注的重要挑战。

英文摘要:

The reliance of popular programming languages such as Python and JavaScript on centralized package repositories and open-source software, combined with the emergence of code-generating Large Language Models (LLMs), has created a new type of threat to the software supply chain: package hallucinations. These hallucinations, which arise from fact-conflicting errors when generating code using LLMs, represent a novel form of package confusion attack that poses a critical threat to the integrity of the software supply chain. This paper conducts a rigorous and comprehensive evaluation of package hallucinations across different programming languages, settings, and parameters, exploring how a diverse set of models and configurations affect the likelihood of generating erroneous package recommendations and identifying the root causes of this phenomenon. Using 16 popular LLMs for code generation and two unique prompt datasets, we generate 576,000 code samples in two programming languages that we analyze for package hallucinations. Our findings reveal that that the average percentage of hallucinated packages is at least 5.2% for commercial models and 21.7% for open-source models, including a staggering 205,474 unique examples of hallucinated package names, further underscoring the severity and pervasiveness of this threat. To overcome this problem, we implement several hallucination mitigation strategies and show that they are able to significantly reduce the number of package hallucinations while maintaining code quality. Our experiments and findings highlight package hallucinations as a persistent and systemic phenomenon while using state-of-the-art LLMs for code generation, and a significant challenge which deserves the research community's urgent attention.

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

↑