[Paper Review] SPT-Code: Sequence-to-Sequence Pre-Training for Learning Source Code Representations
SPT-Code proposes a sequence-to-sequence pre-trained model for source code representation learning that jointly pre-trains both encoder and decoder using three novel, self-supervised tasks—code reconstruction, code structure modeling via AST traversal, and natural language description prediction—without requiring bilingual parallel data. It achieves state-of-the-art performance across five downstream code-related tasks, including code summarization, code completion, and bug fixing.
Recent years have seen the successful application of large pre-trained models to code representation learning, resulting in substantial improvements on many code-related downstream tasks. But there are issues surrounding their application to SE tasks. First, the majority of the pre-trained models focus on pre-training only the encoder of the Transformer. For generation tasks that are addressed using models with the encoder-decoder architecture, however, there is no reason why the decoder should be left out during pre-training. Second, many existing pre-trained models, including state-of-the-art models such as T5-learning, simply reuse the pre-training tasks designed for natural languages. Moreover, to learn the natural language description of source code needed eventually for code-related tasks such as code summarization, existing pre-training tasks require a bilingual corpus composed of source code and the associated natural language description, which severely limits the amount of data for pre-training. To this end, we propose SPT-Code, a sequence-to-sequence pre-trained model for source code. In order to pre-train SPT-Code in a sequence-to-sequence manner and address the aforementioned weaknesses associated with existing pre-training tasks, we introduce three pre-training tasks that are specifically designed to enable SPT-Code to learn knowledge of source code, the corresponding code structure, as well as a natural language description of the code without relying on any bilingual corpus, and eventually exploit these three sources of information when it is applied to downstream tasks. Experimental results demonstrate that SPT-Code achieves state-of-the-art performance on five code-related downstream tasks after fine-tuning.
Motivation & Objective
- Address the limitation of existing code pre-training models that only pre-train the encoder, leaving the decoder unoptimized.
- Overcome the reliance on small, bilingual code-docstring corpora by designing pre-training tasks that do not require labeled natural language descriptions during pre-training.
- Improve code representation by jointly learning source code structure (via AST) and natural language semantics without external supervision.
- Enable end-to-end pre-training of encoder-decoder models on fully unlabeled code data to boost performance on downstream software engineering tasks.
Proposed method
- Propose three self-supervised pre-training tasks: (1) code reconstruction via masked token prediction, (2) code structure modeling using an improved AST traversal method (X-SBT), and (3) natural language description prediction using code tokens as input.
- Design a hybrid input representation that combines source code tokens, AST traversals (via X-SBT), and natural language embeddings to enrich structural and semantic signals.
- Train the SPT-Code model end-to-end using a sequence-to-sequence Transformer architecture, pre-training both encoder and decoder on a large-scale, unlabeled code corpus.
- Use CodeSearchNet as the pre-training dataset, applying no duplicate removal to ensure fair comparison with baselines.
- Fine-tune the pre-trained SPT-Code model on five downstream tasks: code summarization, code completion, bug fixing (BFP), code search, and Java code summarization (JCSD).
- Introduce X-SBT, an enhanced AST traversal method that better captures code structure by preserving control and data flow semantics during traversal.
Experimental results
Research questions
- RQ1Can a sequence-to-sequence pre-trained model that jointly trains both encoder and decoder outperform encoder-only models in code representation learning?
- RQ2Can pre-training tasks that do not rely on bilingual code-docstring pairs still effectively learn natural language descriptions of code?
- RQ3To what extent does incorporating AST structure and natural language signals improve downstream code task performance?
- RQ4How do the three proposed pre-training tasks individually contribute to the model’s performance across different downstream tasks?
- RQ5Does the use of an improved AST traversal method (X-SBT) lead to better code structure modeling than standard traversal techniques?
Key findings
- SPT-Code achieves state-of-the-art performance on five downstream code-related tasks: code summarization (BLEU +0.88 over SOTA), code completion (Acc@1 +0.03), and bug fixing (BFP medium +0.07 accuracy).
- Ablation studies show that all three pre-training tasks contribute positively, with the AST-based task having the strongest impact on code structure understanding.
- The inclusion of both AST and natural language input components significantly improves model performance, indicating complementary benefits from structural and semantic signals.
- Even after removing test set duplicates from CodeSearchNet, SPT-Code’s performance degrades by less than 0.07 in any metric, indicating robustness to data leakage concerns.
- Models that incorporate AST information (e.g., SPT-Code, GraphCodeBERT) generate more accurate and readable summaries than those relying only on data flow or code tokens.
- The X-SBT traversal method outperforms standard AST traversal in capturing code structure, as evidenced by better summary quality and structural consistency.
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.