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

Evaluation Methodologies for Code Learning Tasks

Pengyu Nie, Jiyang Zhang, Junyi Jessy Li, Raymond J. Mooney, Milos Gligoric

Abstract

There has been a growing interest in developing machine learning (ML) models for code summarization tasks, e.g., comment generation and method naming. Despite substantial increase in the effectiveness of ML models, the evaluation methodologies, i.e., the way people split datasets into training, validation, and test sets, were not well studied. Specifically, no prior work on code summarization considered the timestamps of code and comments during evaluation. This may lead to evaluations that are inconsistent with the intended use cases. In this paper, we introduce the time-segmented evaluation methodology, which is novel to the code summarization research community, and compare it with the mixed-project and cross-project methodologies that have been commonly used. Each methodology can be mapped to some use cases, and the time-segmented methodology should be adopted in the evaluation of ML models for code summarization. To assess the impact of methodologies, we collect a dataset of (code, comment) pairs with timestamps to train and evaluate several recent ML models for code summarization. Our experiments show that different methodologies lead to conflicting evaluation results. We invite the community to expand the set of methodologies used in evaluations.

Introduction

Machine learning models for code summarization—such as generating natural language comments or predicting method names—are typically evaluated using standard practices that split datasets into training, validation, and test sets. However, these practices often ignore the reality of software evolution. In a real-world scenario, a developer uses a model trained on existing code to summarize newly written code.

Most research utilizes "time-unaware" splits, where a model might be tested on code written simultaneously with, or even before, the training data. This potential "data leakage" from the future or from within the same project leads to inflated performance metrics and a skewed understanding of how a model will perform in a continuous development environment. This paper introduces a novel time-segmented evaluation methodology to address these discrepancies.

Evaluation Methodologies

The authors compare three primary evaluation methodologies, each corresponding to different real-world use cases:

  1. Mixed-Project (MP): Samples from various projects are randomly shuffled and split. This is the most common but least realistic method, as the model "sees" code from the same projects during training.
  2. Cross-Project (CP): Entire projects are held out for testing. This evaluates how well a model generalizes to completely new, unseen codebases.
  3. Time-Segmented (T): This novel approach splits data based on timestamps. The model is trained on code available before time $\tau^{-2}$, validated on code from $\tau^{-2}$ to $\tau^{-1}$, and tested on code written after $\tau^{-1}$. This simulates a "continuous-mode" use case where a model predicts summaries for future code within known projects.
The time-segmented methodology splits data chronologically to simulate real-world usage in continuous development environments.

Experimental Design

Because existing datasets lacked the necessary timestamps, the authors collected a new dataset from 160 popular open-source Java projects on GitHub. They extracted (code, comment) pairs and (code, method name) pairs, using specific timestamps (Jan 1st of 2019, 2020, and 2021) to create the time-segmented splits. The final dataset contains over 77,000 samples.

To ensure a fair comparison, the authors developed a rigorous 6-step pipeline. This includes downsampling training sets to equal sizes and removing duplicates to prevent bias across the three methodologies.

The 6-step process for creating comparable training, validation, and test sets across methodologies.

Key Insights and Results

The study reveals that the choice of methodology fundamentally dictates which model appears to be the "state-of-the-art."

  • Ranking Shifts: In method naming tasks, Code2Seq outperformed Code2Vec in the cross-project setting. However, in the time-segmented setting, Code2Vec actually performed better (56.2 vs 42.9 F1 score).
  • Performance Inflation: Scores are consistently highest under the Mixed-Project (MP) methodology. For comment generation, the Transformer model achieved a 58.1 BLEU score under MP, but this dropped significantly to 14.1 in a Cross-Project setting and 56.1 in the Time-Segmented setting.
  • The Generalization Gap: Cross-Project results were consistently lower than Time-Segmented results, implying that generalizing to a brand-new project is significantly more difficult than generalizing to future code within familiar projects.

Conclusion

Researchers must define their intended use case—whether "batch-mode" for documenting old codebases or "continuous-mode" for daily IDE integration—and select an evaluation methodology accordingly. The results highlight that models struggle most with unseen projects, but the novel time-segmented approach provides a more realistic middle ground for evaluating tools intended for long-term deployment. The authors advocate for the broader adoption of temporal awareness in the evaluation of machine learning models for software engineering.

Summary updated

BibTeX
@inproceedings{nie2022evaluation,
  author = {Pengyu Nie and Jiyang Zhang and Junyi Jessy Li and Raymond J. Mooney and Milos Gligoric},
  title = {{Evaluation Methodologies for Code Learning Tasks}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2022},
  url = {https://openreview.net/forum?id=eLyxKrJPI-y},
}
Figure