一句话:提出基于 Transformer 的多任务预训练语言模型,联合预测下一个 token 及其类型以提升代码补全性能。
代码补全是 IDE 中最实用的功能之一,可基于上下文实时建议下一个可能的 token。已有基于统计语言模型的方法虽能从大规模代码库中学习,但存在两个问题:一是使用静态词嵌入,同一 token 在不同上下文中共享同一向量,丢失了语义差异;二是这些模型在补全标识符时表现较差,且大多忽略了标识符的类型信息。本文提出一个面向代码理解与代码生成的预训练语言模型,采用 Transformer 架构,使用融合代码理解与代码生成任务的混合目标函数进行预训练,再在代码补全任务上微调。补全时模型并不直接预测下一个 token,而是通过多任务学习联合预测 token 及其类型,并利用预测出的类型辅助 token 预测。在两个真实数据集上的实验结果表明,该模型优于当时的最先进方法。
Code completion is one of the most useful features in the Integrated Development Environments (IDEs), which can accelerate software development by suggesting the next probable token based on the contextual code in real-time. Recent studies have shown that statistical language modeling techniques can improve the performance of code completion tools through learning from large-scale software repositories. However, these models suffer from two major drawbacks: a) Existing research uses static embeddings, which map a word to the same vector regardless of its context. The differences in the meaning of a token in varying contexts are lost when each token is associated with a single representation; b) Existing language model based code completion models perform poor on completing identifiers, and the type information of the identifiers is ignored in most of these models. To address these challenges, in this paper, we develop a multi-task learning based pre-trained language model for code understanding and code generation with a Transformer-based neural architecture. We pre-train it with hybrid objective functions that incorporate both code understanding and code generation tasks. Then we fine-tune the pre-trained model on code completion. During the completion, our model does not directly predict the next token. Instead, we adopt multi-task learning to predict the token and its type jointly and utilize the predicted type to assist the token prediction. Experiments results on two real-world datasets demonstrate the effectiveness of our model when compared with state-of-the-art methods.
DOI 原文 ·
@inproceedings{paperbot5885,
title = {Multi-task learning based pre-trained language model for code completion},
author = {Fang Liu and Ge Li and Yunfei Zhao and Zhi Jin},
booktitle = {ASE},
year = {2020},
doi = {10.1145/3324884.3416591}
}