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

Code to Comment Translation: A Comparative Study on Model Effectiveness & Errors

Junayed Mahmud, Fahim Faisal, Raihan Islam Arnob, Antonios Anastasopoulos, Kevin Moran

TL;DR

This paper dives deep into the effectiveness and error patterns of three leading neural models for automatically generating natural language summaries (comments) from Java code. By combining quantitative metrics with a novel qualitative error analysis, the study reveals that while CodeBERT leads in performance, all models struggle with missing or incorrect information, highlighting crucial areas for future research in code summarization.

What Problem Does This Paper Address?

Manually documenting software is a time-consuming and often neglected task, especially in agile development environments. This leads to technical debt and hinders program comprehension and maintenance. Automated source code summarization, using machine translation techniques, aims to bridge this gap by generating natural language descriptions of code. However, existing evaluations primarily rely on automatic metrics like BLEU, which may not fully capture the nuances of code summarization due to the inherent semantic gap between programming languages and natural language. This paper addresses the need for a more thorough understanding of why these models succeed or fail, by investigating their error modes and comparing their effectiveness qualitatively.

Methods

The researchers conducted a comparative study of three prominent neural code summarization models: CodeBERT, NeuralCodeSum, and code2seq.

  • Quantitative Evaluation: They used standard machine translation metrics – smoothed BLEU-4, METEOR, and ROUGE-L – to compare the models' performance on a Java dataset.
  • Qualitative Evaluation: This was the core of their novel approach. They employed a manual, open-coding procedure to categorize the errors made by each model. This involved annotators independently labeling predictions against ground truth comments, followed by discussions to resolve disagreements and build a comprehensive error taxonomy.

Datasets

The primary dataset used in this study is Funcom, a large dataset specifically curated for code summarization, containing over 2.1 million Java methods paired with JavaDoc comments. For their experiments, they sampled the first 500,000 method-comment pairs from the filtered Funcom dataset. They also reference the CodeXGLUE dataset, which was used in prior work for evaluating CodeBERT.

Key Insights and Ideas

  • Beyond Metrics: The study strongly advocates for qualitative analysis alongside quantitative metrics. The semantic gap between code and natural language means that metrics alone can be misleading about a model's true understanding and error patterns.
  • CodeBERT's Strength: CodeBERT, being pre-trained on both bimodal (code-text) and unimodal data, shows a significant advantage, likely due to its broader understanding of language and code relationships.
  • Common Pitfalls: The most prevalent errors across models are "Missing Information" and "Incorrect Construction," indicating that current models struggle with accurately and completely conveying the code's functionality.
  • AST Limitations: For models like code2seq that rely on Abstract Syntax Tree (AST) parsing, challenges arise with methods that are too short or have unusual structures, leading to parsing failures and inability to generate predictions.
  • Semantic Similarity vs. Exact Match: The paper highlights that a summary might be semantically meaningful and useful for comprehension even if it doesn't achieve a high score on n-gram-based metrics like BLEU. This suggests a need for new evaluation metrics that capture semantic similarity better.

Key Results

  • Quantitative Performance: CodeBERT significantly outperformed NeuralCodeSum and code2seq across all three metrics:
  • CodeBERT: BLEU-4 (24.15), METEOR (30.34), ROUGE-L (35.65)

    • NeuralCodeSum: BLEU-4 (21.50), METEOR (27.78), ROUGE-L (33.71)
    • code2seq: BLEU-4 (18.61), METEOR (27.31), ROUGE-L (33.52) These differences were found to be statistically significant.
  • Qualitative Error Analysis: The study identified a taxonomy of errors, with the most frequent categories being:

  • Consistent with Ground Truth: (30.28%) - The largest category, showing that models can produce reasonable summaries.
  • Missing Information: (27.66%) - A major struggle for current models.
  • Incorrect Construction: (20.56%) - Issues with comment syntax and structure.
  • Incorrectly Recognized/Failed to Recognize Identifiers: (13.2%) - Difficulty in pinpointing key elements.
  • Over-Generalization: (9.15%) - Summaries that are too broad and lose specific meaning.

Limitations and Future Work

  • Limitations:
    • The code2seq model's reliance on AST parsing limits its ability to process all code snippets, particularly shorter ones.
  • The study acknowledges that current metrics like BLEU may not fully capture the semantic quality of generated summaries.
  • Future Work:
    • Develop more robust evaluation metrics specifically for code summarization that go beyond n-gram matching and better capture semantic similarity.
  • Focus future research on mitigating "Missing Information" and "Incorrect Construction" errors, as these are the most prevalent.
  • Explore hybrid approaches combining AST traversal with self-attention mechanisms to leverage the strengths of both.
  • Investigate techniques for adapting source coverage to improve summarization.

Summary updated

BibTeX
@inproceedings{mahmud2021code,
  author = {Junayed Mahmud and Fahim Faisal and Raihan Islam Arnob and Antonios Anastasopoulos and Kevin Moran},
  title = {{Code to Comment Translation: A Comparative Study on Model Effectiveness \& Errors}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2021},
}
Figure