The existing deep learning code generation methods are insufficient in capturing local structural features, low in grammatical correctness and limited in long sequence efficiency. Therefore, an intelligent code automatic generation system combining abstract syntax tree (AST) and multi-scale convolutional neural network (CNN) is proposed. The system adopts the encoder-decoder architecture: the encoder extracts the multi-scale local and global features of the code text sequence and AST node sequence through parallel convolution kernels (sizes 3, 5 and 7), and uses the element-by-element weighted fusion mechanism to enhance grammar perception, The decoder generates codes based on mask CNN autoregressive, and introduces cross-attention mechanism to dynamically associate the input description with the generated codes. Experiments on CONCODE data set show that the proposed model CNN-CodeGen achieves 28.37% in BLEU-4, 38.95% in CodeBLEU and 10.26% in exact matching rate (EM), which are significantly better than the baseline models such as Seq2Seq, Transformer and CodeGPT. Ablation experiments verify the key role of AST fusion, multi-scale convolution and attention module in improving the functional correctness and grammatical rigor of the code. In addition, with the parallel computing characteristics of CNN, the system has obvious advantages over the Transformer model in training and reasoning efficiency, which provides a new idea for efficient and accurate code generation.
Lan Yang (Sun,) studied this question.