[论文解读] ClassEval: A Manually-Crafted Benchmark for Evaluating LLMs on Class-level Code Generation
本文提出 ClassEval,这是一个手工构建的用于类级代码生成的100任务 Python 基准,并在三种生成策略下分析了11个最先进的 LLM,揭示了函数级与类级性能之间的显著差距以及模型特定策略。
In this work, we make the first attempt to evaluate LLMs in a more challenging code generation scenario, i.e. class-level code generation. We first manually construct the first class-level code generation benchmark ClassEval of 100 class-level Python code generation tasks with approximately 500 person-hours. Based on it, we then perform the first study of 11 state-of-the-art LLMs on class-level code generation. Based on our results, we have the following main findings. First, we find that all existing LLMs show much worse performance on class-level code generation compared to on standalone method-level code generation benchmarks like HumanEval; and the method-level coding ability cannot equivalently reflect the class-level coding ability among LLMs. Second, we find that GPT-4 and GPT-3.5 still exhibit dominate superior than other LLMs on class-level code generation, and the second-tier models includes Instruct-Starcoder, Instruct-Codegen, and Wizardcoder with very similar performance. Third, we find that generating the entire class all at once (i.e. holistic generation strategy) is the best generation strategy only for GPT-4 and GPT-3.5, while method-by-method generation (i.e. incremental and compositional) is better strategies for the other models with limited ability of understanding long instructions and utilizing the middle information. Lastly, we find the limited model ability of generating method-dependent code and discuss the frequent error types in generated classes. Our benchmark is available at https://github.com/FudanSELab/ClassEval.
研究动机与目标
- 创建一个具有挑战性的、手工构建的用于类级 Python 代码生成的基准,以评估 LLM 在生成相互依赖的类方法方面的能力。
- 通过专门的单元测试套件验证生成类的正确性,确保高覆盖率/充足的测试。
- 在整体、增量和组合生成策略下评估多样化的 LLM,以理解策略的适用性。
- 分析在生成方法依赖性或上下文丰富的类代码时的错误类型和模型局限性。
提出的方法
- 手工构建的 ClassEval,包含约 412 个方法的 100 个类级 Python 任务,且覆盖率高。
- 围绕契约编程原则设计的类骨架,包括类级导入、构造函数和方法契约。
- 开发两级测试:方法级测试和类级测试,以验证方法之间的交互。
- 创建并经全面测试用例核验的规范解,以确保高质量的基线。
- 对11个 LLMs 在三种生成策略(整体/ holistic、增量、组合)下进行评估,使用 Pass@k 作为正确性度量。
实验结果
研究问题
- RQ1与像 HumanEval 这样的函数级基准相比,LLMs 在类级代码生成上的表现如何?
- RQ2不同生成策略(整体、增量、组合)如何影响 LLM 在类级任务上的表现?
- RQ3LLMs 在多大程度上能够生成依赖同一类中其他上下文的代码?
- RQ4在生成类级代码时的常见错误类型有哪些,以及它们在不同模型间的差异?
主要发现
- 所有 LLM 在类级生成上的表现都不如在独立方法级基准上的表现。
- GPT-4 和 GPT-3.5 的表现优于其他模型,Instruct-StarCoder、Instruct-CodeGen 和 WizardCoder 作为强力但相近的竞争者。
- 整体生成对 GPT-4 和 GPT-3.5 最佳,而增量/组合策略则有利于其他模型,特别是在有限的长指令和中上下文利用能力方面。
- ClassEval 中相当一部分方法依赖字段或其他方法(独立 vs 依赖库/字段/方法)。
- 该基准强调高测试充分性(语句级和分支级覆盖率超过 98%),以可靠验证生成的类正确性。
- ClassEval 记录了常见错误类型,并讨论某些模型在生成依赖方法的代码方面的能力有限。
更好的研究,从现在开始
从论文设计到论文写作,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。