[論文レビュー] Beyond Functional Correctness: Exploring Hallucinations in LLM-Generated Code
この研究は大規模言語モデルによるコード生成における幻覚を分析し、5つの幻覚カテゴリの分類法を開発し、評価のためのHalluCodeを作成し、現行モデルはその種の幻覚を認識・緩和することに苦戦していることを示します。
The rise of Large Language Models (LLMs) has significantly advanced various applications on software engineering tasks, particularly in code generation. Despite the promising performance, LLMs are prone to generate hallucinations, which means LLMs might produce outputs that deviate from users' intent, exhibit internal inconsistencies, or misaligned with the real-world knowledge, making the deployment of LLMs potentially risky in a wide range of applications. Existing work mainly focuses on investigating the hallucination in the domain of Natural Language Generation (NLG), leaving a gap in comprehensively understanding the types, causes, and impacts of hallucinations in the context of code generation. To bridge the gap, we conducted a thematic analysis of the LLM-generated code to summarize and categorize the hallucinations, as well as their causes and impacts. Our study established a comprehensive taxonomy of code hallucinations, encompassing 3 primary categories and 12 specific categories. Furthermore, we systematically analyzed the distribution of hallucinations, exploring variations among different LLMs and benchmarks. Moreover, we perform an in-depth analysis on the causes and impacts of various hallucinations, aiming to provide valuable insights into hallucination mitigation. Finally, to enhance the correctness and reliability of LLM-generated code in a lightweight manner, we explore training-free hallucination mitigation approaches by prompt enhancing techniques. We believe our findings will shed light on future research about code hallucination evaluation and mitigation, ultimately paving the way for building more effective and reliable code LLMs in the future. The replication package is available at https://github.com/Lorien1128/code_hallucination
研究の動機と目的
- LLM生成コードに発生する幻覚の分類法を確立し、それをユーザーの意図・文脈と関連づける。
- コードLLMにおける幻覚の分布と共起を定量化し、それがコードの正確さとどのように関係するかを分析する。
- HalluCodeを開発し、コード生成における幻覚の認識と緩和を評価・改善するベンチマークとする。
- コードLLMの検出・評価・緩和戦略を今後導くための経験的洞察を提供する。
提案手法
- CodeGen、CodeRL、ChatGPTからHumanEvalおよびDS-1000データセットのコードスニペットを13,968件収集し、分析対象として3,084件をサンプリングした。
- 複数のアノテータを用いた主題分析を用いて、幻覚の分類法(5カテゴリ、19タイプ)を導出した。
- 分類法をNLPの幻覚カテゴリーにマッピングし、分布・共起・モデル差を分析した。
- Code Alpaca由来の5,663のPythonタスクを用いてHalluCodeを構築し、タイプ認識スコアリングとルールベースの手法による幻覚の注入を設計し、幻覚認識と緩和の評価を実施した。
- HalluCode上で最先端モデル(ChatGPT-4、CodeLlama-7B、DeepSeek-Coder-7B)を評価し、認識と緩和能力を評価した。
実験結果
リサーチクエスチョン
- RQ1LLMが生成するコードにおける幻覚の prevailタイプと分布はどのようなものか?
- RQ2幻覚タイプは異なるLLM間でどのように共起し、変化するのか?
- RQ3生成コードの機能的正確性と幻覚の関係はどうなるのか?
- RQ4HalluCodeはコード幻覚の検出と緩和をLLM間で効果的にベンチマークできるのか?
主な発見
- 5つの主要幻覚カテゴリと19の葉タイプの分類法、3,084サンプルで2,119件の幻覚を識別。
- Intent Conflicting(32.1%)とContext Deviation(サブタイプとしてInconsistency 31.8%、Repetition 17.3%、Dead Code 3.2%)が最も多く、Knowledge Conflictingが15.1%を占める。
- 幻覚は単一のプログラム内で共起することがあり、Context Repetitionは他のタイプと最も頻繁に共起する(そのようなケースのおよそ1/3)。
- 幻覚を含むコードのごく一部だけが全テストをパスする(≤10%)ことが多く、いくつかのエラーは幻覚に直接起因しない一方、幻覚はしばしば根本的な問題を示唆する。
- HalluCodeには幻覚の認識と緩和を評価するための5,663のPythonタスクが含まれており、オープンソースモデルは強力なプロンプトと比較して幻覚を緩和する能力が限定的であることを示す。
- 異なるモデルは異なる支配的な幻覚タイプを示し、モデルの能力と訓練戦略を反映している。
より良い研究を、今すぐ始めましょう
論文の読解から最終レビューまで、研究時間を劇的に削減しましょう。
クレジットカード登録不要
このレビューはAIが作成し、人間の編集者が確認しました。