KFCC: A differentiation-aware and keyword-guided fine-grain code comment generation model

Rui Zhang, Ziyue Qiao, Chenghao Zhang, Jianjun Yu · Expert Systems with Applications · 2024

An efficient and accurate understanding of the intent of code is an indispensable skill in computer technology, especially in collaborative engineering and experimental reproduction. AI-assisted automated code comment generator, with the goal of generating programmer-readable explanations, has been an emerging hot topic for software project comprehension. Despite promising performances, three critical issues emerged: 1) The summary comment is limited in understanding the fine-grain details of the code. 2) key-word level guidance in the model should be included for better comments generation. 3) performance of the generative model may be dampened by noises in the manual annotation. In response, we propose a novel fine-grain comment generation, a scenario of generating the statement-level comment with the assistance of method-level comment. We also propose KFCC, a differentiation-aware and keyword-guided fine-grain comment generation model. Specifically, the proposed KFCC model generates the statement-level comments by incorporating the key information extracted by the keyword extractor in a gate fusion way. To enhance the effectiveness and robustness of the proposed KFCC model, we propose a differentiation-aware enhancing encoder comprehension, letting the model distinguish significant knowledge via contrastive learning. Extensive experiments conducted on open-source projects demonstrate that the KFCC model achieves outstanding performance in six programming languages (including Ruby, Python, JavaScript, Java, etc.) on the CodeSearchNet benchmark.

Read the paper · More papers on PaperTik