arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2511.00776cs.SE
收藏

LLM中代码幻觉的系统性文献综述:特征、缓解方法、挑战及可靠AI的未来方向

A Systematic Literature Review of Code Hallucinations in LLMs: Characterization, Mitigation Methods, Challenges, and Future Directions for Reliable AI

Harbin Institute of Technology(哈尔滨工业大学);Shandong Agriculture and Engineering University(山东农业工程学院);Monash University Malaysia(马来西亚马来亚大学);Tianjin University(天津大学);Chongqing University(重庆大学);Singapore Management University(新加坡管理大学);Sun Yat-sen University(中山大学)

Cuiyun Gao, Guodong Fan, Chun Yong Chong, Shizhan Chen, Chao Liu, David Lo, Zibin Zheng, Qing Liao

AI总结:

本综述从定义与成因、通用缓解策略、代码特定挑战及评估基准四个维度,系统回顾了LLM代码幻觉现象,总结了60篇相关研究,并指出了可靠AI的未来方向。

摘要:

模型幻觉是大型语言模型(LLM)面临的最关键挑战之一,尤其是在高风险的代码智能任务中。随着LLM日益融入软件工程任务,理解并缓解代码中的幻觉变得至关重要。本综述从四个关键角度对面向代码的LLM中的幻觉现象进行了系统性回顾。首先,我们调研了60篇论文以定义代码语境下的幻觉,并总结了其主要成因,如数据噪声、暴露偏差和语义基础不足,同时追溯了自然语言处理(NLP)和软件工程社区文献的最新趋势。其次,我们回顾了更广泛范围内的模型幻觉综述,并总结了具有代表性的幻觉缓解策略,如知识增强生成、约束解码和后编辑。第三,我们回顾了针对代码智能的方法,并强调了加剧幻觉的代码特定挑战,包括语法敏感性、严格类型系统和对外部库的依赖。同时,我们分析了新兴的代码智能任务(如程序分析、符号执行和单元测试)如何被用于检测和缓解幻觉。第四,我们总结了当前的评估基准,涵盖从静态指标到动态检查(如编译和执行正确性),并强调了对面向幻觉的基准的需求。

英文摘要:

Model hallucination is one of the most critical challenges faced by Large Language Models (LLMs), especially in high-stakes code intelligence tasks. As LLMs become increasingly integrated into software engineering tasks, understanding and mitigating hallucination in code becomes essential. In this survey, we provide a systematic review of hallucination phenomena in code-oriented LLMs from four key perspectives. First, we begin by surveying 60 papers to define hallucination in the context of code and summarize its primary causes, such as data noise, exposure bias, and insufficient semantic grounding, while also tracing recent trends in literature across natural language processing (NLP) and software engineering communities. Second, we review model hallucination surveys in a broader span and summarize representative hallucination mitigation strategies, such as knowledge-enhanced generation, constrained decoding, and post-editing. Third, we review approaches targeted for code intelligence and highlight code-specific challenges that aggravate hallucination, including syntax sensitivity, strict type systems, and dependence on external libraries. Meanwhile, we analyze how emerging code intelligence tasks, e.g., program analysis, symbolic execution, and unit testing, are utilized to detect and mitigate hallucinations. Fourth, we summarize current evaluation benchmarks, ranging from static metrics to dynamic checks, e.g., compilation and execution correctness, and emphasize the need for hallucination-oriented benchmarks.

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

↑