Introduction
Code summarization—the process of automatically generating natural language descriptions for source code—is a cornerstone of modern software documentation and maintenance. However, evaluating the quality of these summaries remains a significant challenge. Traditional automated metrics like BLEU, ROUGE, and METEOR were originally designed for machine translation and rely heavily on n-gram overlap. These metrics often fail to capture the semantic nuances of code, penalizing accurate summaries that use different terminology than a human-written reference. While human evaluation remains the gold standard, its high cost and lack of scalability make it impractical for large-scale model development. This paper explores whether Large Language Models (LLMs) can bridge this gap by serving as automated, human-aligned evaluators.
The CODERPE Framework
The researchers propose CODERPE (Role-Player for Code Summarization Evaluation), a framework that leverages the reasoning capabilities of LLMs to judge summary quality. The framework is built on four key pillars:
- Role-Playing Personas: Instead of generic prompts, CODERPE instructs the LLM to adopt specific professional roles, such as Code Reviewer, Original Code Author, Code Editor, or Systems Analyst. This contextual framing helps the model focus on relevant quality criteria.
- Multi-Dimensional Evaluation: Summaries are assessed across four critical dimensions: Coherence (logical structure), Consistency (factual alignment with the code), Fluency (natural language quality), and Relevance (capturing the code's core purpose).
- Advanced Prompting Techniques: The framework incorporates Chain-of-Thought (CoT) reasoning, requiring the model to explain its judgment before assigning a score, and In-Context Learning (ICL), which provides few-shot examples to calibrate the model's expectations.
- Reference-Free Capability: CODERPE can evaluate summaries by analyzing the source code directly, eliminating the need for a "gold standard" human reference—a major advantage in real-world scenarios where such references are often unavailable.
Experimental Setup
The framework was validated using the TL-CodeSum dataset, specifically a subset of 300 Java code-summary pairs. To establish a ground truth for correlation, 15 human experts (senior developers and graduate students) provided detailed annotations. The performance of CODERPE was then compared against traditional metrics and human scores using Spearman correlation.
Results and Discussion
CODERPE demonstrates a significant leap in evaluation accuracy. Using GPT-4 in a reference-free setting, the framework achieved an 81.59% Spearman correlation with human judgment, outperforming the previous state-of-the-art metric, BERTScore, by 17.27%.
As shown in the comparison above, traditional metrics often yield low scores (e.g., BLEU scores near zero) even when human experts rate a summary highly. In contrast, the LLM-based evaluator produces scores that closely mirror human intuition across all four dimensions.
Key findings include:
- Persona Impact: Specific roles improve accuracy; for instance, the "Code Editor" persona was most effective at identifying coherence issues.
- Semantic Understanding: Unlike n-gram metrics, LLMs can recognize that different phrasing can carry the same semantic weight, effectively closing the "semantic gap" in automated evaluation.
- Reference-Free Success: The model's ability to judge summaries based solely on source code proved nearly as effective as reference-based evaluation, suggesting that LLMs possess a deep enough understanding of code logic to act as independent judges.
Conclusion and Future Work
While CODERPE represents a major advancement, the study notes that LLMs are not immune to hallucinations—occasionally rewarding summaries for mentioning features not present in the code due to pre-training biases. Additionally, the cost of using high-end models like GPT-4 remains higher than traditional scripts. Future research will explore multi-agent "debate" settings, where different LLM personas collaborate to reach a consensus, potentially further reducing bias and improving evaluation reliability.
Summary updated