[论文解读] CrossCodeEval: A Diverse and Multilingual Benchmark for Cross-File Code Completion
CrossCodeEval 引入一个跨文件、面向多语言的代码完成基准,覆盖 Python、Java、TypeScript 和 C#,通过静态分析要求跨文件上下文。它在文件内、检索以及带参考的检索提示下评估 CodeGen、StarCoder 与 GPT-3.5-Turbo,强调跨文件上下文对代码语言模型的重要性与挑战。
Code completion models have made significant progress in recent years, yet current popular evaluation datasets, such as HumanEval and MBPP, predominantly focus on code completion tasks within a single file. This over-simplified setting falls short of representing the real-world software development scenario where repositories span multiple files with numerous cross-file dependencies, and accessing and understanding cross-file context is often required to complete the code correctly. To fill in this gap, we propose CrossCodeEval, a diverse and multilingual code completion benchmark that necessitates an in-depth cross-file contextual understanding to complete the code accurately. CrossCodeEval is built on a diverse set of real-world, open-sourced, permissively-licensed repositories in four popular programming languages: Python, Java, TypeScript, and C#. To create examples that strictly require cross-file context for accurate completion, we propose a straightforward yet efficient static-analysis-based approach to pinpoint the use of cross-file context within the current file. Extensive experiments on state-of-the-art code language models like CodeGen and StarCoder demonstrate that CrossCodeEval is extremely challenging when the relevant cross-file context is absent, and we see clear improvements when adding these context into the prompt. However, despite such improvements, the pinnacle of performance remains notably unattained even with the highest-performing model, indicating that CrossCodeEval is also capable of assessing model's capability in leveraging extensive context to make better code completion. Finally, we benchmarked various methods in retrieving cross-file context, and show that CrossCodeEval can also be used to measure the capability of code retrievers.
研究动机与目标
- 激发在现实软件仓库中评估具有跨文件上下文的代码补全的必要性。
- 从真实开源仓库创建 CrossCodeEval,具严格的跨文件完成要求。
- 确保与训练数据的重叠最小化,以避免记忆效应干扰。
- 提供一个基准,也能评估跨文件上下文检索能力。
提出的方法
- 从四种语言中许可较宽松的 GitHub 仓库构建跨文件代码完成数据集。
- 使用静态分析自动识别跨文件上下文依赖,以生成需要跨文件上下文的提示。
- 对数据进行后处理和筛选,以保证质量并降低泄漏风险,包括一个基于检索的验证步骤。
- 在零样本设置下评估多种代码语言模型(CodeGen 多个尺寸、StarCoder、GPT-3.5-Turbo),使用文件内、检索以及带参考的检索提示。
- 使用两种度量:代码匹配(严格匹配和编辑相似度)和标识符匹配(EM 和 F1)来评估性能。
实验结果
研究问题
- RQ1跨文件上下文是否提升主要编程语言的代码完成性能?
- RQ2基于检索的方法与文件内上下文相比,在跨文件代码完成中的表现如何?
- RQ3使用带参考的跨文件上下文进行检索时,性能的上限是怎样的?
- RQ4在本基准中,不同检索器(BM25、神经检索器)在跨文件代码检索任务中的表现如何?
- RQ5CrossCodeEval 能否作为代码检索质量和策略的基准?
主要发现
- 仅使用文件内上下文时,模型表现较差,显示出对跨文件上下文的需求。
- 增加跨文件上下文在各语言和模型上带来显著的性能提升。
- 带跨文件上下文的检索在某些模型和语言上将严格代码匹配提升至约 3 倍左右,使用带参考的检索可带来进一步提升,显示出上限效应。
- 即使有检索的跨文件上下文,性能仍未接近完美,表明在利用广泛的仓库级上下文方面仍有改进空间。
- 检索方法质量对结果有显著影响,OpenAI ada 向量在某些语言中常常优于稀疏的 BM25;然而,即使是最好的检索器也未达到理想的上界,表明需要更好的跨文件检索技术。
阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。