| Code comment generation technology analyzes the source code and automatically generates comments for the source code.This technology not only helps developers better understand the source code,but also reduces the time cost of software development and maintenance.The traditional code comment generation method requires manual construction of templates,which not only requires developers to have rich domain knowledge,but also is very time-consuming to construct templates.In order to reduce the labor cost of generating code comments,a code comment generation method based on artificial intelligence(AI)came into being.The AI-based code comment generation method is a data-driven method that generates code comments by designing and training a neural network model.AI-based methods can avoid the process of manually constructing templates,and can quickly generate code comments when used,but there is a problem that training neural network models is time-consuming and the quality of code comments is not high.The AI-based code comment generation method includes two parts:the representation of the source code and the design of the neural network model.Code text and Abstract Syntax Tree(AST)are common code representation methods in the field of code comment generation.AST is a tree structure,it is difficult to directly input the neural network model,so researchers usually use structure-based traversa(SBT)method to traverse the AST.However,this traversal method will generate a lot of redundant information and produce a long sequence.The existing code comment generation model is implemented based on the structure of encoder and decoder.Both encoder and decoder use Recurrent Neural Network(RNN).But they all face the problem of long-term dependence,and the code text and AST are separately coded during the coding process,ignoring the relationship between the two.In order to solve the above problems,this paper proposes an AST traversal method and three AI-based code comment generation models.Specifically,in view of the excessive redundant information generated by the SBT method traversing the AST,this paper proposes a RAST method for optimization.Aiming at the long dependency problem in the code comment generation method,a code comment generation method SeCNN based on Convolutional Neural Network(CNN)is proposed.SeCNN effectively alleviates the problem of long-term dependence by designing two CNN components.Aiming at the current research methods ignoring the relationship between code text and AST,a Transformer-based code comment generation method SeTransformer is proposed.SeTransformer uses an improved Transformer model to jointly encode the vocabulary and structural information of the source code to extract semantic information,effectively using the relationship between the code text and the AST.Finally,we combine SeCNN and SeTransformer to propose a code comment generation method ISeTransformer,which further reduces the execution time of the model.This paper uses a large-scale Java dataset for experiments,which contains 87,136 pairs of<Java method,comment>data.Experimental results show that,compared with other code comment generation methods,the code comment generation method proposed in this article has achieved the best results on both the BLEU and METEOR indicators.At the same time,the RAST method can effectively reduce the training time of the model without loss of accuracy. |