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.
翻译:大型语言模型(LLM)在代码相关任务上取得了显著进展,但许多LLM将代码视为简单序列,忽略了其结构化特性。我们提出AST-T5这一新型预训练范式,利用抽象语法树(AST)增强代码生成、转换与理解能力。通过动态规划方法,我们的AST感知分割机制保留代码结构,而AST感知跨度破坏目标则使模型能够重构多种代码结构。与其他模型不同,AST-T5无需复杂的程序分析或架构修改,可无缝集成至任意编码器-解码器Transformer。评估结果表明,AST-T5在各类代码任务中持续优于同等规模的语言模型。结构感知特性使AST-T5在代码到代码任务中表现尤为突出:在Bugs2Fix任务上精确匹配得分超过CodeT5 2个百分点,在CodeXGLUE的Java-C#转换任务中超出3个百分点。我们的代码与模型已公开于https://github.com/gonglinyuan/ast_t5。