引用本文:张育博,姚开春,张立波,武延军,赵琛.基于依赖感知分层神经网络的代码注释增强方法.软件学报,2026,37(2):662-683
【打印本页】   【下载PDF全文】   查看/发表评论  【EndNote】   【RefMan】   【BibTex】
←前一篇|后一篇→ 过刊浏览    高级检索
本文已被:浏览 788次   下载 1943 本文二维码信息
码上扫一扫!
分享到: 微信 更多
基于依赖感知分层神经网络的代码注释增强方法
张育博1,2, 姚开春1,3, 张立波1,3, 武延军1,3, 赵琛1,3
1.中国科学院 软件研究所 智能软件研究中心, 北京 100190;2.中国科学院大学, 北京 100049;3.计算机科学国家重点实验室(中国科学院 软件研究所), 北京 100190
摘要:
作为软件工程领域的一项新兴技术, 源代码自动生成注释旨在为给定的代码片段生成自然语言描述. 目前最先进的代码注释技术采用编码器-解码器神经网络模型: 编码器提取源代码的语义表示, 而解码器则将其转换为人类可读的代码注释. 然而, 许多现有方法将输入的代码片段视为独立函数, 往往忽略了目标函数与其调用的子函数之间的上下文依赖关系. 忽视这些依赖关系可能导致关键语义信息的缺失, 从而降低生成注释的质量. 为此, 提出了一种函数依赖感知的分层代码注释神经网络模型DHCS (dependency-aware hierarchical code summarization). DHCS通过显式建模目标函数与其子函数之间的分层依赖关系, 旨在提高代码注释的质量. 采用了一个分层编码器, 包括子函数编码器和目标函数编码器, 使模型能够有效地捕捉局部和上下文的语义表示. 同时, 引入了一项自监督任务, 即掩码子函数预测, 以增强子函数的表示学习. 此外, 提出挖掘子函数的主题分布, 并将其与主题感知的复制机制相结合, 集成到注释解码器中. 因此, 它能够直接从子函数中提取关键信息, 从而更有效地生成目标函数的注释. 最后, 在针对Python、Java和Go语言构建的3个真实数据集上进行了大量实验, 结果充分验证了所提方法的有效性.
关键词:  代码注释生成  API文档  分层神经网络  自监督任务
DOI:10.13328/j.cnki.jos.007504
分类号:TP311
基金项目:
Code Summarization Enhancing Method with Dependency-aware Hierarchical Neural Network
ZHANG Yu-Bo1,2, YAO Kai-Chun1,3, ZHANG Li-Bo1,3, WU Yan-Jun1,3, ZHAO Chen1,3
1.Intelligent Software Research Center, Institute of Software, Chinese Academy of Sciences, Beijing 100190, China;2.University of Chinese Academy of Sciences, Beijing 100049, China;3.State Key Laboratory of Computer Science (Institute of Software, Chinese Academy of Sciences), Beijing 100190, China
Abstract:
As an emerging technique in software engineering, automatic source code summarization aims to generate natural language descriptions for given code snippets. State-of-the-art code summarization techniques utilize encoder-decoder neural models. The encoder extracts the semantic representations of the source code, while the decoder translates them into human-readable code summaries. However, many existing approaches treat input code snippets as standalone functions, often overlooking the context dependencies between the target function and its invoked subfunctions. Ignoring these dependencies can result in the omission of crucial semantic information, potentially reducing the quality of the generated summaries. To this end, this study proposes a dependency-aware hierarchical code summarization neural model, DHCS. DHCS is designed to improve code summarization by explicitly modeling the hierarchical dependencies between the target function and its subfunctions. The proposed approach employs a hierarchical encoder consisting of both a subfunction encoder and a target function encoder, allowing the model to capture both local and contextual semantic representations effectively. Meanwhile, a self-supervised task, namely the masked subfunction prediction, is introduced to enhance the representation learning of subfunctions. Furthermore, the topic distribution of subfunctions is mined and incorporated into a summary decoder with a topic-aware copy mechanism. Therefore, it enables the direct extraction of key information from subfunctions, facilitating more effective summary generation for the target function. Finally, extensive experiments are conducted on three real-world datasets constructed for Python, Java, and Go languages, which clearly validate the effectiveness of the proposed approach.
Key words:  code summarization generation  API document  hierarchical neural network  self-supervised task

引用本文:
【打印本页】   【下载PDF全文】   查看/发表评论  【EndNote】   【RefMan】   【BibTex】
←前一篇|后一篇→ 过刊浏览    高级检索
本文已被:浏览次   下载  
分享到: 微信 更多
摘要:
关键词:  
DOI:
分类号:
基金项目:
Abstract:
Key words: