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

A Prompt Learning Framework for Source Code Summarization

Weisong Sun, Chunrong Fang, Yudu You, Yuchen Chen, Yi Liu, Chong Wang, Jian Zhang, Quanjun Zhang, Hanwei Qian, Wei Zhao, Yang Liu, Zhenyu Chen · DOI

Introduction

Generating natural language summaries for source code is a critical task in software engineering, facilitating code comprehension and maintenance. While Large Language Models (LLMs) have shown remarkable capabilities in this domain, their deployment often faces a trade-off between manual effort and computational cost. Traditional instruction prompting requires labor-intensive manual engineering of "discrete" prompts, which often fails to capture the optimal triggers for a model's latent knowledge. Conversely, full-parameter fine-tuning, while effective, is computationally prohibitive for models with billions of parameters.

To bridge this gap, we present PromptCS, a parameter-efficient prompt learning framework designed specifically for code summarization. PromptCS automates prompt engineering by training a small, dedicated "prompt agent" while keeping the underlying LLM frozen, achieving high performance with minimal hardware requirements.

The PromptCS Framework

PromptCS consists of two primary components: a frozen LLM and a trainable Prompt Agent. The framework operates by replacing human-written discrete prompts with "pseudo prompts"—sequences of learnable tokens.

Overview of the PromptCS training and deployment architecture.

As shown in the architecture above, these pseudo prompts are processed by a Prompt Encoder (comprising a BiLSTM network and an MLP) to generate continuous prompt embeddings. Unlike discrete text, these embeddings exist in the high-dimensional vector space native to the LLM, allowing for more precise steering of the model's output. During the training phase, only the Prompt Agent's parameters are updated via backpropagation, while the LLM remains entirely frozen. This non-invasive approach significantly reduces the memory footprint and training time.

Prompt Fusion Strategies

A key aspect of PromptCS is how the learned prompt embeddings are integrated with the code snippet embeddings. The framework explores three distinct fusion modes to determine the optimal placement of the prompt information relative to the input code.

Illustration of Front-end, Back-end, and Two-end prompt fusion modes.
  1. Front-end Mode: The prompt embedding is prepended to the code embedding.
  2. Back-end Mode: The prompt embedding is appended after the code embedding.
  3. Two-end Mode: The prompt embedding is split and placed at both the beginning and the end of the code sequence.

Evaluation and Results

The framework was evaluated using the CodeSearchNet (CSN) corpus across Java, Python, and JavaScript. Experiments utilized several autoregressive LLMs, including PolyCoder, CodeGen-Multi, and StarCoderBase, with parameter counts ranging from 160M to 7B.

Performance and Efficiency

PromptCS consistently outperformed zero-shot and few-shot baselines across standard metrics such as BLEU, METEOR, and ROUGE-L. Notably, on StarCoderBase (1B and 3B), PromptCS exceeded the performance of full-parameter fine-tuning.

The efficiency gains were substantial. For a 7B parameter model, PromptCS reduced training time by approximately 68% compared to full fine-tuning. Memory efficiency was equally impressive; for instance, PolyCoder-0.4B required only 2.5GB of VRAM with PromptCS, compared to 11.5GB for standard fine-tuning. This allows large models to be trained on consumer-grade hardware.

Data Efficiency and Human Evaluation

One of the most striking findings was the framework's data efficiency. PromptCS achieved competitive results with as few as 100 training samples, suggesting its utility for low-resource programming languages. Furthermore, a blind human evaluation by experienced developers rated PromptCS-generated summaries higher (3.64/5.0) than those produced by traditional fine-tuning or manual prompting.

Conclusion

PromptCS demonstrates that continuous prompt learning is a highly effective and efficient alternative to full-parameter fine-tuning for code summarization. By shifting the focus from manual discrete prompt engineering to automated continuous embedding optimization, PromptCS enables high-quality documentation generation with significantly lower computational overhead. Future work will explore extending this framework to other software engineering tasks such as code generation and bug fixing.

Summary updated

BibTeX
@misc{sun2023prompt,
  author = {Weisong Sun and Chunrong Fang and Yudu You and Yuchen Chen and Yi Liu and Chong Wang and Jian Zhang and Quanjun Zhang and Hanwei Qian and Wei Zhao and Yang Liu and Zhenyu Chen},
  title = {{A Prompt Learning Framework for Source Code Summarization}},
  year = {2023},
  eprint = {2312.16066},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2312.16066},
}
Figure