(Source) code summarization aims to automatically generate succinct natural language summaries for given code snippets. Such summaries play a significant role in promoting developers to understand and maintain code. Inspired by neural machine translation, deep learning-based code summarization techniques widely adopt an encoder-decoder framework, where the encoder transforms given code snippets into context vectors, and the decoder decodes context vectors into summaries. Recently, large-scale pre-trained models for source code are equipped with encoders capable of producing general context vectors and have achieved substantial improvements on code summarization. However, although they are usually trained mainly on code-focused tasks and can capture general code features, they still fall short in capturing specific features that need to be summarized. This paper proposes a novel approach to improve code summarization based on summary-focused tasks. Specifically, we exploit a multi-task learning paradigm to train the encoder on three summary-focused tasks to enhance its ability to learn code-summary alignment, including unidirectional language modeling (ULM), masked language modeling (MLM), and action word prediction (AWP). Unlike pre-trained models that mainly predict masked tokens in code snippets, we design ULM and MLM to predict masked words in summaries. Intuitively, predicting words based on given code snippets would help learn the code-summary alignment. Additionally, we introduce the domain-specific task AWP to enhance the ability of the encoder to learn the alignment between action words and code snippets. The extensive experiments on four datasets demonstrate that our approach, called ESALE significantly outperforms baselines in all three widely used metrics, including BLEU, METEOR, and ROUGE-L.
翻译:源代码摘要生成旨在为给定代码片段自动生成简洁的自然语言摘要。此类摘要在促进开发者理解和维护代码方面发挥着重要作用。受神经机器翻译启发,基于深度学习的代码摘要技术广泛采用编码器-解码器框架:编码器将给定代码片段转换为上下文向量,解码器则将上下文向量解码为摘要。近年来,面向源代码的大规模预训练模型配备了能够生成通用上下文向量的编码器,在代码摘要任务上取得了显著提升。然而,尽管这些模型主要基于代码中心任务进行训练且能捕捉通用代码特征,但在捕获需要被摘要化的特定特征方面仍存在不足。本文提出一种基于摘要中心任务改进代码摘要的新方法。具体而言,我们采用多任务学习范式,通过三个摘要中心任务训练编码器以增强其学习代码-摘要对齐的能力,包括单向语言建模(ULM)、掩码语言建模(MLM)和动作词预测(AWP)。与主要预测代码片段中掩码标记的预训练模型不同,我们设计的ULM和MLM用于预测摘要中的掩码词汇。直观而言,基于给定代码片段预测词汇有助于学习代码-摘要对齐关系。此外,我们引入领域特定任务AWP以增强编码器学习动作词与代码片段间对齐的能力。在四个数据集上的大量实验表明,我们提出的ESALE方法在BLEU、METEOR和ROUGE-L三项广泛使用的指标上均显著优于基线模型。