Source Code Summarization in the Era of Large Language Models

Weisong Sun, Yun Miao, Yuekang Li, Hongyu Zhang, Chunrong Fang, Yi Liu, Gelei Deng, Yang Liu, Zhenyu Chen

TL;DR

This paper presents a comprehensive, systematic study of Large Language Models (LLMs) applied to automatic source code summarization (generating code comments). The authors discover that traditional evaluation metrics like BLEU fail to capture the quality of LLM-generated summaries, whereas GPT-4 serves as an excellent automated evaluator that aligns closely with human judgment. Surprisingly, advanced prompting techniques often fail to beat simple zero-shot prompts, and smaller open-source models like CodeLlama-Instruct 7B can actually outperform GPT-4 at explaining code rationale and properties.

What Problem Does This Paper Address?

Code comments are vital for software maintenance and program comprehension, yet writing high-quality documentation is notoriously labor-intensive. While automated code summarization tools aim to solve this by generating natural language descriptions of code snippets, the field has transitioned rapidly into the era of LLMs without a clear understanding of how to optimize or evaluate them.

The core challenge addressed here is twofold:

  1. Evaluation Mismatch: Traditional evaluation metrics (like BLEU, METEOR, and ROUGE-L) measure exact text overlap against human-written reference summaries. However, human references in standard datasets are often brief or outdated, whereas LLMs generate rich, detailed summaries that get penalized by old metrics for not matching the reference text exactly.
  2. Workflow Optimization: There is a lack of empirical evidence regarding which prompting techniques, model parameters (temperature, top_p), and programming language paradigms yield the best results when using LLMs for code documentation.

Methods

The authors systematically evaluate four representative LLMs: CodeLlama-Instruct (7B), StarChat-β (16B), GPT-3.5, and GPT-4. Their study investigates five distinct dimensions of the code summarization workflow:

  1. Evaluation Frameworks: They benchmark text-similarity metrics, semantic-similarity metrics (like BERTScore), and LLM-as-an-evaluator methods against a ground-truth human evaluation conducted by 15 software engineering volunteers.
  2. Prompt Engineering: They test five prompting strategies: Zero-Shot, Few-Shot (using 4 examples), Chain-of-Thought (CoT), Critique (forcing the model to self-correct), and Expert prompting (instructing the model to act as an expert).
  3. Parameter Tuning: They analyze how shifting temperature and top_p impacts summary quality.
  4. Language Paradigms: They evaluate performance across 10 different programming languages spanning 5 paradigms (Procedural, Object-Oriented, Scripting, Functional, and Logic).
  5. Developer Intent Categories: They break down summaries into functional categories (What the code does, Why it does it, How it is implemented, Properties/Constraints, and How to use it) using a specialized comment classifier (COIN).
General workflow of LLM-based code summarization and evaluation

Datasets

The study utilizes two established benchmarks and introduces three new ones:

  • CodeSearchNet (CSN): Used for Java, Python, Go, Ruby, PHP, and JavaScript.
  • CCSD: Used for C function-summary pairs crawled from open-source systems like Linux and Redis.
  • New Paradigms (Erlang, Haskell, Prolog): To address the lack of diverse programming paradigms in existing datasets, the authors curated three new datasets from GitHub: Erlang (7,025 pairs) and Haskell (6,759 pairs) for Functional Programming, and Prolog (1,547 pairs) for Logic Programming.

Key Insights and Ideas

  • The Inadequacy of Traditional Metrics: Overlap metrics like BLEU correlate poorly—and sometimes negatively—with human judgment. LLMs frequently generate summaries that human evaluators consider superior to the original human-written reference text, making reference-based metrics highly misleading.
  • GPT-4 as a Reliable Judge: Prompting GPT-4 to act as a quality evaluator (on a scale of 1 to 5) yielded the strongest positive correlation with human expert evaluation, offering a scalable surrogate for expensive human studies.
Example of prompting an LLM to act as an evaluator
  • Simplicity Wins in Prompt Engineering: Intuitively advanced prompting methods like Chain-of-Thought or Critique do not consistently outperform simple zero-shot or few-shot prompts. For GPT-3.5, straightforward zero-shot prompting actually yielded the best overall results.
  • David Beats Goliath in Rationale: While GPT-4 dominates overall, the lightweight, open-source CodeLlama-Instruct (7B) unexpectedly outperformed GPT-4 when generating "Why" summaries (explaining design rationale) and "Property" summaries (asserting pre/post-conditions).

Key Results

  • Human vs. Reference Quality: Human evaluators rated GPT-4 and GPT-3.5 summaries significantly higher than the original human reference summaries in the datasets. For the C dataset, GPT-4 scored 4.25/5 compared to the human reference score of 3.05/5.
  • Prompting Nuances: When using GPT-3.5 on Java, zero-shot prompting achieved a score of 3.90, outperforming few-shot (3.56) and chain-of-thought (3.36).
  • The Logic Programming Gap: All LLMs performed worst on Logic Programming (Prolog), with scores dropping significantly compared to object-oriented or procedural languages (e.g., StarChat-β scored 2.34 on Prolog vs. 2.97 on Go).
  • Category Excellence: CodeLlama-Instruct 7B scored 4.29 on "Why" summaries and 4.19 on "Property" summaries, edging out GPT-4's scores of 4.28 and 4.06, respectively.

Limitations and Future Work

The authors acknowledge a few limitations in their study:

  • LLM Non-Determinism: LLMs inherently generate varied responses. While the authors mitigated this by setting a low temperature (0.1) for generation and 0 for evaluation, slight randomness remains.
  • Classifier Constraints: The evaluation of summary categories (RQ5) was restricted to the Java dataset because reliable comment intent classifiers (like COIN) are currently unavailable for the other programming languages.

Future Work: The authors suggest developing multi-language comment intent classifiers and exploring cost-effective knowledge distillation methods to train smaller, specialized open-source models based on these workflow insights.

Summary updated

BibTeX
@inproceedings{sun2025source,
  author = {Weisong Sun and Yun Miao and Yuekang Li and Hongyu Zhang and Chunrong Fang and Yi Liu and Gelei Deng and Yang Liu and Zhenyu Chen},
  title = {{Source Code Summarization in the Era of Large Language Models}},
  booktitle = {ICSE},
  year = {2025},
  doi = {10.1109/icse55347.2025.00034},
}
Figure