Low-Resources Project-Specific Code Summarization

Rui Xie, Tianxiang Hu, Wei Ye, Shikun Zhang

TL;DR

This paper introduces "project-specific code summarization" (PCS) – generating accurate code summaries tailored to a particular project, even with limited existing documentation. They propose MPCos, a meta-transfer learning approach that leverages multiple projects to learn project-specific nuances efficiently, outperforming general code summarization models in low-resource settings.

What Problem Does This Paper Address?

Developers often need to understand and document code within their specific projects. While general code summarization (GCS) models can generate summaries based on large, diverse datasets, they struggle to capture the unique style and domain knowledge of individual projects. This is particularly problematic in "low-resource" scenarios where a project has insufficient existing code-summary pairs for effective training. Existing GCS models might produce generic or even inaccurate summaries, failing to align with a project's established documentation style. This paper addresses this gap by proposing a method for project-specific code summarization (PCS) that excels even with very limited project data.

Methods

The core of the proposed method, MPCos (Meta Prefix-tuning for COde Summarization), is built upon a Transformer architecture. It incorporates two key innovations:

  • Meta-Transfer Learning: Instead of treating all projects equally, MPCos views each project as a distinct "domain." It uses Model-Agnostic Meta-Learning (MAML) to learn how to learn transfer learning across multiple projects. This process condenses shared cross-project knowledge into initial weights for the model, enabling better adaptation to new, specific projects.
  • Prefix-Tuning: To address the challenge of limited data and prevent overfitting, MPCos freezes the pre-trained Transformer model's parameters. It then optimizes a small set of continuous "project-specific prefix vectors" for each project. These prefixes are prepended to each layer of the Transformer, allowing for efficient adaptation without modifying the entire model. This is inspired by prompt learning techniques in NLP.

The overall framework involves meta-training on a collection of projects to learn good initial prefix vectors, followed by fine-tuning the target project using these learned prefixes.

Datasets

The authors created a new dataset for project-specific code summarization by extracting methods from nine active open-source projects from Apache, Google, and Spring. They extracted the first sentence of the existing documentation as the ground truth summary. To simulate low-resource scenarios, they used a 5-fold cross-validation approach, randomly selecting only 10 or 100 samples from the candidate training set for fine-tuning. The pre-training dataset used for the general code summarization knowledge was the one proposed by LeClair et al. [14].

Key Insights and Ideas

  • Project-Specific Knowledge is Crucial: The study strongly suggests that generic code summarization models perform poorly on individual projects because they fail to capture project-specific nuances in style and domain.
  • Meta-Learning for Efficient Adaptation: Leveraging multiple projects through meta-learning is effective for learning how to adapt to new projects, especially when those new projects have limited data.
  • Prefix-Tuning for Parameter Efficiency: Freezing the main model and optimizing only project-specific prefixes is a highly effective and efficient way to adapt models to new domains with minimal data, preventing overfitting.
  • Two-Stage Learning: The research indicates that MPCos learns in stages: first, it captures shallow textual style information with a few examples, and then, with more data, it delves into deeper semantic understanding.

Key Results

  • Significant Improvement over GCS: MPCos achieved substantial improvements over state-of-the-art General Code Summarization (GCS) models in the project-specific scenario, with BLEU scores showing nearly 100% relative enhancement.
  • Outperforms Transfer-Learning Baselines: MPCos outperformed other transfer-learning-based models like Adaptor, MAM-Adaptor, and MTL-ABS, demonstrating its effectiveness in the low-resource PCS task. For instance, MPCos(100) showed a 42.47% improvement in BLEU over MTL-ABS on average.
  • Effectiveness of Components: Both meta-learning and prefix-tuning were shown to be crucial. Removing meta-learning led to decreased performance, and while prefix-tuning was slightly less impactful with only 10 samples, it was vital for achieving optimal results with 100 samples.
  • Human Evaluation Confirms Superiority: Human evaluations confirmed MPCos's superiority in naturalness, informativeness, and relevance compared to baselines.

Limitations and Future Work

  • Project Selection: The authors acknowledge that the selection of projects for meta-learning can influence performance, and this process is non-trivial. Future work could explore more principled project selection strategies.
  • Ground Truth Noise: The use of the first sentence of existing documentation as ground truth can introduce noise.
  • Zero-Shot PCS: The paper identifies the "zero-shot PCS scenario" (no historical code summaries) as an extreme challenge. Future research could investigate methods for this scenario, including strategies for manually annotating a minimal set of summaries.
  • Explicit Knowledge Extraction: The current method extracts implicit project knowledge via prefix-tuning. Future work could explore incorporating explicit project-specific knowledge.

Summary updated

BibTeX
@inproceedings{xie2022low,
  author = {Rui Xie and Tianxiang Hu and Wei Ye and Shikun Zhang},
  title = {{Low-Resources Project-Specific Code Summarization}},
  booktitle = {ASE},
  year = {2022},
  doi = {10.1145/3551349.3556909},
}

Loading related content...

Figure