NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Automatic Code Summarization via ChatGPT: How Far Are We?

Weisong Sun, Chunrong Fang, Yudu You, Yun Miao, Yi Liu, Yuekang Li, Gelei Deng, Shenghan Huang, Yuchen Chen, Quanjun Zhang, Hanwei Qian, Yang Liu, Zhenyu ChenarXiv 2023 · DOI

Abstract

Automatic code summarization is vital for software maintenance, yet the effectiveness of general-purpose Large Language Models (LLMs) like ChatGPT in this domain remains under-explored compared to specialized models. This paper benchmarks ChatGPT’s zero-shot performance against state-of-the-art (SOTA) models fine-tuned for code summarization. Our results indicate that while ChatGPT lags in traditional word-matching metrics like BLEU and ROUGE-L, it excels in semantic richness and logical accuracy, often surpassing human-written "ground truth" benchmarks. These findings highlight the limitations of current evaluation metrics for LLMs in software engineering.

Introduction

Code summarization—generating natural language descriptions for code snippets—is essential for reducing the cognitive load on developers. Traditionally, this task has been dominated by specialized Deep Learning models such as CodeBERT and CodeT5, which are fine-tuned on massive datasets of code-comment pairs. With the advent of ChatGPT, a general-purpose conversational AI, a critical question arises: can a zero-shot LLM compete with these specialized "experts"? This study evaluates ChatGPT's zero-shot capabilities against the reigning SOTA models.

Methodology

The research follows a structured approach involving prompt engineering, zero-shot evaluation, and comparative analysis against SOTA baselines.

Overview of the study workflow and experimental design.

Prompt Engineering

To optimize ChatGPT's performance, the researchers tested five distinct heuristic prompts. They observed that ChatGPT's default responses were often too verbose for standard benchmarks. To align with the typically concise human-written comments in datasets, the researchers discovered that the most effective prompt was: "Please generate a short comment in one sentence for the following function: <code>".

Example of a prompt and ChatGPT's response during the initial study phase.

Experimental Setup

The study utilized the CSN-Python dataset, a cleaned version of the CodeSearchNet corpus. The evaluation focused on a test set of 14,918 samples to ensure statistical significance. ChatGPT was tested in a "zero-shot" configuration, meaning it received no task-specific training, unlike the baseline models (NCS, CodeBERT, and CodeT5) which were fine-tuned on hundreds of thousands of examples.

Results and Discussion

The quantitative evaluation revealed a performance gap depending on the metric used:

  • Overlap Metrics: Specialized models like CodeT5 significantly outperformed ChatGPT on BLEU (20.0 vs. 10.28) and ROUGE-L (37.7 vs. 20.81). These metrics reward exact word matches, which favors models fine-tuned to mimic the specific vocabulary of the training data.
  • Semantic Metrics: On the METEOR metric, which accounts for synonyms and stemming, ChatGPT (14.40) performed nearly as well as CodeT5 (14.70) and outperformed CodeBERT and NCS. This suggests that ChatGPT captures the underlying meaning more effectively than word-overlap scores imply.

The "Metric Trap"

Qualitative analysis showed that ChatGPT often understands the logic and intent of code better than fine-tuned models. While specialized models might "guess" a summary based on variable names, ChatGPT can describe the "how" and "why" of a function. Crucially, ChatGPT's summaries were sometimes found to be more accurate or descriptive than the human-provided "ground truth" in the dataset. Because these superior summaries did not match the exact wording of the benchmark, they received lower scores, suggesting that BLEU and ROUGE-L are increasingly inadequate for evaluating modern LLMs.

Conclusion

ChatGPT demonstrates remarkable zero-shot capabilities in code summarization, providing human-friendly and logically sound descriptions. While it currently trails specialized models on traditional metrics, its qualitative performance suggests it is a powerful tool for developers. Future work should focus on developing better evaluation frameworks and using LLMs to clean and improve existing code-comment datasets to establish higher standards for the field.

Summary updated

BibTeX
@misc{sun2023automatic,
  author = {Weisong Sun and Chunrong Fang and Yudu You and Yun Miao and Yi Liu and Yuekang Li and Gelei Deng and Shenghan Huang and Yuchen Chen and Quanjun Zhang and Hanwei Qian and Yang Liu and Zhenyu Chen},
  title = {{Automatic Code Summarization via ChatGPT: How Far Are We?}},
  year = {2023},
  eprint = {2305.12865},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2305.12865},
}
Figure