先行预测比你认为的更重要:一种有效的基于树的代码生成方法
Antecedent Predictions Are More Important Than You Think: An Effective Method for Tree-Based Code Generation
AI总结:
针对现有Seq2Tree代码生成方法对AST前后节点预测同等重视的问题,提出先行优先损失与AST2Vec位置建模方法,构建APT模型,在四个基准数据集上验证了其性能优越性与通用性。
摘要:
代码生成致力于将自然语言(NL)表述自动转换为代码片段。序列到树(Seq2Tree)方法被提出用于代码生成,可保证生成代码的语法正确性,这类方法依赖抽象语法树(AST)节点的先行预测来生成后续的AST节点。现有Seq2Tree方法往往对先行预测和后续预测一视同仁。然而,在AST的约束下,Seq2Tree模型很难基于错误的先行预测得出正确的后续预测。因此,先行预测理应比后续预测得到更多关注。为此,本文提出了一种名为先行优先(Antecedent Prioritized, AP)损失的有效方法,该方法通过利用生成的AST节点的位置信息,帮助模型重视先行预测。我们设计了一种AST到向量(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.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。