ThrowBench: Benchmarking LLMs by Predicting Runtime Exceptions
作者: Julian Aron Prenner, Romain Robbes
分类: cs.SE, cs.LG
发布日期: 2025-03-06
💡 一句话要点
提出ThrowBench基准测试,用于评估LLM预测运行时异常的能力
🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)
关键词: 大型语言模型 代码理解 运行时异常 基准测试 代码LLM
📋 核心要点
- 现有代码LLM基准测试主要关注从自然语言指令合成代码,忽略了其他形式的代码理解能力评估。
- ThrowBench通过要求LLM预测程序运行时是否会抛出异常及其类型,来评估LLM对代码运行时行为的理解。
- 实验结果表明,现有代码LLM在ThrowBench上的表现有限,表明其在运行时异常预测方面存在不足。
📝 摘要(中文)
本文提出ThrowBench,一个用于评估大型语言模型(LLM)预测运行时程序行为能力的基准测试。该基准包含超过2400个由用户编写的、使用四种不同编程语言编写的短程序。这些程序中的大多数在运行时会抛出异常(由于错误)。LLM需要预测给定的程序是否会抛出异常,如果会,则预测是哪种异常。在六个最先进的代码LLM上评估ThrowBench,结果显示性能适中,F1分数在19%到38%之间。更广泛地评估代码能力可以改进对代码LLM的评估,并帮助识别当前模型的弱点。此外,由于ground-truth答案是通过程序执行确定的,因此无需担心数据泄露。ThrowBench以及所有结果都将随本文一起发布。
🔬 方法详解
问题定义:现有代码LLM的评估基准主要集中在代码生成能力上,缺乏对代码理解,特别是运行时行为理解的有效评估。此外,现有基准存在数据泄露的风险,即测试数据可能出现在训练集中,导致评估结果偏差。因此,需要一个能够有效评估LLM对代码运行时行为理解能力,且不存在数据泄露风险的基准测试。
核心思路:ThrowBench的核心思路是通过让LLM预测程序在运行时是否会抛出异常以及异常类型,来评估其对代码运行时行为的理解能力。这种方法避免了代码生成任务,直接考察LLM对代码语义和潜在错误的理解。由于ground-truth是通过实际执行程序获得的,因此可以有效避免数据泄露问题。
技术框架:ThrowBench包含超过2400个短程序,使用Python、Java、JavaScript和C#四种编程语言编写。每个程序都设计为在运行时可能抛出异常。LLM的任务是接收程序代码作为输入,并预测程序是否会抛出异常,如果会,则预测异常的类型。评估指标主要采用F1分数,用于衡量预测的准确性和召回率。
关键创新:ThrowBench的关键创新在于其评估目标:运行时异常预测。与传统的代码生成基准不同,ThrowBench侧重于评估LLM对代码语义和潜在错误的理解能力。此外,通过程序执行获取ground-truth,有效避免了数据泄露问题,保证了评估的公平性和可靠性。
关键设计:ThrowBench中的程序设计力求简洁明了,突出可能导致运行时异常的代码片段。程序长度适中,避免了因代码过于复杂而影响LLM的预测。四种编程语言的选择覆盖了广泛的应用领域,增加了基准的通用性。评估指标采用F1分数,综合考虑了预测的准确性和召回率,能够更全面地反映LLM的性能。
🖼️ 关键图片
📊 实验亮点
在六个最先进的代码LLM上评估ThrowBench,结果显示F1分数在19%到38%之间。这表明现有代码LLM在运行时异常预测方面表现有限,仍有很大的提升空间。该基准的发布为研究人员提供了一个新的评估工具,可以更有效地评估和改进代码LLM的性能。
🎯 应用场景
ThrowBench可用于评估和改进代码LLM的性能,特别是在代码理解和错误预测方面。通过识别LLM在运行时异常预测方面的弱点,可以指导模型训练和架构设计,提高LLM在软件开发、代码审查和自动调试等领域的应用能力。此外,该基准可以促进对代码LLM的更全面评估,推动相关研究的发展。
📄 摘要(原文)
Modern Large Language Models (LLMs) have shown astounding capabilities of code understanding and synthesis. In order to assess such capabilities, several benchmarks have been devised (e.g., HumanEval). However, most benchmarks focus on code synthesis from natural language instructions. Hence, such benchmarks do not test for other forms of code understanding. Moreover, there have been concerns about contamination and leakage. That is, benchmark problems (or closely related problems) may appear in training set, strongly biasing benchmark results. In this work we investigate whether large language models can correctly predict runtime program behavior. To this end, we introduce ThrowBench, a benchmark consisting of over 2,400 short user-written programs written in four different programming languages. The majority of these programs throw an exception during runtime (due to a bug). LLMs are asked to predict whether a presented program throws an exception and, if so, which one. Evaluating our benchmark on six state-of-the-art code LLMs we see modest performance ranging from 19 to 38% (F1 score). Benchmarking a wider set of code capabilities could improve the assessment of code LLMs and help identify weak points in current models. Moreover, as ground-truth answers have been determined through program execution, leakage is not a concern. We release ThrowBench as well as all of our results together with this work.