Encoding Beacon Statements for Code Comment Generation

Nan Jia, Jie Chen, Mingliang Li · Research Square · 2023

Abstract High-quality code comment is important to help developer review and comprehend source code. Inspired by the effectiveness of deep learning techniques in the NLP field, many studies focus on using the machine translation algorithm to automatically generate comment for the source code. Most of the current studies typically involve in collecting a large number of dataset regarding the function-comment pairs, and then encode the information (e.g., AST) from the whole function for training a generation model. Most of current studies indistinguishably encode every statement in a function, which may not be the best strategy for comment generation because each statement in a function plays different roles, and the non-core code statements may have no effect or even a negative effect on the comment generation. In this paper, we propose a flexible encoding strategy that highlights the most informative statements from the function, called beacon statements, for code comment generation. Specifically, the beacon statements are detected from the function according to their roles when human understanding program, and then a pre-training model is proposed to encode the knowledge of the beacon statements. At last, the knowledge of the beacon statements is transferring to a basic model for comment generation by sharing the training parameters. The encouraging experimental results demonstrate the feasibility and effectiveness of our comment generation model.

Read the paper · More papers on PaperTik