Skip to main content
QUICK REVIEW

[논문 리뷰] CodeHalu: Investigating Code Hallucinations in LLMs via Execution-based Verification

Yuchen Tian, Weixiang Yan|arXiv (Cornell University)|2024. 04. 30.
Security and Verification in Computing인용 수 4
한 줄 요약

이 논문은 실행 기반 검증을 사용하여 LLM 내 코드 환각 현상을 정의하고 분류하는 프레임워크인 CodeHalu를 소개한다. 이는 매핑, 이름 지정, 자원, 논리 환각 현상의 네 가지 유형을 제안하며, 동적 탐지 알고리즘과 699개의 작업에 걸쳐 8,883개의 샘플을 포함하는 벤치마크를 제공한다. 16개의 LLM에 대한 평가 결과, 환각 현상 비율이 높게 나타나, 코드 생성에서 모델 신뢰성 향상의 긴급한 필요성을 드러낸다.

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.

연구 동기 및 목표

  • 문자열의 의미적 타당성 대신 실행 정확도를 기반으로 LLM 내 코드 환각 현상을 정의하고 체계적으로 분류하는 것.
  • 코드 생성에서 환각 현상에 대한 표준화된 평가 부재로 인한 런타임 오류 및 보안 취약성 문제를 해결하는 것.
  • 실제 코드 실행을 통해 환각 현상을 실시간으로 탐지할 수 있는 동적 탐지 알고리즘을 개발하는 것.
  • 699개의 작업에 걸쳐 8,883개의 샘플을 포함하는 종합적인 벤치마크(CodeHalu)를 구축하여 LLM 내 환각 현상의 빈도와 유형을 평가하는 것.
  • 16개의 인기 있는 LLM에서 환각 현상의 빈도를 실증적으로 입증하여 향후 기능 정확도 향상을 위한 모델 개선에 기여하는 것.

제안 방법

  • 생성된 코드가 문법적으로는 올바르지만 실행 중 실패하거나 기능적 요구사항을 위반하는 경우를 코드 환각 현상으로 정의한다.
  • 실행 실패 패턴에 기반해 매핑, 이름 지정, 자원, 논리의 네 가지 주요 유형으로 환각 현상을 분류하며, 각 유형은 하위 유형을 포함한다.
  • 테스트 케이스에 대해 생성된 코드를 실행하여 실시간으로 환각 현상을 탐지할 수 있는 동적 탐지 알고리즘을 개발한다.
  • 699개의 프로그래밍 작업과 8,883개의 환각 현상 샘플을 포함하는 CodeHalu 벤치마크를 구축하며, 각 샘플은 기대 동작과 실행 결과로 주석 처리되어 있다.
  • 정확도 검증의 핵심 메커니즘으로 실행 기반 검증을 사용하여, 환각 현상과 단순한 문법적 또는 의미적 오류를 구분한다.
  • 벤치마크를 기반으로 16개의 인기 있는 LLM을 평가하여 환각 현상의 빈도와 유형 분포를 측정한다.
Figure 1: The summary of CodeHalu Benchmark. CodeHalu includes 4 main categories and 8 sub-categories of hallucinations.
Figure 1: The summary of CodeHalu Benchmark. CodeHalu includes 4 main categories and 8 sub-categories of hallucinations.

실험 결과

연구 질문

  • RQ1LLM 기반 코드 생성 중 발생하는 주요 유형과 하위 유형의 코드 환각 현상은 무엇인가?
  • RQ2실행 정확도 기준으로 평가했을 때, 다양한 LLM이 얼마나 자주 환각된 코드를 생성하는가?
  • RQ3코드 생성에서 환각 현상은 논리적, 이름 지정, 자원 또는 매핑 오류 중 어느 정도의 원인으로 발생하는가?
  • RQ4실행 기반 검증은 문법적으로는 유효하지만 기능적으로 잘못된 환각 현상을 효과적으로 탐지하고 분류할 수 있는가?
  • RQ5실제 프로그래밍 작업에서 다양한 LLM 아키텍처와 프롬프팅 전략에 따라 환각 현상 비율은 어떻게 달라지는가?

주요 결과

  • 평가된 16개의 LLM 전반에 걸쳐 코드 환각 현상이 널리 퍼져 있으며, 빈도와 유형 분포에 큰 차이가 있다.
  • 가장 흔한 환각 현상 유형은 논리적 오류(예: 잘못된 루프 또는 조건 처리)와 자원 관련 오류(예: 정수 오버플로우, 메모리 오류)이다.
  • MagicCoder와 StarCoder와 같은 일부 모델은 큰 정수 처리나 생성자 오용으로 인해 OverflowError 및 StopIteration 예외를 발생시켰다.
  • 실행 기반 검증은 문법적으로는 유효하지만 의미적으로 잘못된 환각 현상을 성공적으로 폭 드러내어, 벤치마크의 효과성을 입증했다.
  • 벤치마크는 심지어 최신 기술의 LLM이라도 실행 기반 평가 시 20퍼센트 이상의 경우에서 정확한 코드를 생성하지 못한다는 점을 드러냈다.
  • 이 연구는 환각 현상이 무작위가 아니라 식별 가능한 패턴을 따르며, 향후 모델 훈련에서 대응 전략을 타겟팅할 수 있음을 입증했다.
Figure 2: Collection of CodeHalu benchmark based on a verification-identification-construction process. For a sample from the APPS test set, we use $n$ LLMs to generate code, which is then executed and validated. We select the top 5 most frequent hallucinations from the code execution results to rep
Figure 2: Collection of CodeHalu benchmark based on a verification-identification-construction process. For a sample from the APPS test set, we use $n$ LLMs to generate code, which is then executed and validated. We select the top 5 most frequent hallucinations from the code execution results to rep

더 나은 연구,지금 바로 시작하세요

논문 읽기부터 검토까지, 연구 시간을 획기적으로 줄여보세요.

카드 등록 없음 · 무료 플랜 제공

이 리뷰는 AI가 만들고, 인간 에디터가 검토했습니다.