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

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.

[1]  Ge Li,et al.  CODEP: Grammatical Seq2Seq Model for General-Purpose Code Generation , 2023, ISSTA.

[2]  Ge Li,et al.  Self-collaboration Code Generation via ChatGPT , 2023, ACM Transactions on Software Engineering and Methodology.

[3]  Ge Li,et al.  Self-planning Code Generation with Large Language Models , 2023, ACM Transactions on Software Engineering and Methodology.

[4]  Ge Li,et al.  CodeScore: Evaluating Code Generation by Learning Code Execution , 2023, ArXiv.

[5]  Qi Guo,et al.  Incorporating domain knowledge through task augmentation for front-end JavaScript code generation , 2022, ESEC/SIGSOFT FSE.

[6]  Yue Wang,et al.  CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generation , 2021, EMNLP.

[7]  Fandong Meng,et al.  Exploring Dynamic Selection of Branch Expansion Orders for Code Generation , 2021, ACL.

[8]  Jianwei Cui,et al.  Improving Tree-Structured Decoder Training for Code Generation via Mutual Learning , 2021, AAAI.

[9]  Neel Sundaresan,et al.  CodeXGLUE: A Machine Learning Benchmark Dataset for Code Understanding and Generation , 2021, NeurIPS Datasets and Benchmarks.

[10]  Graham Neubig,et al.  Incorporating External Knowledge through Pre-training for Natural Language to Code Generation , 2020, ACL.

[11]  Lili Mou,et al.  TreeGen: A Tree-Based Transformer Architecture for Code Generation , 2019, AAAI.

[12]  Xin Xia,et al.  Code Generation as a Dual Task of Code Summarization , 2019, NeurIPS.

[13]  Graham Neubig,et al.  Reranking for Neural Semantic Parsing , 2019, ACL.

[14]  Oleksandr Polozov,et al.  Program Synthesis and Semantic Parsing with Learned Code Idioms , 2019, NeurIPS.

[15]  Lili Mou,et al.  A Grammar-Based Structural CNN Decoder for Code Generation , 2018, AAAI.

[16]  Graham Neubig,et al.  TRANX: A Transition-based Neural Abstract Syntax Parser for Semantic Parsing and Code Generation , 2018, EMNLP.

[17]  Graham Neubig,et al.  Retrieval-Based Neural Code Generation , 2018, EMNLP.

[18]  Graham Neubig,et al.  Learning to Mine Aligned Code and Natural Language Pairs from Stack Overflow , 2018, 2018 IEEE/ACM 15th International Conference on Mining Software Repositories (MSR).

[19]  Mirella Lapata,et al.  Coarse-to-Fine Decoding for Neural Semantic Parsing , 2018, ACL.

[20]  Lukasz Kaiser,et al.  Attention is All you Need , 2017, NIPS.

[21]  Dan Klein,et al.  Abstract Syntax Networks for Code Generation and Semantic Parsing , 2017, ACL.

[22]  Tommi S. Jaakkola,et al.  Tree-structured decoding with doubly-recurrent neural networks , 2016, ICLR.

[23]  Wang Ling,et al.  Latent Predictor Networks for Code Generation , 2016, ACL.

[24]  Mirella Lapata,et al.  Language to Logical Form with Neural Attention , 2016, ACL.

[25]  Tomoki Toda,et al.  Learning to Generate Pseudo-Code from Source Code Using Statistical Machine Translation (T) , 2015, 2015 30th IEEE/ACM International Conference on Automated Software Engineering (ASE).

[26]  Jimmy Ba,et al.  Adam: A Method for Stochastic Optimization , 2014, ICLR.

[27]  Raymond J. Mooney,et al.  Learning to Parse Database Queries Using Inductive Logic Programming , 1996, AAAI/IAAI, Vol. 2.

[28]  George R. Doddington,et al.  The ATIS Spoken Language Systems Pilot Corpus , 1990, HLT.

[29]  Yubin Ge,et al.  An AST Structure Enhanced Decoder for Code Generation , 2022, IEEE/ACM Transactions on Audio, Speech, and Language Processing.