Skip to main content
SAICA-KG

Papers

CodeHalu: Investigating Code Hallucinations in LLMs via Execution-based Verification

Yuchen Tian, Weixiang Yan, Qian Yang, Xuandong Zhao, Qian Chen, Wen Wang, Ziyang Luo, Lei Ma · 2024 · AAAI Conference on Artificial Intelligence

Source →arXiv:2405.00253DOI: 10.1609/aaai.v39i24.3471738 citations
failure-mode-taxonomyhallucinationcode-generationbenchmarkexecution-based-verification

TL;DR

Introduces the concept of code hallucinations and a four-class execution- verification taxonomy (mapping, naming, resource, logic). Provides the CodeHalu detection algorithm and the CodeHaluEval benchmark (8,883 samples over 699 tasks) across 17 LLMs.

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.

Editorial notes

Must-cite. The "mapping / naming / resource / logic" axis is a direct predecessor to SAICA-KG's FailureMode partition (fabrication / logic_error / dependency_blindness). Cite as prior art for the fabrication FailureMode and for execution-based detection Tools.

View raw YAML on GitHub →