arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2303.05061cs.SE
收藏

一种面向Turducken式代码生成的语法引导多任务学习方法

A Syntax-Guided Multi-Task Learning Approach for Turducken-Style Code Generation

Guang Yang, Yu Zhou, Xiang Chen, Xiangyu Zhang, Yiran Xu, Tingting Han, Taolue Chen

AI总结:

针对Turducken式代码生成中语法约束缺失的挑战,提出语法引导的多任务学习方法TurduckenGen,通过类型信息附加、辅助任务形式化和编译器反馈选择,有效提升了生成代码的语法正确性和质量。

摘要:

由于预训练语言模型的发展,自动代码生成技术在近年来展现出巨大潜力。然而,生成的代码难以满足目标语言的语法约束,特别是在Turducken式代码中,声明式代码片段被嵌入到命令式程序中。在本研究中,我们将语法约束的缺乏总结为三个重大挑战:(1)语法约束的高效表示,(2)语法信息的有效整合,以及(3)可扩展的语法优先解码算法。为了应对这些挑战,我们提出了一种语法引导的多任务学习方法TurduckenGen。具体而言,我们首先显式地将类型信息附加到代码标记上,以捕获语法约束的表示。然后,我们将带有语法约束表示的代码生成形式化为辅助任务,使模型能够学习代码的语法约束。最后,借助编译器反馈,从多个候选中准确选择语法正确的代码。大量实验和全面分析表明,在两个Turducken式代码数据集上与六个最先进的基线进行比较后,我们方法的有效性和普遍适用性得到了验证。最后,我们进行了一项人类研究,发现我们方法生成的代码在代码可读性和语义相似性方面优于基线。

英文摘要:

Due to the development of pre-trained language models, automated code generation techniques have shown great promise in recent years. However, the generated code is difficult to meet the syntactic constraints of the target language, especially in the case of Turducken-style code, where declarative code snippets are embedded within imperative programs. In this study, we summarize the lack of syntactic constraints into three significant challenges: (1) the efficient representation of syntactic constraints, (2) the effective integration of syntactic information, and (3) the scalable syntax-first decoding algorithm. To address these challenges, we propose a syntax-guided multi-task learning approach TurduckenGen. Specifically, we first explicitly append the type information to the code tokens to capture the representation of syntactic constraints. Then we formalize code generation with syntactic constraint representation as an auxiliary task to enable the model to learn the syntactic constraints of the code. Finally, the syntactically correct code is selected accurately from the multiple candidates with the help of the compiler feedback. Extensive experiments and comprehensive analysis demonstrate the effectiveness and general applicability of our approach after being compared with six state-of-the-art baselines on two Turducken-style code datasets. Finally, we conducted a human study and found the code quality generated by our approach is better than baselines in terms of code readability and semantic similarity.

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

↑