构建首个代码生成幻觉预测基准,揭示大模型写错代码的规律
Collu-Bench: A Benchmark for Predicting Language Model Hallucinations in Code
- 收集1.3万例代码幻觉数据,包含多模型、多任务场景
- 用机器学习方法预测幻觉,准确率22%至33%
- 适合研究代码安全与大模型可信性的研究人员
尽管大语言模型(LLMs)取得成功,但仍面临幻觉问题——生成看似合理但错误的内容。现有研究多关注图像和自然语言中的幻觉,对代码领域的关注较少,而代码幻觉可能导致错误且脆弱的代码,造成重大经济损失。为推动该领域研究,我们提出Collu-Bench,一个用于预测代码生成(CG)与自动程序修复(APR)任务中大模型代码幻觉的基准。该基准涵盖来自五个数据集的13,234个代码幻觉实例,涉及11种不同大语言模型(包括开源与商业模型)。为深入分析,该基准提供每步输出的对数概率、标记类型及生成代码的执行反馈等详细特征。我们进一步在该基准上进行幻觉预测实验,采用传统机器学习与神经网络方法,准确率达到22.03%至33.15%。实验揭示了代码幻觉模式,指出精确定位幻觉仍具挑战,凸显亟需更先进的检测技术。
原文摘要 · Abstract (English)
Despite their success, large language models (LLMs) face the critical challenge of hallucinations, generating plausible but incorrect content. While much research has focused on hallucinations in multiple modalities including images and natural language text, less attention has been given to hallucinations in source code, which leads to incorrect and vulnerable code that causes significant financial loss. To pave the way for research in LLMs' hallucinations in code, we introduce Collu-Bench, a benchmark for predicting code hallucinations of LLMs across code generation (CG) and automated program repair (APR) tasks. Collu-Bench includes 13,234 code hallucination instances collected from five datasets and 11 diverse LLMs, ranging from open-source models to commercial ones. To better understand and predict code hallucinations, Collu-Bench provides detailed features such as the per-step log probabilities of LLMs' output, token types, and the execution feedback of LLMs' generated code for in-depth analysis. In addition, we conduct experiments to predict hallucination on Collu-Bench, using both traditional machine learning techniques and neural networks, which achieves 22.03 -- 33.15% accuracy. Our experiments draw insightful findings of code hallucination patterns, reveal the challenge of accurately localizing LLMs' hallucinations, and highlight the need for more sophisticated techniques.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。