Skip to main content
QUICK REVIEW

[论文解读] DeepSumm -- Deep Code Summaries using Neural Transformer Architecture

Vivek Kumar Gupta|arXiv (Cornell University)|Mar 31, 2020
Software Engineering Research参考文献 16被引用 4
一句话总结

本文提出 DeepSumm,一种基于神经网络 Transformer 的 Java 源代码自动摘要模型,用自注意力机制替代循环结构。在包含 210 万个代码-注释对的测试集上,其 BLEU 得分为 17.99,训练时间相比基于 RNN 的模型减少 50% 以上,同时在速度和性能上均优于基线模型。

ABSTRACT

Source code summarizing is a task of writing short, natural language descriptions of source code behavior during run time. Such summaries are extremely useful for software development and maintenance but are expensive to manually author,hence it is done for small fraction of the code that is produced and is often ignored. Automatic code documentation can possibly solve this at a low cost. This is thus an emerging research field with further applications to program comprehension, and software maintenance. Traditional methods often relied on cognitive models that were built in the form of templates and by heuristics and had varying degree of adoption by the developer community. But with recent advancements, end to end data-driven approaches based on neural techniques have largely overtaken the traditional techniques. Much of the current landscape employs neural translation based architectures with recurrence and attention which is resource and time intensive training procedure. In this paper, we employ neural techniques to solve the task of source code summarizing and specifically compare NMT based techniques to more simplified and appealing Transformer architecture on a dataset of Java methods and comments. We bring forth an argument to dispense the need of recurrence in the training procedure. To the best of our knowledge, transformer based models have not been used for the task before. With supervised samples of more than 2.1m comments and code, we reduce the training time by more than 50% and achieve the BLEU score of 17.99 for the test set of examples.

研究动机与目标

  • 解决软件开发中人工代码文档成本高、覆盖范围低的问题。
  • 改进传统模板化和启发式方法在灵活性与可扩展性方面的不足。
  • 评估 Transformer 架构在代码摘要任务中的有效性——此前该架构尚未在该任务中测试过——并与成熟的基于 RNN 的序列到序列模型进行对比。
  • 在不牺牲摘要质量的前提下,减少训练时间并提升推理效率。
  • 探索自注意力机制在捕捉代码序列中长距离依赖关系方面,相较于循环结构是否更具优势。

提出的方法

  • 采用序列到序列的 Transformer 架构,包含多头自注意力和前馈网络,完全摒弃循环单元。
  • 在大规模 210 万个 Java 方法-注释对数据集上进行训练,将代码和注释分词为子词单元。
  • 使用标准的 Transformer 编码器-解码器结构,采用学习得到的位置嵌入,取代编码器和解码器中的 RNN。
  • 在解码过程中使用交叉注意力机制,对齐源代码标记与目标摘要中的词语。
  • 应用标签平滑和 Adam 优化,采用固定学习率,由于计算资源限制,仅训练 5 个周期。
  • 使用 BLEU 得分评估性能,并通过分析注意力分布来解释模型在样本输入上的行为。

实验结果

研究问题

  • RQ1基于 Transformer 的架构是否能在 BLEU 得分和训练效率两方面均优于基于 RNN 的序列到序列模型?
  • RQ2在模型架构中消除循环结构是否能实现更快的训练速度,且不显著降低摘要质量?
  • RQ3Transformer 模型中的注意力分布如何反映代码标记与摘要词语之间的对齐关系?
  • RQ4与最先进方法相比,模型中缺乏代码结构或语法组成信息在多大程度上影响了性能?
  • RQ5更简单的非循环架构是否能在显著减少训练时间的前提下,实现具有竞争力的代码摘要结果?

主要发现

  • 基于 Transformer 的 DeepSumm 模型在测试集上达到 17.99 的 BLEU 得分,比基于 RNN 的基线模型高出超过 1 个 BLEU 点。
  • 与循环模型相比,训练时间减少了 50% 以上,证明了自注意力机制在效率上的优势。
  • 模型成功为简单方法生成有意义的摘要,例如为 getter 方法生成 "gets the child",且注意力正确对齐到相关标记。
  • 在复杂情况下,如方法名与返回类型不匹配时,模型偶尔会产生错误术语(例如将 "oxygen" 误生成为 "water"),表明其在语义理解方面仍存在局限。
  • 模型性能受限于较短的训练周期(仅 5 个周期)以及缺乏代码结构表示,表明延长训练时间并改进架构有望进一步提升性能。
  • 尽管未达到最先进水平,但结果证实了 Transformer 在代码摘要任务中的可行性与优势,尤其是在训练速度和可扩展性方面。

更好的研究,从现在开始

从阅读论文到最终审阅,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。