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.
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.
- Front-end Mode: The prompt embedding is prepended to the code embedding.
- Back-end Mode: The prompt embedding is appended after the code embedding.
- 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