Abstract
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.
Original language | English |
---|---|
Title of host publication | Proceedings of the 39th AAAI Conference on Artificial Intelligence, AAAI 2025 |
Publisher | AAAI press |
Pages | 25300-25308 |
Number of pages | 9 |
ISBN (Print) | 157735897X, 9781577358978 |
DOIs | |
Publication status | Published - 11 Apr 2025 |
Event | 39th AAAI Conference on Artificial Intelligence, AAAI 2025 - Philadelphia, United States Duration: 25 Feb 2025 → 4 Mar 2025 https://ojs.aaai.org/index.php/AAAI/issue/archive (Conference Proceedings) |
Publication series
Name | Proceedings of the AAAI Conference on Artificial Intelligence |
---|---|
Publisher | Association for the Advancement of Artificial Intelligence |
Number | 24 |
Volume | 39 |
ISSN (Print) | 2159-5399 |
ISSN (Electronic) | 2374-3468 |
Conference
Conference | 39th AAAI Conference on Artificial Intelligence, AAAI 2025 |
---|---|
Country/Territory | United States |
City | Philadelphia |
Period | 25/02/25 → 4/03/25 |
Internet address |
|