[Paper Review] Code to Comment "Translation": Data, Metrics, Baselining & Evaluation
This paper critically evaluates the use of neural machine translation models for code-to-comment generation, revealing that code comments are far more repetitive than natural language text, leading to inflated BLEU scores. It demonstrates that simple information retrieval baselines often outperform state-of-the-art deep learning models, challenging the validity of current evaluation practices in the field.
The relationship of comments to code, and in particular, the task of generating useful comments given the code, has long been of interest. The earliest approaches have been based on strong syntactic theories of comment-structures, and relied on textual templates. More recently, researchers have applied deep learning methods to this task, and specifically, trainable generative translation models which are known to work very well for Natural Language translation (e.g., from German to English). We carefully examine the underlying assumption here: that the task of generating comments sufficiently resembles the task of translating between natural languages, and so similar models and evaluation metrics could be used. We analyze several recent code-comment datasets for this task: CodeNN, DeepCom, FunCom, and DocString. We compare them with WMT19, a standard dataset frequently used to train state of the art natural language translators. We found some interesting differences between the code-comment data and the WMT19 natural language data. Next, we describe and conduct some studies to calibrate BLEU (which is commonly used as a measure of comment quality). using "affinity pairs" of methods, from different projects, in the same project, in the same class, etc; Our study suggests that the current performance on some datasets might need to be improved substantially. We also argue that fairly naive information retrieval (IR) methods do well enough at this task to be considered a reasonable baseline. Finally, we make some suggestions on how our findings might be used in future research in this area.
Motivation & Objective
- To assess whether code-comment generation truly resembles natural language translation, given the use of similar deep learning models.
- To investigate the impact of high repetition in code comments on evaluation metrics like BLEU.
- To calibrate BLEU scores using affinity-based method groups to establish realistic performance expectations.
- To evaluate whether simple information retrieval methods can serve as strong baselines for code-comment generation.
- To advocate for standardized evaluation and baselining practices in future research on code-comment generation.
Proposed method
- Compared trigram frequency distributions between code-comment datasets (CodeNN, DeepCom, FunCom, DocString) and the WMT19 natural language translation dataset using Zipf plots.
- Defined 'affinity pairs' of methods (same project, same class, same method name) to calibrate BLEU scores and assess similarity-based performance.
- Measured BLEU scores across different data splits and preprocessing methods to assess variance and reliability.
- Implemented a simple information retrieval baseline using TF-IDF vectorization and cosine similarity to retrieve comments from similar methods.
- Evaluated the performance of retrieval-based baselines against reported SOTA results on standard datasets.
- Proposed that future work should adopt standardized evaluation protocols similar to those used in NLP benchmarks like GLUE and SQuAD.
Experimental results
Research questions
- RQ1How do the linguistic characteristics of code comments compare to those of natural language in standard translation datasets like WMT19?
- RQ2To what extent does the high repetition in code comments distort the reliability of BLEU scores as a metric for comment quality?
- RQ3Can simple information retrieval methods achieve performance comparable to or better than state-of-the-art deep learning models in code-comment generation?
- RQ4How do different levels of method affinity (e.g., same class, same project) affect expected BLEU scores, and what do they reveal about baseline performance?
- RQ5What improvements are needed in evaluation practices to ensure fair and reproducible comparisons in code-comment generation research?
Key findings
- Code comments exhibit significantly higher trigram repetition than natural language in WMT19, as shown by steeper Zipf plot slopes, indicating a more saturated, template-driven language.
- The WMT19 dataset shows stronger input-output dependency, where similar German inputs produce similar English outputs, but this pattern is weak or absent in code-comment datasets.
- BLEU scores are highly sensitive to data splits and preprocessing, with variations exceeding claimed model improvements in some cases.
- A simple information retrieval baseline using TF-IDF and cosine similarity achieves performance comparable to or better than reported SOTA neural models on multiple datasets.
- Retrieving comments from methods in the same class yields an average BLEU score comparable to current state-of-the-art models, suggesting this is a strong baseline.
- The study reveals significant inconsistencies in dataset preprocessing, splits, and evaluation functions across existing code-comment datasets, undermining comparability.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.