Abstract
Fine-tuning large Pre-trained Language Models (PLMs) for code-related tasks is computationally expensive and requires significant storage for task-specific parameters. CodePrompt introduces a novel, task-agnostic prefix tuning method that addresses the unique challenges of applying prompt tuning to programming languages. By utilizing input-dependent templates and a multi-word prefix initialization strategy, CodePrompt achieves performance comparable to full fine-tuning while updating only ~9% of the model's parameters. It demonstrates particular strength in low-data and cross-domain scenarios.
Introduction
As Pre-trained Language Models (PLMs) like CodeT5 grow in size, the cost of fine-tuning them for specific tasks—such as code summarization, generation, or translation—becomes prohibitive. While "prompt tuning" has emerged as a lightweight alternative in Natural Language Processing (NLP), it faces two primary hurdles in the code domain:
- The Pre-training Gap: Unlike NLP models trained on text with natural instructions, code models are often trained on raw code or code-comment pairs, lacking explicit task cues.
- Initialization Difficulty: Standard prefix tuning relies on task-specific word initialization, but such words are often absent or rare in code pre-training corpora.
CodePrompt bridges these gaps by providing structural context and a more robust initialization strategy.
Methodology
CodePrompt introduces three key innovations to optimize prefix tuning for code tasks:
- Input-Dependent Prompt Template: Instead of manual, task-specific prompts, CodePrompt uses a fixed, task-agnostic backbone:
Language: [L], Function Name: [F], Keywords: [K]. This mimics the bimodal (code + text) data seen during pre-training, helping the model utilize its internal knowledge without task-specific instructions. - Corpus-Specific Prefix Tuning: Learnable prefix vectors are initialized using the most frequent words from the specific programming language or text corpus, anchoring the model in the correct domain (e.g., Java vs. Python) from the start.
- Multi-Word Prefix Initialization: To enrich the initial prefix, the system identifies a "core" word and its $K$ nearest neighbors in the embedding space. The average of these embeddings is processed through a small neural network to create a more informative starting point for the learnable prompts.
Experimental Setup
The researchers evaluated CodePrompt using the CodeXGLUE benchmark across three primary Program and Language Generation (PLG) tasks:
- Code Summarization: Generating natural language descriptions for code in six languages (Ruby, JavaScript, Go, PHP, Java, Python).
- Code Generation: Converting natural language descriptions into Java code.
- Code Translation: Translating code between Java and C#.
Key Results and Insights
CodePrompt demonstrates that task-agnostic structural metadata (like function names and keywords) is more effective for "priming" code models than traditional NLP-style task prompts.
Efficiency and Performance
In full-data settings, CodePrompt achieved an overall BLEU score of 19.46 on code summarization, nearly matching the 19.55 of full fine-tuning, despite updating 11x fewer parameters (20M vs 222M for CodeT5-base).
Low-Resource and Cross-Domain Success
CodePrompt significantly outperforms standard prefix tuning when training data is scarce. In "16-shot" experiments, CodePrompt remained effective while standard methods often failed to learn useful patterns. Furthermore, when tested on unseen languages (cross-domain generalization), CodePrompt outperformed full fine-tuning, likely because freezing the core model prevents overfitting to the source language.
Conclusion
CodePrompt offers a highly efficient alternative to full fine-tuning for code generation tasks. By intelligently designing prefixes and templates that align with the model's pre-training data, it achieves state-of-the-art results with a fraction of the trainable parameters. Future research may explore applying these techniques to code understanding tasks, such as defect detection, and developing more sophisticated automated templates.
Summary updated