Skip to main content
QUICK REVIEW

[论文解读] CodeMind: Evaluating Large Language Models for Code Reasoning

Changshu Liu, Chen, Yang|arXiv (Cornell University)|Feb 15, 2024
Software Engineering ResearchComputer Science被引用 3
一句话总结

CodeMind 是一个框架,用于在三种代码推理任务上评估大型语言模型(LLMs)——独立执行推理(IER)、依赖执行推理(DER)和规范推理(SR)——以评估其在测试通过之外的代码执行和规范推理能力。研究发现,尽管 LLMs 在简单程序和其能合成的代码上表现良好,但随着复杂度、非基本类型和 API 调用的增加,其推理能力显著下降,且规范推理并不能推断出执行推理能力。

ABSTRACT

Large Language Models (LLMs) have been widely used to automate programming tasks. Their capabilities have been evaluated by assessing the quality of generated code through tests or proofs. The extent to which they can reason about code is a critical question revealing important insights about their true capabilities. This paper introduces CodeMind, a framework designed to gauge the code reasoning abilities of LLMs through the following explicit and implicit code reasoning tasks: Independent Execution Reasoning (IER), Specification Reasoning (SR) and Dynamic Semantics Reasoning (DSR). The first evaluates the abilities of LLMs to simulate the execution of given inputs to a code and predict the output (IER). The second assesses the abilities of LLMs to incorporate the simulation of test data in the specification into code generation (SR). Finally, CodeMind evaluates LLMs' abilities to understand overall code semantics only given a specific input/output (DSR). Our extensive evaluation of ten LLMs across four widely used benchmarks using CodeMind shows that LLMs, depending on their size and training strategy, can reason about some dynamic aspects of code. However, their performance drops for code with higher complexity, non-trivial logical and arithmetic operators, non-primitive types, and API calls. We show that these reasoning tasks evaluate LLMs differently, and a comprehensive evaluation of code reasoning requires them all. Finally, we show that the performance of LLMs in bug repair is not correlated with any of the code reasoning tasks, and except for advanced frontier models, other LLMs do not incorporate code reasoning when performing bug repair.

研究动机与目标

  • 为解决现有代码合成 LLM 评估中仅依赖测试通过的局限性,该局限可能掩盖数据泄露或推理缺陷。
  • 开发一个衡量深层代码推理能力的框架,包括执行可追溯性和规范符合性。
  • 探究 LLM 是否能在不依赖自然语言规范或测试数据的情况下进行代码执行推理。
  • 在多样化编程基准上比较通用型与代码专用型 LLM 的推理表现。
  • 识别与控制流、运算符、数据类型和 API 使用相关的推理失败模式。

提出的方法

  • 提出 CodeMind,一个包含三项核心任务的框架:IER(对任意代码执行进行推理)、DER(对模型自身生成的代码进行推理)和 SR(对指定的输入-输出行为进行推理)。
  • 设计提示词,以从 LLM 中激发分步的思维链推理,确保推理过程中不依赖测试数据。
  • 在五个基准数据集(HumanEval、MBPP、CRUXEval、CodeNet 和 Avatar)的 5,395 个程序上评估九个 LLM(包括 GPT-3.5、CodeLlama、StarCoder 和 MagicCoder)。
  • 使用扎根理论分析识别推理中的失败模式,重点关注控制流、算术/逻辑运算符、数据类型和 API 调用。
  • 对输出类型(如 Int、List、Tuple、Decimal)进行分类,并测量类型匹配(Type Match)和值匹配(Value Match)以评估推理准确性。
  • 对失败案例进行人工分析,以理解根本原因,如错误理解条件分支或按位运算符。
Figure 1 : An example illustrating the importance of evaluating LLMs on code reasoning
Figure 1 : An example illustrating the importance of evaluating LLMs on code reasoning

实验结果

研究问题

  • RQ1LLMs 在无测试数据或自然语言参考的情况下,能在多大程度上推理任意代码的执行过程?
  • RQ2LLMs 在推理其自身生成的代码与未生成的代码时,推理表现有何差异?
  • RQ3LLMs 的测试通过性能与执行推理能力之间是否存在强相关性?
  • RQ4复杂控制结构、非基本类型和 API 调用如何影响 LLM 推理的准确性?
  • RQ5LLM 推理的主要失败模式是什么,例如错误理解条件语句或按位运算符?

主要发现

  • LLMs 在简单程序和其正确生成的代码上表现出强大的推理能力,但随着代码复杂度的增加,性能显著下降。
  • 基于测试通过性能的模型排名与执行推理性能之间几乎不存在相关性,表明测试通过性是推理能力的弱代理指标。
  • LLMs 在条件结构上存在困难,常错误理解分支或错误评估谓词,尤其在嵌套或复杂条件中。
  • 按位运算符(如 &、|、<<、>>)比算术或比较运算符更容易出错,即使模型理解了单个运算符的语义。
  • LLMs 的类型匹配(Type Match)表现良好(>80%),但对复杂类型(如 List 和 Tuple)的值匹配(Value Match)显著偏低,原因在于难以追踪多元素数据流。
  • 对 API 调用(如 min()、next())的推理是主要瓶颈,尽管模型可能正确理解基本运算符,但仍常错误理解其行为。
CodeMind: Evaluating Large Language Models for Code Reasoning

阅读本论文

在 Nubint 阅读器中打开原文,边读边就任意段落提问。

在 Nubint 中阅读本论文

本解读由 AI 根据论文原文生成,引用前请核对原文。