Skip to main content
QUICK REVIEW

[Paper Review] What's Wrong with Your Code Generated by Large Language Models? An Extensive Study

Shihan Dou, Haoxiang Jia|arXiv (Cornell University)|Jul 8, 2024
Hate Speech and Cyberbullying DetectionComputer Science6 citations
TL;DR

The paper empirically analyzes code generated by seven LLMs across benchmarks, builds a bug taxonomy, creates a real-world benchmark, and proposes a self-critique method to fix bugs without fine-tuning.

ABSTRACT

The increasing development of LLMs in code generation has drawn significant attention among researchers. To enhance LLM-based code generation ability, current efforts are predominantly directed towards collecting high-quality datasets and leveraging diverse training technologies. However, there is a notable lack of comprehensive studies examining the limitations and boundaries of existing methods. To bridge this gap, we conducted an extensive empirical study evaluating the performance of three leading closed-source LLMs and six popular open-source LLMs on three commonly used benchmarks. Our investigation, which evaluated the length, cyclomatic complexity and API number of the generated code, revealed that these LLMs face challenges in generating successful code for more complex problems, and tend to produce code that is shorter yet more complicated as compared to canonical solutions. Additionally, we developed a taxonomy of bugs for incorrect codes that includes three categories and ten sub-categories, and analyzed the root cause for common bug types. To better understand the performance of LLMs in real-world projects, we also manually created a real-world benchmark RWPB. We analyzed bugs on RWPB to highlight distinct differences in bug distributions between actual scenarios and existing benchmarks. Finally, we propose a novel training-free iterative method that introduces self-critique, enabling LLMs to critique and correct their generated code based on bug types and compiler feedback. Our comprehensive and extensive study provides insights into the current limitations of LLM-based code generation and opportunities for enhancing the accuracy and quality of the generated code.

Motivation & Objective

  • Assess the accuracy and characteristics of code generated by leading closed- and open-source LLMs on Python tasks.
  • Characterize the types and distributions of bugs in generated code.
  • Compare performance on standard benchmarks versus a real-world, manually curated benchmark (RWPB).
  • Propose a training-free self-critique approach to mitigate bugs and improve passing rates.

Proposed method

  • Evaluate seven LLMs (three closed-source, four open-source) on 1,164 programming problems from HumanEval+, MBPP+, and APPS+.
  • Measure code length, cyclomatic complexity, and API usage of generated code and compare with canonical solutions.
  • Develop a two-stage bug annotation process (script-based initial taxonomy plus manual refinement) to classify bugs into 3 primary types and 12 sub-types.
  • Construct a real-world benchmark (RWPB) from 140 GitHub tasks to compare real-world bug distributions with benchmarks.
  • Introduce a self-critique iterative method where LLMs critique and correct their code based on bug taxonomy and compiler feedback, without additional training.
  • Report passing-rate improvements and analyze how task complexity affects LLM performance.

Experimental results

Research questions

  • RQ1RQ1: How effective are LLMs at code generation and how does task complexity influence performance?
  • RQ2RQ2: What are the root causes and distributions of bugs in LLM-generated code across benchmarks?
  • RQ3RQ3: How can a real-world benchmark be built to minimize data leakage and how do real-world bugs compare to benchmark bugs?
  • RQ4RQ4: Can a training-free self-critique approach mitigate bugs and improve correctness of generated code?

Key findings

  • Closed-source LLMs outperform open-source ones, especially on complex tasks (GPT-4 and Claude-3 are top performers; Phi-3 lags).
  • Generated code tends to be shorter but with higher cyclomatic complexity and similar API usage compared to canonical solutions.
  • Incorrect code often carries more comments than correct code, suggesting comments correlate with complexity rather than correctness.
  • Functional bugs are the predominant issue, with syntax and runtime bugs also present; complex problems lead to timeouts or suboptimal algorithms.
  • Real-world benchmark results show Claude-3 achieving 45.7% accuracy, while Phi-3 attains 22% on RWPB, with bug distributions differing from benchmarks.
  • The self-critique method increases passing rates by 29.2% after two iterations without additional training.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.