[Paper Review] AST-T5: Structure-Aware Pretraining for Code Generation and Understanding
AST-T5 introduces AST-aware pretraining for encoder-decoder LMs, using AST-aware segmentation and AST-aware subtree masking to improve code generation, transpilation, and understanding without architectural changes.
Large language models (LLMs) have made significant advancements in code-related tasks, yet many LLMs treat code as simple sequences, neglecting its structured nature. We introduce AST-T5, a novel pretraining paradigm that leverages the Abstract Syntax Tree (AST) for enhanced code generation, transpilation, and understanding. Using dynamic programming, our AST-Aware Segmentation retains code structure, while our AST-Aware Span Corruption objective equips the model to reconstruct various code structures. Unlike other models, AST-T5 avoids intricate program analyses or architectural changes, so it integrates seamlessly with any encoder-decoder Transformer. Evaluations show that AST-T5 consistently outperforms similar-sized LMs across various code-related tasks. Structure-awareness makes AST-T5 particularly powerful in code-to-code tasks, surpassing CodeT5 by 2 points in exact match score for the Bugs2Fix task and by 3 points in exact match score for Java-C# Transpilation in CodeXGLUE. Our code and model are publicly available at https://github.com/gonglinyuan/ast_t5.
Motivation & Objective
- Motivation to treat code as structured, not just a sequence, to improve code-related tasks.
- Develop a structure-aware pretraining paradigm that requires no complex program analyses.
- Enable seamless integration with existing encoder-decoder Transformers as a drop-in replacement.
- Demonstrate improvements across generation, transpilation, and understanding benchmarks.
Proposed method
- Parse code into ASTs using Tree-sitter to capture structure.
- Apply AST-Aware Segmentation to partition code with minimal AST structure breaks.
- Apply AST-Aware Subtree Corruption to mask AST subtrees during span corruption.
- Train with a single pretraining objective (span corruption) augmented by structure-aware masking.
- Maintain compatibility with Vanilla T5 without extra heads or architectures.
Experimental results
Research questions
- RQ1Does AST-aware segmentation preserve code structure better than greedy segmentation during pretraining?
- RQ2Does AST-aware subtree masking improve generation and transpilation quality compared with standard span corruption?
- RQ3Can a single pretraining objective with structure-aware modifications achieve competitive performance on code understanding and generation tasks?
- RQ4How does AST-T5 perform relative to CodeT5 and CodeT5+ on HumanEval, MBPP, Bugs2Fix, and Java-C# transpilation?
Key findings
- AST-Aware Segmentation yields more coherent training chunks than Greedy Segmentation, reducing AST structure breaks.
- AST-Aware Subtree Corruption improves generation and transpilation metrics versus vanilla span corruption.
- Increasing mask ratio to 25% boosts generation with limited impact on understanding; 50% yields diminishing returns.
- AST-T5 achieves strong results for its size, outperforming similar-sized models like CodeT5 and CodeT5+ on multiple tasks.
- In transpilation and clone detection, AST-awareness provides a notable edge over baselines.
- AST-T5 competes with larger models on HumanEval and MBPP, highlighting parameter efficiency.
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.