[论文解读] RepoBench: Benchmarking Repository-Level Code Auto-Completion Systems
RepoBench 引入一个面向代码自动完成的仓库级基准,包含三项任务——检索、代码补全和管线(Pipeline)——在 Python 和 Java 上对多种模型和检索策略进行评估。
Large Language Models (LLMs) have greatly advanced code auto-completion systems, with a potential for substantial productivity enhancements for developers. However, current benchmarks mainly focus on single-file tasks, leaving an assessment gap for more complex, real-world, multi-file programming scenarios. To fill this gap, we introduce RepoBench, a new benchmark specifically designed for evaluating repository-level code auto-completion systems. RepoBench supports both Python and Java and consists of three interconnected evaluation tasks: RepoBench-R (Retrieval), RepoBench-C (Code Completion), and RepoBench-P (Pipeline). Each task respectively measures the system's ability to retrieve the most relevant code snippets from other files as cross-file context, predict the next line of code with cross-file and in-file context, and handle complex tasks that require a combination of both retrieval and next-line prediction. RepoBench aims to facilitate a more complete comparison of performance and encouraging continuous improvement in auto-completion systems. RepoBench is publicly available at https://github.com/Leolty/repobench.
研究动机与目标
- 弥补在对多文件、仓库级代码补全系统进行评估方面的空白,超越单文件基准。
- 提供一个包含三个互相关联任务(检索、代码补全、管线)的基准,以评估端到端工作流。
- 揭示模型在真实仓库中的跨文件和长上下文代码处理能力。
- 促进公平比较并推动仓库级代码智能的改进。
提出的方法
- 从 GitHub 代码(训练集)和新抓取的 GitHub 仓库(测试集)构建数据集,聚焦 Python 和 Java。
- 通过 tree-sitter 解析跨文件依赖,识别跨文件行及相应的定义。
- 定义三项任务:RepoBench-R(检索)、RepoBench-C(代码补全)、RepoBench-P(管线)。
- 通过将跨文件上下文(来自导入)与文件内上下文(前面的行)相结合来创建提示,对于 RepoBench-C 设置 30 行上限。
- 使用 acc@k 进行检索评估,对补全和管线使用 Exact Match(EM)和 Edit Similarity(ES)评估。
- 测试一系列基线方法,包括词法检索、语义检索(CodeBERT、UniXcoder)以及大型语言模型(Codex、CodeGen、StarCoder)在 Python/Java 变体上的表现。
实验结果
研究问题
- RQ1检索策略在多大程度上能够识别相关的跨文件片段以支持下一个代码行的预测?
- RQ2在不同上下文长度(XF-F、XF-R、IF)下,模型使用跨文件与文件内上下文预测下一行代码的有效性如何?
- RQ3将检索与补全结合在管线中时的端到端性能如何,以及跨文件上下文的放置如何影响结果?
- RQ4仓库级基准是否揭示在检索和补全性能上的语言特定差异(Python 与 Java)?
主要发现
| 检索方法 | XF-F EM | XF-F ES | XF-R EM | XF-R ES | IF EM | IF ES | All EM | All ES |
|---|---|---|---|---|---|---|---|---|
| Gold-Only * (Python) | 30.59 | 70.43 | 40.65 | 74.45 | 41.10 | 78.32 | 35.79 | 73.59 |
| Gold-Filled-Head * (Python) | 31.07 | 70.48 | 39.77 | 74.42 | 41.87 | 78.56 | 36.07 | 73.68 |
| Gold-Filled-Tail * (Python) | 31.35 | 70.73 | 40.56 | 74.37 | 41.21 | 78.50 | 36.18 | 73.77 |
| UniXcoder-H2L (Python) | 30.99 | 70.68 | 40.71 | 74.74 | 43.19 | 79.18 | 36.61 | 74.02 |
| UniXcoder-L2H (Python) | 32.12 | 71.36 | 40.59 | 74.48 | 43.07 | 79.22 | 37.11 | 74.32 |
| Random (Python) | 28.06 | 68.95 | 38.75 | 73.81 | 41.16 | 78.34 | 34.15 | 72.72 |
| Baseline (Python) | 26.75 | 68.16 | 37.60 | 73.30 | 40.79 | 78.26 | 33.15 | 72.20 |
| Gold-Only * (Java) | 32.48 | 70.39 | 43.51 | 76.49 | 55.91 | 81.65 | 41.62 | 74.95 |
| Gold-Filled-Head * (Java) | 32.48 | 70.29 | 43.44 | 76.36 | 55.84 | 81.68 | 41.59 | 74.88 |
| Gold-Filled-Tail * (Java) | 32.37 | 70.30 | 43.48 | 76.63 | 55.66 | 81.55 | 41.49 | 74.91 |
| UniXcoder-H2L (Java) | 32.46 | 70.16 | 42.79 | 76.14 | 56.71 | 81.86 | 41.70 | 74.83 |
| UniXcoder-L2H (Java) | 32.69 | 70.33 | 43.08 | 76.21 | 56.57 | 81.89 | 41.83 | 74.93 |
| Random (Java) | 31.34 | 69.81 | 42.08 | 75.73 | 55.94 | 81.67 | 40.77 | 74.51 |
| Baseline (Java) | 30.73 | 69.48 | 41.44 | 75.42 | 56.18 | 81.70 | 40.40 | 74.29 |
- UniXcoder 在 RepoBench-R 中始终优于其他检索方法,表明对跨文件片段具有很强的语义理解。
- 词汇检索(Jaccard)通常在跨文件片段相关性方面优于编辑相似度。
- 在各方法中,Python 检索任务的准确性通常高于 Java。
- 在 RepoBench-P 中,结合跨文件上下文在各设置下提升性能,且有效的检索(例如 UniXcoder)提升检索和补全结果。
- 检索到的片段的顺序/放置会影响代码补全效果,离目标行越近越有利。
更好的研究,从现在开始
从论文设计到论文写作,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。