Page 183 - 《软件学报》2026年第2期
P. 183

软件学报 ISSN 1000-9825, CODEN RUXUEW                                        E-mail: jos@iscas.ac.cn
                 2026,37(2):662−683 [doi: 10.13328/j.cnki.jos.007504] [CSTR: 32375.14.jos.007504]  http://www.jos.org.cn
                 ©中国科学院软件研究所版权所有.                                                          Tel: +86-10-62562563



                                                                            *
                 基于依赖感知分层神经网络的代码注释增强方法

                 张育博  1,2 ,    姚开春  1,3 ,    张立波  1,3 ,    武延军  1,3 ,    赵    琛  1,3


                 1
                  (中国科学院 软件研究所 智能软件研究中心, 北京 100190)
                 2
                  (中国科学院大学, 北京 100049)
                 3
                  (计算机科学国家重点实验室       (中国科学院 软件研究所), 北京 100190)
                 通信作者: 姚开春, E-mail: yaokaichun@outlook.com

                 摘 要: 作为软件工程领域的一项新兴技术, 源代码自动生成注释旨在为给定的代码片段生成自然语言描述. 目前
                 最先进的代码注释技术采用编码器-解码器神经网络模型: 编码器提取源代码的语义表示, 而解码器则将其转换为
                 人类可读的代码注释. 然而, 许多现有方法将输入的代码片段视为独立函数, 往往忽略了目标函数与其调用的子函
                 数之间的上下文依赖关系. 忽视这些依赖关系可能导致关键语义信息的缺失, 从而降低生成注释的质量. 为此, 提
                 出了一种函数依赖感知的分层代码注释神经网络模型                     DHCS (dependency-aware hierarchical code summari-
                 zation). DHCS  通过显式建模目标函数与其子函数之间的分层依赖关系, 旨在提高代码注释的质量. 采用了一个分
                 层编码器, 包括子函数编码器和目标函数编码器, 使模型能够有效地捕捉局部和上下文的语义表示. 同时, 引入了
                 一项自监督任务, 即掩码子函数预测, 以增强子函数的表示学习. 此外, 提出挖掘子函数的主题分布, 并将其与主题
                 感知的复制机制相结合, 集成到注释解码器中. 因此, 它能够直接从子函数中提取关键信息, 从而更有效地生成目
                 标函数的注释. 最后, 在针对       Python、Java 和  Go  语言构建的  3  个真实数据集上进行了大量实验, 结果充分验证了
                 所提方法的有效性.
                 关键词: 代码注释生成; API 文档; 分层神经网络; 自监督任务
                 中图法分类号: TP311

                 中文引用格式: 张育博, 姚开春, 张立波, 武延军, 赵琛. 基于依赖感知分层神经网络的代码注释增强方法. 软件学报, 2026, 37(2):
                 662–683. http://www.jos.org.cn/1000-9825/7504.htm
                 英文引用格式: Zhang YB, Yao KC, Zhang LB, Wu YJ, Zhao C. Code Summarization Enhancing Method with Dependency-aware
                 Hierarchical Neural Network. Ruan Jian Xue Bao/Journal of Software, 2026, 37(2): 662–683 (in Chinese). http://www.jos.org.cn/1000-
                 9825/7504.htm

                 Code Summarization Enhancing Method with Dependency-aware Hierarchical Neural Network

                                          1,3
                                                       1,3
                                                                   1,3
                            1,2
                 ZHANG Yu-Bo , YAO Kai-Chun , ZHANG Li-Bo , WU Yan-Jun , ZHAO Chen 1,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


                 *    收稿时间: 2025-03-21; 修改时间: 2025-06-26; 采用时间: 2025-07-18; jos 在线出版时间: 2025-09-02
                  CNKI 网络首发时间: 2025-11-27
   178   179   180   181   182   183   184   185   186   187   188