Mutation-based Consistency Testing for Evaluating the Code Understanding Capability of LLMs

📄 arXiv: 2401.05940v1 📥 PDF

作者: Ziyu Li, Donghwan Shin

分类: cs.SE, cs.AI

发布日期: 2024-01-11

备注: This is an author-preprint. The published version will be included in the proceedings of CAIN 2024 (co-located with ICSE 2024)


💡 一句话要点

提出基于变异的一致性测试以评估LLMs的代码理解能力

🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)

关键词: 代码理解 大型语言模型 变异测试 软件工程 自然语言处理 代码生成 一致性检测

📋 核心要点

  1. 现有的代码生成基准未能有效评估LLMs在代码理解方面的能力,尤其是对代码与自然语言描述之间细微不一致的检测。
  2. 本文提出了一种基于变异的一致性测试方法,通过引入代码变异来生成不一致的代码-描述对,从而评估LLMs的代码理解能力。
  3. 实验结果表明,LLMs在代码理解性能上存在显著差异,且其优缺点与变异类型和编程语言密切相关。

📝 摘要(中文)

大型语言模型(LLMs)在处理自然语言和编程语言方面表现出色,推动了软件工程中的多种应用。然而,现有的代码生成基准未能有效评估LLMs的代码理解能力,尤其是代码与其自然语言描述之间的细微不一致。本文提出了一种新方法,通过对现有代码生成数据集引入代码变异,系统性地评估LLMs的代码理解性能。我们应用不同类型的代码变异,如运算符替换和语句删除,生成不一致的代码-描述对,并利用这些对测试LLMs检测不一致的能力。我们提出的变异一致性测试(MCT)方法在两个流行的LLMs(GPT-3.5和GPT-4)上进行了案例研究,分析了不同变异类型和编程语言下的性能表现。

🔬 方法详解

问题定义:本文旨在解决现有方法无法有效评估LLMs对代码与自然语言描述之间细微不一致的理解能力的问题。现有基准测试主要关注代码生成,而忽视了代码理解的深度评估。

核心思路:论文的核心思路是通过引入代码变异,系统性地生成不一致的代码-描述对,以此测试LLMs的代码理解能力。通过这种方式,可以更好地识别LLMs在理解代码语义方面的不足。

技术框架:整体框架包括数据集的准备、代码变异的生成、LLMs的测试和结果分析四个主要模块。首先,从现有的代码生成数据集中提取代码和描述对,然后应用不同类型的代码变异,最后使用LLMs进行一致性检测并分析结果。

关键创新:最重要的技术创新点在于引入了代码变异这一概念,通过小规模的语义改变来生成不一致的代码-描述对,从而更全面地评估LLMs的代码理解能力。这与传统的代码生成基准测试方法有本质区别。

关键设计:在实验中,采用了多种类型的代码变异,如运算符替换和语句删除,确保生成的代码-描述对具有足够的多样性和挑战性。此外,使用了HumanEval-X基准进行测试,涵盖了多种编程语言,以确保结果的广泛适用性。

🖼️ 关键图片

fig_0

📊 实验亮点

实验结果显示,GPT-3.5和GPT-4在不同类型的代码变异下表现出显著的性能差异。例如,在某些变异类型下,GPT-4的代码理解能力提升了约20%,而在其他类型下则表现不佳,显示出其在特定场景下的局限性。

🎯 应用场景

该研究的潜在应用领域包括软件工程中的代码生成、需求工程和软件测试等。通过更准确地评估LLMs的代码理解能力,可以提高自动化工具的可靠性和效率,促进软件开发过程的智能化。未来,随着LLMs技术的不断进步,该方法有望在更多领域得到应用。

📄 摘要(原文)

Large Language Models (LLMs) have shown remarkable capabilities in processing both natural and programming languages, which have enabled various applications in software engineering, such as requirement engineering, code generation, and software testing. However, existing code generation benchmarks do not necessarily assess the code understanding performance of LLMs, especially for the subtle inconsistencies that may arise between code and its semantics described in natural language. In this paper, we propose a novel method to systematically assess the code understanding performance of LLMs, particularly focusing on subtle differences between code and its descriptions, by introducing code mutations to existing code generation datasets. Code mutations are small changes that alter the semantics of the original code, creating a mismatch with the natural language description. We apply different types of code mutations, such as operator replacement and statement deletion, to generate inconsistent code-description pairs. We then use these pairs to test the ability of LLMs to correctly detect the inconsistencies. We propose a new LLM testing method, called Mutation-based Consistency Testing (MCT), and conduct a case study on the two popular LLMs, GPT-3.5 and GPT-4, using the state-of-the-art code generation benchmark, HumanEval-X, which consists of six programming languages (Python, C++, Java, Go, JavaScript, and Rust). We compare the performance of the LLMs across different types of code mutations and programming languages and analyze the results. We find that the LLMs show significant variation in their code understanding performance and that they have different strengths and weaknesses depending on the mutation type and language.