arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2501.05062cs.SE
收藏

基于深度学习的代码补全:上下文信息对性能的影响

Deep Learning-based Code Completion: On the Impact on Performance of Contextual Information

Matteo Ciniselli, Luca Pascarella, Gabriele Bavota

AI总结:

本文通过实验评估8类编码、过程与开发者上下文及其组合,发现额外上下文可使深度学习代码补全的正确预测相对提升最高22%。

摘要:

代码补全旨在通过向开发者推荐他们接下来可能输入的标记来加快代码编写速度。深度学习(DL)模型通过重新定义这些编码助手的能力,推动了代码补全的边界:我们已经从预测少量代码标记发展到自动生成整个函数。影响基于深度学习的代码补全技术性能的一个重要因素是作为输入提供的上下文。我们所说的“上下文”是指模型对要补全代码的已知信息。在一个简单场景中,可能会向深度学习模型输入一个部分实现的函数以供补全。在这种情况下,上下文由不完整的函数表示,模型必须基于它生成预测。然而,可以扩展这种上下文以纳入额外信息,例如包含待补全函数的整个源代码文件,这可能有助于提升预测性能。在本工作中,我们提出一项实证研究,调查基于深度学习的代码补全技术性能如何受到不同上下文的影响。我们对8种上下文及其组合进行了实验。这些上下文包括:(i) 编码上下文,其特征是从调用代码补全的代码库中提取的信息(例如,与要“补全”的代码组件在结构上相关的代码组件);(ii) 过程上下文,包含旨在描述触发代码补全任务的项目当前状态的信息(例如,与待补全代码相关的未解决问题的文本表示);以及 (iii) 开发者上下文,捕获有关调用代码补全的开发者的信息(例如,经常使用的 API)。我们的结果表明,额外的上下文信息可以提升基于深度学习的代码补全性能,在正确预测方面相对改进最高可达 +22%。

英文摘要:

Code completion aims at speeding up code writing by recommending to developers the next tokens they are likely to type. Deep Learning (DL) models pushed the boundaries of code completion by redefining what these coding assistants can do: We moved from predicting few code tokens to automatically generating entire functions. One important factor impacting the performance of DL-based code completion techniques is the context provided as input. With "context" we refer to what the model knows about the code to complete. In a simple scenario, the DL model might be fed with a partially implemented function to complete. In this case, the context is represented by the incomplete function and, based on it, the model must generate a prediction. It is however possible to expand such a context to include additional information, like the whole source code file containing the function to complete, which could be useful to boost the prediction performance. In this work, we present an empirical study investigating how the performance of a DL-based code completion technique is affected by different contexts. We experiment with 8 types of contexts and their combinations. These contexts include: (i) coding contexts, featuring information extracted from the code base in which the code completion is invoked (e.g., code components structurally related to the one to "complete"); (ii) process context, with information aimed at depicting the current status of the project in which a code completion task is triggered (e.g., a textual representation of open issues relevant for the code to complete); and (iii) developer contexts, capturing information about the developer invoking the code completion (e.g., the APIs frequently used). Our results show that additional contextual information can benefit the performance of DL-based code completion, with relative improvements up to +22% in terms of correct predictions.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑