论文标题

先例预测比您想象的要重要:基于树代码生成的有效方法

Antecedent Predictions Are More Important Than You Think: An Effective Method for Tree-Based Code Generation

论文作者

Dong, Yihong, Li, Ge, Jiang, Xue, Jin, Zhi

论文摘要

代码生成的重点是将自然语言(NL)的自动转换为代码段。序列对树(SEQ2TREE)方法是为代码生成而提出的,并保证了生成的代码的语法正确性,该代码的语法正确性会生成随后依靠AST节点的前提预测的随后的抽象语法树(AST)节点。现有的SEQ2TREE方法倾向于同时对待前期预测和随后的预测。但是,在AST约束下,SEQ2TREE模型很难基于不正确的先行预测来产生正确的后续预测。因此,与后续的预测相比,先行预测应该受到更多的关注。为此,在本文中,我们提出了一种有效的方法,称为先行优先(AP)损失,该方法通过利用生成的AST节点的位置信息来帮助该模型对先行预测的重要性。我们设计了AST-to-vector(AST2VEC)方法,该方法将AST节点位置映射到二维矢量,以模拟AST节点的位置信息。为了评估我们提议的损失的有效性,我们实施并培训了一个名为APT的基于树的优先级代码生成模型。有了更好的先行预测和随后的预测,APT显着提高了性能。我们在四个基准数据集上进行了广泛的实验,实验结果证明了我们提出的方法的优势和普遍性。

Code generation focuses on the automatic conversion of natural language (NL) utterances into code snippets. The sequence-to-tree (Seq2Tree) approaches are proposed for code generation, with the guarantee of the grammatical correctness of the generated code, which generate the subsequent Abstract Syntax Tree (AST) node relying on antecedent predictions of AST nodes. Existing Seq2Tree methods tend to treat both antecedent predictions and subsequent predictions equally. However, under the AST constraints, it is difficult for Seq2Tree models to produce the correct subsequent prediction based on incorrect antecedent predictions. Thus, antecedent predictions ought to receive more attention than subsequent predictions. To this end, in this paper, we propose an effective method, named Antecedent Prioritized (AP) Loss, that helps the model attach importance to antecedent predictions by exploiting the position information of the generated AST nodes. We design an AST-to-Vector (AST2Vec) method, that maps AST node positions to two-dimensional vectors, to model the position information of AST nodes. To evaluate the effectiveness of our proposed loss, we implement and train an Antecedent Prioritized Tree-based code generation model called APT. With better antecedent predictions and accompanying subsequent predictions, APT significantly improves the performance. We conduct extensive experiments on four benchmark datasets, and the experimental results demonstrate the superiority and generality of our proposed method.

扫码加入交流群

加入微信交流群

微信交流群二维码

扫码加入学术交流群,获取更多资源