CodePAD:基于序列的下推自动机代码生成
CodePAD: Sequence-based Code Generation with Pushdown Automaton
摘要:
在代码生成过程中,保证生成的代码满足程序设计语言的语法约束是至关重要的。然而,忽略语法约束是常用的基于序列的代码生成的致命缺点。在本文中,我们设计了一个基于下推自动机(PDA)的方法来解决这个问题,利用PL是PDA可识别语言的子集和PDA接受的代码是语法的原则。具体来说,我们构建了一个PDA模块,并设计了一个算法来约束基于序列的模型的生成,以确保语法的正确性。在此方法的指导下,我们进一步提出了CodePAD,一个基于序列的代码生成框架,配备了PDA模块,将PDA的推导集成到深度学习中。此外,该框架可以利用PDA推导的状态(包括状态表示、状态预测任务和与状态的联合预测)来帮助模型学习PDA推导。为了全面评估CodePAD,我们为Python构建了一个PDA,并在四个公共基准数据集上进行了广泛的实验。CodePAD可以利用现有的基于序列的模型,我们表明,它可以在这些基准数据集上实现100\%的语法正确率。因此,与基本模型相比,它在CONALA上相对提高了17% CodeBLEU,在Django上提高了8% EM,在JUICE-10 K上提高了15% CodeBLEU。此外,我们的方法显著增强了预训练模型,例如,CodeGen-350 M的CodeBLEU在zero-shot设置下将MBPP从3.21提高到21.54。
英文摘要:
In the process of code generation, it is essential to guarantee the generated code satisfies grammar constraints of programming language (PL). However, neglecting grammar constraints is a fatal drawback of commonly used sequence-based code generation. In this paper, we devise a pushdown automaton (PDA)-based methodology to address this problem, exploiting the principle that PL is a subset of PDA recognizable language and code accepted by PDA is grammatical. Specifically, we construct a PDA module and design an algorithm to constrain the generation of sequence-based models to ensure grammatical correctness. Guided by this methodology, we further propose CodePAD, a sequence-based code generation framework equipped with a PDA module, to integrate the deduction of PDA into deep learning. Additionally, this framework can leverage states of PDA deduction (including state representation, state prediction task, and joint prediction with state) to assist models in learning PDA deduction. To comprehensively evaluate CodePAD, we construct a PDA for Python and conduct extensive experiments on four public benchmark datasets. CodePAD can leverage existing sequence-based models, and we show that it can achieve 100\% grammatical correctness percentage on these benchmark datasets. Thus, it relatively improve 17\% CodeBLEU on CONALA, 8\% EM on DJANGO, and 15\% CodeBLEU on JUICE-10K compared to base models. In addition, our method significantly enhances pre-trained models, e.g., CodeBLEU of CodeGen-350M improvement from 3.21 to 21.54 on MBPP in zero-shot setting.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。