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

A Prompt Learning Framework for Source Code Summarization

Tingting Xu, Yun Miao, Chunrong Fang, Hanwei Qian, Xia Feng, Zhenpeng Chen, Chong Wang, Jian Zhang, Weisong Sun, Zhenyu Chen, Yang Liu

TL;DR

PromptCS is a novel, parameter-efficient framework for source code summarization that replaces manual prompt engineering with a trained "prompt agent." By generating continuous prompt embeddings rather than discrete text instructions, it achieves performance comparable to—and sometimes better than—full-parameter fine-tuning at a fraction of the computational cost and time.

What Problem Does This Paper Address?

Writing high-quality code comments is essential for software maintenance, yet it remains a persistent challenge in the industry. While Large Language Models (LLMs) like StarCoder and CodeGen show great promise in automating this task, adapting them effectively is difficult.

Current adaptation methods fall into two extremes:

  1. Instruction Prompting: Requires humans to "rack their brains" to design perfect prompts, which is often a trial-and-error process requiring deep domain expertise.
  2. Full Fine-tuning: Updates all model parameters, which is prohibitively expensive in terms of GPU memory and time as models scale into the billions of parameters.

The authors identify a gap for a "non-invasive" method that is both automated and resource-efficient, specifically tailored for the nuances of source code.

Methods

The authors introduce PromptCS, which consists of two collaborating components: a Prompt Agent and a frozen LLM.

  • The Prompt Agent: Instead of using human-readable text, this agent uses a deep learning-based encoder (a BiLSTM followed by a two-layer MLP) to transform "pseudo prompts"—a set of learnable placeholder tokens—into continuous prompt embeddings ($e^P$).
  • Non-Invasive Training: During training, the parameters of the base LLM are completely frozen. Only the small prompt agent is updated via backpropagation. This drastically reduces the hardware requirements.
  • Fusion Embedding: The generated prompt embedding is concatenated with the code snippet embedding ($e^C$) to create a fusion embedding ($e^F$), which is then fed into the LLM's module blocks. The authors experimented with three concatenation modes: front-end, back-end, and two-end.
Overview of PromptCS training and deployment

Datasets

The framework was evaluated using the CodeSearchNet (CSN) corpus, specifically the cleaned version provided by the CodeXGLUE benchmark to ensure high-quality data.

  • Primary Language: Java was used for the bulk of the configuration and ablation studies.
  • Generalization Languages: Python and JavaScript were used to test the framework's versatility across different programming paradigms.

Key Insights and Ideas

  • Continuous > Discrete: The core "aha moment" is that LLMs understand continuous vector representations better than discrete human language. By training an agent to "speak" directly in the LLM's embedding space, the framework bypasses the limitations of human-written prompts.
  • Efficiency through Freezing: Because the LLM weights are frozen, they can be loaded in half-precision (fp16), speeding up inference and reducing memory usage significantly. For example, fine-tuning PolyCoder-0.4b requires 11.5GB of VRAM, while PromptCS needs only 2.5GB.
  • Small-Data Adaptability: One of the most surprising findings was PromptCS's performance on small datasets. While full fine-tuning requires large amounts of data to be effective, PromptCS trained on just 100 samples performed comparably to a version trained on over 164,000 samples.
  • Task-Specific Agents: The non-invasive nature allows a single base LLM to serve multiple downstream tasks simultaneously. You simply swap out the lightweight prompt agent for each specific task (e.g., summarization vs. bug fixing) without altering the core model.
Different modes for concatenating prompt and code embeddings

Key Results

  • Performance: PromptCS significantly outperformed zero-shot and few-shot instruction prompting across all metrics (BLEU, METEOR, ROUGE-L, and SentenceBERT).
  • Beating Fine-Tuning: On models like StarCoderBase-1B and -3B, PromptCS actually outperformed full-parameter fine-tuning.
  • Training Speed: For a 7B parameter model, PromptCS reduced training time from 211 hours (for one epoch of full fine-tuning) to just 67 hours.
  • Human Evaluation: In a blind study with five experienced developers, PromptCS generated the highest average scores and the largest number of "good" summaries compared to all baseline methods.

Limitations and Future Work

While PromptCS is highly effective, the authors noted through case studies that it still has room for improvement in capturing extremely complex logic or specific edge cases in code.

Future research directions include:

  • Optimizing the prompt encoder architecture further to capture deeper semantic nuances.
  • Exploring the application of the PromptCS framework to other software engineering tasks, such as code translation or automated bug fixing.
  • Investigating how different base LLM architectures (beyond autoregressive models) interact with continuous prompt learning.

Summary updated

BibTeX
@misc{xu2023prompt,
  author = {Tingting Xu and Yun Miao and Chunrong Fang and Hanwei Qian and Xia Feng and Zhenpeng Chen and Chong Wang and Jian Zhang and Weisong Sun and Zhenyu Chen and Yang Liu},
  title = {{A Prompt Learning Framework for Source Code Summarization}},
  year = {2023},
  eprint = {2312.16066},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2312.16066},
}
Figure