An Intra-Class Relation Guided Approach for Code Comment Generation
33354Authors
nan
Abstract
AbstractCode comments are critical for maintaining and comprehending software programs, but they are often missing, mismatched, or outdated in practice. Code comment generation task aims to automatically produce descriptive comments for code snippets. Recently, methods based on the neural encoder-decoder architecture have achieved impressive performance. These methods assume that all the information required to generate comments is encoded in the target function itself, yet in most realistic situations, it is hard to understand a function in isolation from the surrounding context. Furthermore, the global context may contain redundant information that should not be introduced. To address the above issues, we present a novel graph-based learning framework to capture various relations among functions in a class file. Our approach is based on a common real-world scenario in which only a few functions in the source file have human-written comments. Guided by intra-class function relations, our model incorporates contextual information extracted from both the source code and available comments to generate missing comments. We conduct experiments on a Java dataset collected from real-world projects. Experimental results show that the proposed method outperforms competitive baseline models on all automatic and human evaluation metrics.
Keywords
Full Content
Findings of the Association for Computational Linguistics: EACL 2023, pages 1321–1333 May 2-6, 2023 ©2023 Association for Computational Linguistics An Intra-Class Relation Guided Approach for Code Comment Generation Zhenni Wang†, Xiaohan Yu†, Yansong Feng∗, Dongyan Zhao Wangxuan Institute of Computer Technology, Peking University, China The MOE Key Laboratory of Computational Linguistics, Peking University, China {wangzhenni,yuxiaohan,fengyansong,zhaodongyan}@pku.edu.cn Abstract Code comments are critical for maintaining and comprehending software programs, but they are often missing, mismatched, or outdated in prac- tice. Code comment generation task aims to automatically produce descriptive comments for code snippets. Recently, methods based on the neural encoder-decoder architecture have achieved impressive performance. These meth- ods assume that all the information required to generate comments is encoded in the tar- get function itself, yet in most realistic situ- ations, it is hard to understand a function in isolation from the surrounding context. Fur- thermore, the global context may contain re- dundant information that should not be intro- duced. To address the above issues, we present a novel graph-based learning framework to cap- ture various relations among functions in a class file. Our approach is based on a common real-world scenario in which only a few func- tions in the source file have human-written com- ments. Guided by intra-class function relations, our model incorporates contextual information extracted from both the source code and avail- able comments to generate missing comments. We conduct experiments on a Java dataset col- lected from real-world projects. Experimental results show that the proposed method outper- forms competitive baseline models on all auto- matic and human evaluation metrics. 1 Introduction Code comment generation is the task of automati- cally producing natural language descriptions for given code snippets. Appropriate and sufficient comments are essential for software maintenance and understanding (Xia et al., 2018). They allow developers to grasp the purpose of source code quickly and accurately. However, in real-life soft- ware projects, comments are often missing, incom- plete or outdated (Briand, 2003). Existing com- †Equal contribution. *Corresponding author. 1 private void firePropertyChange (String propName, 2 Object oldValue, Object newValue) { 3 PropertyChangeEvent evt = new PropertyChangeEvent(); 4 ... 5 } 6 /* Removes a time series from the map and fires a TS_REMOVED PropertyChangeEvent.*/ 7 public removeTS (String name) { 8 boolean fireChanged = false; 9 ... 10 if (fireChanged) 11 firePropertyChange(TS_REMOVED, name, name); 12 } 13 /* Removes all time series from the map and fires an ALL_TS_REMOVED PropertyChangeEvent.*/ 14 public removeAllTS() { 15 ... 16 firePropertyChange(ALL_TS_REMOVED, null, null); 17 } Table 1: Example illustrating the importance of utilizing class-level contextual information. ments will also need to be adjusted as the associ- ated programs are updated, which could cause large time and labor costs. Hence, there is a significant need for automatic generation technologies that can effectively produce high-quality comments. Recent works in code comment generation take the neural encoder-decoder architecture as their cornerstone (Hu et al., 2018a; Alon et al., 2019; LeClair et al., 2020; Zhang et al., 2020; Wei et al., 2020). However, these works only …
Content truncated to 500 words
Labeled Text
AbstractCode comments are critical for maintaining and comprehending software programs, but they are often missing, mismatched, or outdated in practice. Code comment generation task aims to automatically produce descriptive comments for code snippets. Recently, methods based on the neural encoder-decoder architecture have achieved impressive performance. These methods assume that all the information required to generate comments is encoded in the target function itself, yet in most realistic situations, it is hard to understand a function in isolation from the surrounding context. Furthermore, the global context may contain redundant information that should not be introduced. To address the above issues, we present a novel graph-based learning framework to capture various relations among functions in a class file. Our approach is based on a common real-world scenario in which only a few functions in the source file have human-written comments. Guided by intra-class function relations, our model incorporates contextual information extracted from both the source code and available comments to generate missing comments. We conduct experiments on a Java dataset collected from real-world projects. Experimental results show that the proposed method outperforms competitive baseline models on all automatic and human evaluation metrics.
Publication Details
- Paper ID:
- 33354
- Year:
- 2023
- Publication:
- TIPSTER
- Publication Type:
- conf
- DOI:
- nan