Abstract
Code pre-trained models (CodePTMs) have recently demonstrated a solid capacity to process various code intelligence tasks, e.g., code clone detection, code translation, and code summarization. The current mainstream method that deploys these models to downstream tasks is to fine-tune them on individual tasks, which is generally costly and needs sufficient data for large models. To tackle the issue, in this paper, we present TransCoder, a unified Transferable fine-tuning strategy for Code representation learning. Inspired by human inherent skills of knowledge generalization, TransCoder drives the model to learn better code-related knowledge like human programmers. Specifically, we employ a tunable prefix encoder to first capture cross-task and cross-language transferable knowledge, subsequently applying the acquired knowledge for optimized downstream adaptation. Besides, our approach confers benefits for tasks with minor training sample sizes and languages with smaller corpora, underscoring versatility and efficacy. Extensive experiments conducted on representative datasets clearly demonstrate that our method can lead to superior performance on various code-related tasks and encourage mutual reinforcement, especially in low-resource scenarios.
Introduction: The Challenge of Code Intelligence
The rapid advancement of Code Pre-trained Models (CodePTMs) like CodeT5 and CodeGen has revolutionized code intelligence tasks. However, the prevailing paradigm of fine-tuning these models on individual tasks in isolation presents significant challenges. First, large-scale models are "data-hungry," requiring extensive labeled datasets that are often unavailable for niche tasks or low-resource programming languages. Second, this approach creates "knowledge silos," where insights gained from one task (e.g., code summarization) are not leveraged for another (e.g., defect detection), despite their inherent semantic relationships.
The authors identify a critical data imbalance in the software ecosystem. While languages like Java and Python have massive corpora, others like Ruby or PHP remain relatively low-resource. TransCoder aims to break these silos, allowing models to leverage knowledge from data-rich tasks and languages to boost performance on data-poor ones, mimicking how human programmers transfer skills across different environments.
Methodology: The TransCoder Framework
TransCoder introduces a unified transferable fine-tuning strategy inspired by human programmers' ability to generalize knowledge across languages and tasks. The core innovation is the Universal Knowledge Prefix. Instead of updating all weights of a massive model, TransCoder prepends a set of tunable parameters (the prefix) to the hidden states of the transformer layers. This architecture is "backbone-agnostic," meaning it can be applied to various model types like CodeT5, PLBART, or CodeGen.
The training process is divided into two distinct stages:
- Knowledge Acquisition (Source Tasks): The model undergoes continual learning across a variety of source tasks and languages. During this phase, the prefix acts as a "universal learner," absorbing general patterns of code logic and structure. An adaptive sampling strategy is used to prevent the model from favoring high-resource languages.
- Knowledge Utilization (Target Tasks): The learned "universal" prefix is injected into a fresh CodePTM to tackle a new, unseen target task.
Experimental Evaluation
The researchers evaluated TransCoder using the CodeXGLUE benchmark, a gold standard in the field. Specific datasets included CodeSearchNet for summarization, CodeTrans for translation, BigCloneBench for clone detection, and Devign for defect detection.
Key Results and Insights
TransCoder consistently outperformed standard fine-tuning across multiple backbones:
- Superior Performance: On the CodeT5+ backbone, TransCoder achieved a BLEU score of 21.87 for summarization (compared to 20.15 for standard fine-tuning) and a 96.60 F1 score for clone detection.
- Efficiency in Scarcity: TransCoder shines in low-resource scenarios. In experiments using only 10% of the available data, TransCoder matched or exceeded the performance of standard models fine-tuned on 100% of the data.
- Mutual Reinforcement: One of the most striking findings is that learning to summarize code (a generation task) actually helps the model detect bugs (an understanding task). The "universal knowledge" captured in the prefix acts as a bridge between these seemingly different capabilities.
- Faster Convergence: Models using the universal prefix reached optimal performance significantly faster than those without it, reducing computational overhead.
Conclusion
TransCoder offers a versatile and efficient strategy for code representation learning by treating programming languages as variations on a theme rather than entirely separate entities. By breaking down knowledge silos and enabling mutual reinforcement between tasks, it significantly reduces the data and computational costs associated with deploying large-scale CodePTMs. Future work will explore its efficacy on a broader range of architectures and even more specialized domain-specific languages.
Summary updated