Page 139 - 《软件学报》2026年第2期
P. 139
618 软件学报 2026 年第 37 卷第 2 期
Wei 等人 [13] 和 Liu 等人 [28] 使用 Lucene 和 BM25 算法相结合的检索方式从代码数据库中检索相似代码, 而 Liu 等
人 [28] 则使用基于向量的密集通道检索模型来搜索相似代码. 在利用检索到的相似代码方面, 前述方法直接将检索
到的相似代码和注释编码到深度神经网络模型中, 而 Li 等人 [15] 则是通过一种检索-编辑方式来重用原型摘要中的
模式词汇.
尽管上述代码注释生成方法取得了一定效果, 但是基于信息检索的方法无法有效应对结构复杂的代码, 基于
深度学习的方法则在长注释场景下性能欠佳 [16] . 基于集成的方法对信息检索技术和深度学习技术进行了一定结
合, 但现有基于集成的方法仍主要依赖于深度神经网络模型进行代码注释生成. 此外, 为了集成信息检索技术, 现
有基于集成的方法往往还需要设计特定的模型结构或模型训练方式, 一定程度上限制了这些方法的可扩展性. 不
同于现有方法, 我们所提出的代码注释生成方法 SRBCS 通过语义重排序模型对不同方法所生成的代码注释进行
排序选择, 实现对不同方法的集成. 这种集成方式可以更好地发挥不同方法在生成代码注释方面的优势, 从而更好
地进行代码注释生成.
6 总 结
代码注释生成方法尝试自动化地为源代码生成注释, 这类方法在软件开发和维护过程中具有重要意义. 本文
提出了一种基于语义重排序的代码注释生成方法 SRBCS. 针对现有基于集成的代码注释生成方法, 并不能很好地
利用信息检索技术和深度学习技术在代码注释生成方面能力的问题, 本文从信息检索的视角而非传统的深度学习
视角重新审视了两种技术的集成策略, 并提出通过语义重排序模型对不同方法所生成注释进行排序选择的方式来
实现对不同方法的集成. 大规模的实验评估验证了本文所提出的代码注释生成方法可以有效对不同代码注释生成
方法进行集成, 实现了优于现有 14 种代码注释生成方法的性能.
References
[1] Haiduc S, Aponte J, Marcus A. Supporting program comprehension with source code summarization. In: Proc. of the 32nd ACM/IEEE
Int’l Conf. on Software Engineering. Cape Town: ACM, 2010. 223–226. [doi: 10.1145/1810295.1810335]
[2] Chen X, Yang G, Cui ZQ, Meng GZ, Wang Z. Survey of state-of-the-art automatic code comment generation. Ruan Jian Xue Bao/Journal
of Software, 2021, 32(7): 2118–2141 (in Chinese with English abstract). http://www.jos.org.cn/1000-9825/6258.htm [doi: 10.13328/j.cnki.
jos.006258]
[3] Forward A, Lethbridge TC. The relevance of software documentation, tools and technologies: A survey. In: Proc. of the 2002 ACM
Symp. on Document Engineering. McLean: ACM, 2002. 26–33. [doi: 10.1145/585058.585065]
[4] Eddy BP, Robinson JA, Kraft NA, Carver JC. Evaluating source code summarization techniques: Replication and expansion. In: Proc. of
the 21st Int’l Conf. on Program Comprehension. San Francisco: IEEE, 2013. 13–22. [doi: 10.1109/ICPC.2013.6613829]
[5] Wong E, Liu TY, Tan L. CloCom: Mining existing source code for automatic comment generation. In: Proc. of the 22nd IEEE Int’l Conf.
on Software Analysis, Evolution, and Reengineering. Montreal: IEEE, 2015. 380–389. [doi: 10.1109/SANER.2015.7081848]
[6] Wong E, Yang JQ, Tan L. AutoComment: Mining question and answer sites for automatic comment generation. In: Proc. of the 28th
IEEE/ACM Int’l Conf. on Automated Software Engineering. Silicon Valley: IEEE, 2013. 562–567. [doi: 10.1109/ASE.2013.6693113]
[7] 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]
[8] 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]
[9] 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. Montreal: IEEE, 2019. 795–806. [doi: 10.1109/ICSE.2019.00087]
[10] 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]
[11] 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. 6563–6573.
[12] Gros D, Sezhiyan H, Devanbu P, Yu Z. Code to comment “translation”: Data, metrics, baselining & evaluation. In: Proc. of the 35th

