arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2206.05239cs.LGcs.SE
收藏

StructCoder:面向代码生成的结构感知Transformer

StructCoder: Structure-Aware Transformer for Code Generation

Virginia Tech(弗吉尼亚理工大学)

Sindhu Tipirneni, Ming Zhu, Chandan K. Reddy

AI总结:

针对现有代码生成模型对代码语法语义理解不足的问题,提出结构感知Transformer模型StructCoder,通过在编码器和解码器中分别融入语法、数据流信息及相关辅助任务,在多个代码生成基准上取得优于同规模基线的性能。

摘要:

近年来,利用深度学习实现软件工程任务自动化的研究热度激增。本文聚焦代码生成问题,其目标是根据不同语言的源代码或自然语言描述生成目标代码。大多数最先进的代码生成深度学习模型采用的训练策略主要是为自然语言设计的。然而,理解和生成代码需要对代码的语法和语义有更严谨的理解。基于这一动机,我们开发了一种编码器-解码器Transformer模型,其编码器和解码器都经过显式训练,可分别识别源代码和目标代码中的语法与数据流。我们不仅通过利用源代码的语法树和数据流图让编码器具备结构感知能力,还通过引入两个新颖的辅助任务——AST(抽象语法树)路径预测和数据流预测,帮助解码器保留目标代码的语法和数据流。据我们所知,这是首个引入结构感知Transformer解码器的工作,该解码器同时对语法和数据流建模,以提升生成代码的质量。所提出的StructCoder模型在CodeXGLUE基准的代码翻译和文本到代码生成任务上取得了最先进的性能,并且在APPS代码生成基准上优于同等规模的基线模型。我们的代码已公开在https://github.com/reddy-lab-code-research/StructCoder/。

英文摘要:

There has been a recent surge of interest in automating software engineering tasks using deep learning. This paper addresses the problem of code generation, where the goal is to generate target code given source code in a different language or a natural language description. Most state-of-the-art deep learning models for code generation use training strategies primarily designed for natural language. However, understanding and generating code requires a more rigorous comprehension of the code syntax and semantics. With this motivation, we develop an encoder-decoder Transformer model where both the encoder and decoder are explicitly trained to recognize the syntax and data flow in the source and target codes, respectively. We not only make the encoder structure-aware by leveraging the source code's syntax tree and data flow graph, but we also support the decoder in preserving the syntax and data flow of the target code by introducing two novel auxiliary tasks: AST (Abstract Syntax Tree) paths prediction and data flow prediction. To the best of our knowledge, this is the first work to introduce a structure-aware Transformer decoder that models both syntax and data flow to enhance the quality of generated code. The proposed StructCoder model achieves state-of-the-art performance on code translation and text-to-code generation tasks in the CodeXGLUE benchmark, and improves over baselines of similar size on the APPS code generation benchmark. Our code is publicly available at https://github.com/reddy-lab-code-research/StructCoder/.

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

↑