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

680                                                        软件学报  2026  年第  37  卷第  2  期


                    在案例   2  中, 子函数提供了重绘操作的关键信息, 而两个             baseline 模型都忽略了这一点. 案例      3  中, 目标函数
                 包含了   3  个子函数, 它们分别从时间戳中提取年、月和日期信息. 如果没有考虑这些子函数, 很难进行正确的分析
                 并生成准确的注释, 如两个        baseline 模型所示. 案例  4  中, 子函数提供了返回队列中两个元素这一关键信息, 与参
                 考注释中返回     package rate 和  byte rate 相契合. DHCS  生成的注释符合参考注释的并列结构, 与代码中实际返回两
                 个速率值的逻辑一致, 这种结构相似性直接提升了                 ROUGE-L  的分数. 虽然   DHCS  的用词不完全准确, 但保留了
                 “rate”这一核心术语, 与参考注释高度相关. 而其他两种方法生成的注释则只关注到一个元素, 并且核心内容也不
                 贴切. 这进一步证明了本文模型通过整合子函数调用来增强代码注释性能.

                  6   总 结

                    本文提出了一种依赖感知的分层代码注释生成模型, 旨在通过建模目标函数与其调用的函数依赖之间的层次
                 结构, 增强代码注释生成任务的效果. 具体来说, 本文首先设计了一个分层编码器, 由子函数编码器和目标函数编
                 码器组成, 用于捕捉局部和上下文的语义表示. 此外, 引入了一种自监督目标——掩码子函数预测, 以增强子函数
                 的表示学习. 进一步考虑到子函数的关键作用, 还挖掘了被调用子函数的主题分布, 并设计了一个具有主题感知复
                 制机制的解码器, 直接提取子函数中的关键信息, 促进目标函数的注释生成. 最后, 为本研究构建了                             3  个真实世界
                 数据集, 并通过广泛的实验验证了所提出方法的有效性. 本文的工作不仅推进了代码注释生成领域的发展, 还解决
                 了关于代码依赖关系处理的问题, 为未来更全面、准确的代码注释生成技术奠定了基础.

                 References
                  [1]   Ahmad W, Chakraborty S, Ray B, Chang KW. A Transformer-based approach for source code summarization. In: Proc. of the 58th
                     Annual Meeting of the Association for Computational Linguistics. ACL, 2020. 4998–5007. [doi: 10.18653/v1/2020.acl-main.449]
                  [2]   Hu X, Li G, Xia X, Lo D, Jin Z. Deep code comment generation. In: Proc. of the 26th Conf. on Program Comprehension. Gothenburg:
                     ACM, 2018. 200–210. [doi: 10.1145/3196321.3196334]
                  [3]   Wan Y, Zhao Z, Yang M, Xu GD, Ying HC, Wu J, Yu PS. Improving automatic source code summarization via deep reinforcement
                     learning. In: Proc. of the 33rd ACM/IEEE Int’l Conf. on Automated Software Engineering. Montpellier: ACM, 2018. 397–407. [doi: 10.
                     1145/3238147.3238206]
                  [4]   Wei BL, Li G, Xia X, Fu ZY, Jin Z. Code generation as a dual task of code summarization. In: Proc. of the 33rd Int’l Conf. on Neural
                     Information Processing Systems. Vancouver: Curran Associates Inc., 2019. 589.
                  [5]   Bahdanau D, Cho K, Bengio Y. Neural machine translation by jointly learning to align and translate. In: Proc. of the 3rd Int’l Conf. on
                     Learning Representations. San Diego: OpenReview.net, 2015. [doi: 10.48550/arXiv.1409.0473]
                  [6]   Clement C, Drain D, Timcheck J, Svyatkovskiy A, Sundaresan N. PyMT5: Multi-mode translation of natural language and Python code
                     with  Transformers.  In:  Proc.  of  the  2020  Conf.  on  Empirical  Methods  in  Natural  Language  Processing  (EMNLP).  ACL,  2020.
                     9052–9065. [doi: 10.18653/v1/2020.emnlp-main.728]
                  [7]   LeClair A, Haque S, Wu LF, McMillan C. Improved code summarization via a graph neural network. In: Proc. of the 28th Int’l Conf. on
                     Program Comprehension. Seoul: ACM, 2020. 184–195. [doi: 10.1145/3387904.3389268]
                  [8]   LeClair A, Jiang SY, McMillan C. A neural model for generating natural language summaries of program subroutines. In: Proc. of the
                     41st IEEE/ACM Int’l Conf. on Software Engineering (ICSE). Montreal: IEEE, 2019. 795–806. [doi: 10.1109/ICSE.2019.00087]
                  [9]   Shi ES, Wang YL, Du L, Zhang HY, Han S, Zhang DM, Sun HB. CAST: Enhancing code summarization with hierarchical splitting and
                     reconstruction of abstract syntax trees. In: Proc. of the 2021 Conf. on Empirical Methods in Natural Language Processing. Punta Cana:
                     ACL, 2021. 4053–4062. [doi: 10.18653/v1/2021.emnlp-main.332]
                 [10]   Wu HQ, Zhao H, Zhang M. Code summarization with structure-induced Transformer. In: Proc. of the 2021 Findings of the Association
                     for Computational Linguistics (ACL-IJCNLP 2021). ACL, 2021. 1078–1090. [doi: 10.18653/v1/2021.findings-acl.93]
                 [11]   Hu X, Li G, Xia X, Lo D, Lu S, Jin Z. Summarizing source code with transferred API knowledge. In: Proc. of the 27th Int’l Joint Conf.
                     on Artificial Intelligence. Stockholm: ijcai.org, 2018. 2269–2275. [doi: 10.24963/ijcai.2018/314]
                 [12]   Rozière B, Gehring J, Gloeckle F, Sootla S, Gat I, Tan XE, Adi Y, Liu JY, Remez T, Rapin J, Kozhevnikov A, Evtimov I, Bitton J, Bhatt
                     M, Ferrer CC, Grattafiori A, Xiong WH, Défossez A, Copet J, Azhar F, Touvron H, Martin L, Usunier N, Scialom T, Synnaeve G. Code
                     LLaMA: Open foundation models for code. arXiv:2308.12950, 2023.
   196   197   198   199   200   201   202   203   204   205   206