Papers
Topics
Authors
Recent
Gemini 2.5 Flash
Gemini 2.5 Flash
41 tokens/sec
GPT-4o
59 tokens/sec
Gemini 2.5 Pro Pro
41 tokens/sec
o3 Pro
7 tokens/sec
GPT-4.1 Pro
50 tokens/sec
DeepSeek R1 via Azure Pro
28 tokens/sec
2000 character limit reached

LLM Hallucinations in Practical Code Generation: Phenomena, Mechanism, and Mitigation (2409.20550v1)

Published 30 Sep 2024 in cs.SE, cs.AI, and cs.CL

Abstract: Code generation aims to automatically generate code from input requirements, significantly enhancing development efficiency. Recent LLMs based approaches have shown promising results and revolutionized code generation task. Despite the promising performance, LLMs often generate contents with hallucinations, especially for the code generation scenario requiring the handling of complex contextual dependencies in practical development process. Although previous study has analyzed hallucinations in LLM-powered code generation, the study is limited to standalone function generation. In this paper, we conduct an empirical study to study the phenomena, mechanism, and mitigation of LLM hallucinations within more practical and complex development contexts in repository-level generation scenario. First, we manually examine the code generation results from six mainstream LLMs to establish a hallucination taxonomy of LLM-generated code. Next, we elaborate on the phenomenon of hallucinations, analyze their distribution across different models. We then analyze causes of hallucinations and identify four potential factors contributing to hallucinations. Finally, we propose an RAG-based mitigation method, which demonstrates consistent effectiveness in all studied LLMs. The replication package including code, data, and experimental results is available at https://github.com/DeepSoftwareAnalytics/LLMCodingHallucination

User Edit Pencil Streamline Icon: https://streamlinehq.com
Authors (5)
  1. Ziyao Zhang (16 papers)
  2. Yanlin Wang (76 papers)
  3. Chong Wang (308 papers)
  4. Jiachi Chen (45 papers)
  5. Zibin Zheng (194 papers)
X Twitter Logo Streamline Icon: https://streamlinehq.com