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.
代码完成是一种流行的软件开发工具,集成到所有主要的IDE中。许多神经语言模型在合成基准上的完成建议预测中取得了令人满意的结果。然而,最近的一项研究When Code Completion Fails:a Case Study on Real-World Completions表明,这些结果可能不会转化为现实世界性能的改善。为了对抗这种影响,我们在真实世界的代码完成示例上训练模型,发现这些模型的准确率分别比在提交的源代码和工作版本快照上训练的模型高出12.8%和13.8%。我们在建模技术中观察到这种改进,并通过A/B测试表明,它对应于程序员实际自动完成使用量增加6.2%。此外,我们的研究还描述了一个大型的自动补全使用记录语料库,以研究为什么在真实世界的例子上训练会导致更强大的模型。
Dataflow-Guided Retrieval Augmentation for Repository-Level Code Completion
Nanjing University(南京大学);State Key Laboratory for Novel Software Technology, Nanjing University(南京大学计算机软件新技术国家重点实验室);National Institute of Healthcare Data Science, Nanjing University(南京大学国家卫生数据科学研究院)
在本文中,我们提出了一种新的端到端的AI辅助代码完成方法,称为Pythia。它生成方法和API建议的排名列表,可供软件开发人员在编辑时使用。该系统目前部署为Visual Studio Code IDE中Intellicode扩展的一部分。Pythia利用了最先进的大规模深度学习模型,这些模型是在从抽象语法树中提取的代码上下文上训练的。它被设计为在高吞吐量下工作,预测100个$ms$数量级的最佳匹配代码完成。我们描述了该系统的架构,执行比较基于频率的方法和基于调用的马尔可夫链语言模型,并讨论了轻量级客户端设备上的Pythia模型服务的挑战。在2700个Python开源软件GitHub存储库上获得的离线评估结果显示,对于项目内和跨项目设置,前5名的准确率为92%,超过基线模型20%。
Don't Complete It! Preventing Unhelpful Code Completion for Productive and Sustainable Neural Code Completion Systems
Singapore Management University(新加坡管理大学);Monash University(莫纳什大学);Key Laboratory of System Software (Chinese Academy of Sciences)(中国科学院系统软件重点实验室);State Key Laboratory of Computer Science(计算机科学国家重点实验室);Institute of Software, Chinese Academy of Sciences(中国科学院软件研究所);University of Chinese Academy of Sciences(中国科学院大学);Nanjing Institute of Software Technology(南京软件技术学院);National University of Defense Technology(国防科技大学);University of Technology Sydney(悉尼科技大学);Beihang University(北京航空航天大学)
CodeFill: Multi-token Code Completion by Jointly Learning from Structure and Naming Sequences
Delft University of Technology(代尔夫特理工大学)
代码完成是IDE的一个基本功能,但当前的自动完成器仅限于基于语法或基于NLP的单个标记完成。这两种方法都有明显的缺点:基于语法的自动完成在动态类型语言环境中受到限制,而基于NLP的自动完成程序很难理解程序设计语言的语义和开发人员的代码上下文。在这项工作中,我们提出了CodeFill,一个语言模型自动完成,结合了学习的结构和命名信息。使用并行Transformer架构和多任务学习,CodeFill使用源代码标记名称序列及其等效的AST标记类型。独特的是,CodeFill针对单标记和多标记(语句)预测进行了训练,这使其能够学习语法和命名元素之间的长期依赖关系。我们在两个数据集上训练CodeFill,分别由29 M和425 M行代码组成。为了使评估更加真实,我们开发了一种方法来自动推断源代码中的完成点。我们将CodeFill与四个基线和两个最先进的模型GPT-C和TravTrans+进行了比较。CodeFill在单令牌预测方面超过了所有基线(MRR:70.9% vs. 66.2%和67.8%),并且在多令牌预测方面优于最先进的模型(ROUGE-L:63.7% vs. 52.4%和59.2%,n=4个令牌)。我们公开发布我们的源代码和数据集。