TL;DR
This paper presents a rigorous empirical evaluation of ChatGPT’s capabilities as an automated programming assistant across three core tasks: code generation, program repair, and code summarization. While ChatGPT excels at solving common programming problems and demonstrates a surprising ability to infer developer intent from buggy code, its performance drops sharply on new, unseen problems. Furthermore, counterintuitive findings reveal that overly detailed prompts can actually degrade its performance due to attention span limitations.
What Problem Does This Paper Address?
Large Language Models (LLMs) have taken the software engineering world by storm, showing massive promise in automating tedious coding tasks. However, most existing evaluations of models like ChatGPT rely on older, publicly available benchmarks. This introduces a significant risk of data leakage—meaning the model may have already seen the problems and their solutions during its pre-training phase.
To uncover ChatGPT's true capabilities, the authors design an empirical study that explicitly accounts for data leakage. They investigate how well ChatGPT (specifically the gpt-3.5-turbo model) generalizes to entirely new programming problems, how it handles diverse student-submitted bugs, and whether it can accurately understand the underlying intent of broken code.
Methods
The authors evaluate ChatGPT by querying the API five independent times per prompt to account for the inherent randomness of LLM outputs. They evaluate performance using two primary metrics:
- TOP-5: Success if at least one of the five generated outputs passes all test cases (representing a scenario where a developer reviews a few options).
- AVG-5: The average success rate across all five attempts, indicating the model's consistency.
ChatGPT's performance is benchmarked against OpenAI’s Codex and CodeGen for code generation, and against Refactory (a state-of-the-art, semantics-based automated program repair tool) for fixing buggy code.
Datasets
The study utilizes two distinct benchmarking targets:
- LeetCode Datasets: To isolate the impact of data leakage, the authors curate two sets of 120 problems each (spanning Array, String, Hash Table, and Sorting types across Easy, Medium, and Hard difficulties):
- LeetCode 2016-2020: Problems released before ChatGPT’s September 2021 knowledge cutoff.
- LeetCode 2022: Problems released after the cutoff, ensuring they are entirely unseen.
- Refactory Benchmark: A dataset consisting of real-world Python assignments submitted by undergraduate students at the National University of Singapore. It contains 2,442 correct and 1,783 buggy implementations across five common algorithmic problems.
Key Insights and Ideas
- The Generalization "Cold Start" Problem: ChatGPT struggles to generalize to genuinely new problems. While it dominates older LeetCode problems, its performance plummets on post-2021 problems of medium and high difficulty, proving that data leakage heavily inflates typical benchmark results.
- The Prompt Paradox (Limited Attention Span): Intuitively, one might think that providing more detailed problem descriptions would help the model. However, the authors found the opposite: verbose prompts often distract ChatGPT, causing it to focus on non-bug-related details and fail at fixing or generating code. Concision is key.
- Intent Inference and the Test Oracle Problem: Remarkably, even when code completely lacks critical logic (such as missing a
returnstatement), ChatGPT can accurately deduce what the code intended to do. Its explanations for buggy code are semantically identical to its explanations for correct code. This ability to infer intent means LLMs could play a massive role in solving the "test oracle problem"—helping developers automatically determine what the expected output of a program should be.
A high-level summary of these findings and their actionable insights can be seen in the project's overview tables:
Key Results
Code Generation
On pre-2021 LeetCode problems, ChatGPT achieved a stellar 95% TOP-5 correctness on Easy problems and 65% on Hard problems. However, on the unseen 2022 dataset, its TOP-5 correctness dropped to 58% for Easy and a mere 5% for Hard problems. Despite this drop, it consistently outperformed Codex and CodeGen across the board.
Program Repair
On the Refactory student assignment benchmark, ChatGPT achieved an 84% repair success rate (TOP-5), coming remarkably close to the specialized, state-of-the-art Refactory tool (90.8%). However, its AVG-5 consistency sat at 60%, meaning it functions best as a "helper bot" providing multiple options rather than an autonomous debugger.
Code Summarization
Using BERT to calculate semantic similarity, the authors proved that the distribution of similarities between ChatGPT's explanations of incorrect code vs. the ground-truth problem descriptions was statistically indistinguishable from its explanations of correct code.
Limitations and Future Work
The study primarily focused on the GPT-3.5 model due to strict rate limits and reported API instabilities with GPT-4 during the evaluation period. Additionally, the benchmarks were restricted entirely to Python source code.
The authors suggest that future work should explore GPT-4 as it stabilizes and, crucially, leverage ChatGPT’s unique intent-reasoning capabilities to automatically generate test suites and address the open challenges of automated test oracle generation.
Summary updated