Skip to main content
QUICK REVIEW

[논문 리뷰] Beyond Functional Correctness: Exploring Hallucinations in LLM-Generated Code

Fang Liu, Yang Liu|arXiv (Cornell University)|2024. 04. 01.
Low-power high-performance VLSI design인용 수 30
한 줄 요약

이 연구는 대형 언어 모델이 생성한 코드의 환각을 분석하고, 5가지 환각 범주 체계를 개발하며, 평가를 위한 HalluCode를 만들고, 현재 모델들이 그러한 환각을 인식하고 완화하는 데 어려움을 겪고 있음을 보인다.

ABSTRACT

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의 향후 탐지, 평가 및 완화 전략을 안내할 실증적 통찰을 제공하는 것.

제안 방법

  • HumanEval 및 DS-1000 데이터세트에서 CodeGen, CodeRL, ChatGPT로부터 13,968개의 코드 스니펫을 수집하고 분석을 위해 3,084개를 샘플링했다.
  • 다수의 주석가를 포함한 주제 분석을 사용하여 환각의 분류체계(5개 범주, 19개 유형)를 도출했다.
  • 분류체계를 NLP 환각 범주에 매핑하고 분포, 동시발생, 모델 차이를 분석했다.
  • Code Alpaca에서 파생된 5,663개의 Python 작업으로 HalluCode를 구축하고, 유형 인식 점수화 및 규칙 기반 접근법을 통해 환각 주입을 설계했다; 환각 인식 및 완화 평가를 수행했다.
  • HalluCode에서 최첨단 모델(ChatGPT-4, CodeLlama-7B, DeepSeek-Coder-7B)을 평가하여 인식 및 완화 능력을 평가했다.

실험 결과

연구 질문

  • RQ1LLM이 생성한 코드에서 널리 나타나는 환각의 유형과 분포는 무엇인가?
  • 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가 만들고, 인간 에디터가 검토했습니다.