Better Language Models of Code through Self-Improvement

Hung Quoc To, Nghi D. Q. Bui, Jin L. C. Guo, Tien N. Nguyen

Abstract

Pre-trained language models for code (PLMCs) have gained attention in recent research, utilizing large-scale datasets and multi-modal objectives. However, fine-tuning these models is often constrained by the limited size of supervised datasets. This paper proposes a self-improvement framework that leverages knowledge distillation to augment training data. By utilizing knowledge gained during pre-training and initial fine-tuning, the framework generates augmented data for a subsequent refinement step. Evaluated on state-of-the-art models like CodeT5, CodeBERT, and UniXCoder, the results demonstrate significant performance gains in sequence-generation tasks, including code summarization and code generation within the CodeXGLUE benchmark.

Introduction

Pre-trained Language Models of Code (PLMCs) have revolutionized software engineering tasks, yet they face a performance ceiling during fine-tuning. Standard supervised learning on fixed datasets is limited by data scarcity and exposure bias—the discrepancy between a model being trained on ground-truth tokens versus generating sequences token-by-token during inference. This research addresses whether the "latent knowledge" acquired during a model's massive pre-training phase can be harvested to improve task-specific performance without requiring additional human-labeled data.

Methodology

The authors propose a three-stage "self-improvement" pipeline designed to bridge the gap between training and inference:

  1. Initial Fine-tuning: A standard PLMC is fine-tuned on a task-specific dataset (e.g., the CodeSearchNet dataset for summarization).
  2. Data Augmentation via Self-Distillation: The fine-tuned model performs a beam search on the original training set to generate $k$ candidate outputs. The framework selects the candidate most similar to the original ground truth (using metrics like BLEU or CodeBLEU) to create an augmented training set.
  3. Self-Improved Fine-tuning: The model undergoes a second round of fine-tuning using this augmented dataset, where the targets are the model's own best-achievable predictions.
The three-stage self-improvement framework: from pre-trained model to fine-tuned model, and finally to the self-improved model via data augmentation.

This approach is a form of sequence-level knowledge distillation where the model acts as its own teacher. By training on its own "reasonable outputs," the model learns to handle the stylistic quirks and errors it naturally produces, effectively mitigating exposure bias.

Experimental Results

The framework was tested on the CodeXGLUE benchmark, specifically focusing on code summarization (across six programming languages) and code generation (using the CONCODE dataset). The results show consistent improvements across all tested architectures, including CodeBERT, CodeT5, and UniXCoder.

Performance comparison of baseline and self-improved models on code summarization tasks across six programming languages.

Key findings include:

  • Performance Gains: Self-improved models saw an average increase of 0.76 BLEU points in code summarization and 0.81 BLEU points in code generation.
  • Metric Sensitivity: For code generation, using CodeBLEU as the similarity function for augmentation outperformed standard BLEU, suggesting that domain-specific structural feedback is crucial for self-improvement.
  • Robustness: The improvements were stable across various beam sizes, indicating the framework's reliability.

Discussion and Limitations

While the self-improvement framework is highly effective, it is computationally intensive due to the $O(nk)$ complexity of generating predictions for the entire training set. Furthermore, while the method excels for encoder-decoder and unified models, its impact on massive decoder-only models remains a subject for future research. Subsequent studies may explore applying this loop to larger models and broader tasks such as automated bug fixing or code translation.

Summary updated

BibTeX
@inproceedings{to2023better,
  author = {Hung Quoc To and Nghi D. Q. Bui and Jin L. C. Guo and Tien N. Nguyen},
  title = {{Better Language Models of Code through Self-Improvement}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2023},
  url = {https://openreview.net/forum?id=1xeAz7QAtQ},
}
Figure