[Paper Review] CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generation
CodeT5 proposes a unified encoder-decoder Transformer model pre-trained on code and natural language pairs, introducing identifier-aware masking and bimodal dual generation to improve code understanding and generation. It achieves state-of-the-art performance across 14 CodeXGLUE tasks, significantly outperforming prior methods in both code defect detection and code summarization tasks.
Pre-trained models for Natural Languages (NL) like BERT and GPT have been recently shown to transfer well to Programming Languages (PL) and largely benefit a broad set of code-related tasks. Despite their success, most current methods either rely on an encoder-only (or decoder-only) pre-training that is suboptimal for generation (resp. understanding) tasks or process the code snippet in the same way as NL, neglecting the special characteristics of PL such as token types. We present CodeT5, a unified pre-trained encoder-decoder Transformer model that better leverages the code semantics conveyed from the developer-assigned identifiers. Our model employs a unified framework to seamlessly support both code understanding and generation tasks and allows for multi-task learning. Besides, we propose a novel identifier-aware pre-training task that enables the model to distinguish which code tokens are identifiers and to recover them when they are masked. Furthermore, we propose to exploit the user-written code comments with a bimodal dual generation task for better NL-PL alignment. Comprehensive experiments show that CodeT5 significantly outperforms prior methods on understanding tasks such as code defect detection and clone detection, and generation tasks across various directions including PL-NL, NL-PL, and PL-PL. Further analysis reveals that our model can better capture semantic information from code. Our code and pre-trained models are released at https: //github.com/salesforce/CodeT5 .
Motivation & Objective
- To address the limitations of encoder-only or decoder-only models in code-related tasks by proposing a unified encoder-decoder framework.
- To improve code representation by explicitly modeling developer-assigned identifiers as a key semantic signal.
- To enhance cross-modal alignment between natural language comments and code through a dual-generation pre-training objective.
- To support both code understanding and code generation tasks within a single unified model architecture.
- To enable multi-task fine-tuning using task-specific prompts for improved generalization across diverse code intelligence tasks.
Proposed method
- Leverages the T5 architecture as a unified encoder-decoder framework for joint code understanding and generation.
- Introduces a novel identifier-aware pre-training objective that masks and reconstructs identifiers separately from other token types.
- Employs a bimodal dual generation task to jointly pre-train on both NL→PL and PL→NL generation using code-comment pairs.
- Pre-trains on CodeSearchNet and additional C/C# code from GitHub, using both unimodal and bimodal data.
- Fine-tunes on multiple CodeXGLUE tasks using task control codes as input prompts to enable multi-task learning.
- Uses a unified sequence-to-sequence denoising objective during pre-training to improve generalization across downstream tasks.
Experimental results
Research questions
- RQ1Can a unified encoder-decoder model outperform specialized encoder-only or decoder-only models in both code understanding and generation tasks?
- RQ2Does identifying and masking only identifiers during pre-training improve code representation learning compared to standard masking?
- RQ3Can joint pre-training on NL→PL and PL→NL generation improve cross-modal alignment and performance on code summarization and translation tasks?
- RQ4How does multi-task fine-tuning with task-specific prompts affect model generalization across diverse code intelligence tasks?
- RQ5To what extent does identifier-aware pre-training enhance model understanding of code semantics across multiple programming languages?
Key findings
- CodeT5 achieves state-of-the-art performance on 14 out of 14 sub-tasks in the CodeXGLUE benchmark, outperforming prior methods in both code understanding and generation tasks.
- The identifier-aware pre-training objective significantly improves performance on code defect detection and clone detection, indicating better semantic understanding.
- The bimodal dual generation pre-training task leads to substantial gains on NL-PL and PL-NL tasks, such as code summarization and code translation.
- Multi-task fine-tuning with task control codes improves zero-shot generalization and performance across diverse code intelligence tasks.
- CodeT5-base, with 220M parameters, achieves performance comparable to much larger models like Codex (12B parameters), demonstrating high efficiency and effectiveness.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.