摘要
通过生成源代码片段的简短自然语言描述,可帮助开发人员理解代码并减少文档工作.近期,关于代码摘要的研究工作主要采用深度学习模型,这些模型中的大多数都在由独立代码摘要对组成的大型数据集上进行训练.尽管取得了良好的效果,这些工作普遍忽略了代码片段和摘要的项目级上下文信息,而开发人员在编写文档时往往高度依赖这些信息.针对该问题,研究了一种与开发者行为和代码摘要工具实现更加一致的代码摘要场景——项目级代码摘要,其中,创建了用于项目特定代码摘要的数据集,该数据集包含800k方法摘要对及其生命周期信息,用于构建特定时刻准确的项目项目上下文;提出了一种新颖的深度学习方法,利用高度相关的代码片段及其相应的摘要来表征上下文语义,并通过迁移学习整合从大规模跨项目数据集中学到的常识.实验结果表明:基于项目级上下文的代码摘要模型不仅能够比通用代码摘要模型获得显著的性能提升,同时,针对特定项目能够生成更一致的摘要.
Code summarization generates brief natural language descriptions of source code pieces,which can assist developers to understand code and reduce documentation workload.Recent research efforts on code summarization mainly adopt deep learning models.Most of these models are trained on large datasets,consisting of independent code-summary pairs.Despite the technical advances,most of these works,referred as general code summarization models,ignore the project-level contextual information of code pieces and summaries,which developers would heavily rely on when writing documentation.This study investigates project-specific code summarization,a scenario that is much more consistent with human behavior and tool implementation of code summarization.Specifically,a novel deep learning approach is proposed that leverages highly relevant code pieces and their corresponding summaries to characterize contextual semantics,and integrates common knowledge learned from large-scale cross-project dataset via transfer learning.The dataset is created and released for project-specific code summarization,consisting of 800k method-summary pairs along with their lifecycle information for re-producing accurate code context.Experimental results on this dataset demonstrate that the proposed technique can not only gain huge improvement over general code summarization model,but also generates more consistent summaries within a project.
作者
胡天翔
谢睿
叶蔚
张世琨
HU Tian-Xiang;XIE Rui;YE Wei;ZHANG Shi-Kun(National Enginering Rearch Center for Software Enginering,Peking University,Beijing 100871,China)
出处
《软件学报》
EI
CSCD
北大核心
2023年第4期1695-1710,共16页
Journal of Software
基金
中国博士后科学基金(2021M700216)。
关键词
代码摘要
项目上下文
迁移学习
code summarization
contextual information
transfer learning