arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2401.03003cs.SEcs.CLcs.LG
收藏

AST-T5:面向代码生成与理解的结构感知预训练

AST-T5: Structure-Aware Pretraining for Code Generation and Understanding

University of California at Berkeley(加州大学伯克利分校);AI at Meta(元人工智能部门)

Linyuan Gong, Mostafa Elhoushi, Alvin Cheung

AI总结:

针对大语言模型忽略代码结构化特性的问题,提出基于AST的预训练范式AST-T5,通过结构感知分割与跨度掩码目标提升代码任务性能,无需复杂改动即可适配编码器-解码器Transformer,在多项代码任务上超越同规模模型。

摘要:

大语言模型(LLM)在代码相关任务中已取得显著进展,但多数LLM将代码视为简单序列,忽略了其结构化特性。我们提出AST-T5,这是一种新型预训练范式,利用抽象语法树(Abstract Syntax Tree,AST)提升代码生成、转译与理解能力。通过动态规划,我们的AST感知分割(AST-Aware Segmentation)保留了代码结构,而AST感知跨度掩码(AST-Aware Span Corruption)目标则让模型具备重构各类代码结构的能力。与其他模型不同,AST-T5无需复杂的程序分析或架构改动,因此可无缝集成到任意编码器-解码器Transformer中。评估结果显示,在各类代码相关任务上,AST-T5的表现始终优于同等规模的语言模型。结构感知特性让AST-T5在代码到代码任务中表现尤为突出,在Bugs2Fix任务的精确匹配得分上比CodeT5高2分,在CodeXGLUE的Java-C#转译任务的精确匹配得分上高3分。我们的代码和模型已在https://github.com/gonglinyuan/ast_t5 公开。

英文摘要:

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.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑