DeCon:通过大语言模型生成的后置条件检测错误断言
DeCon: Detecting Incorrect Assertions via Postconditions Generated by a Large Language Model
AI总结:
本文提出 DeCon 方法,利用大语言模型生成的后置条件并结合少量 I/O 示例过滤,以检测大语言模型生成的错误断言,实验表明其检测率超过 64%,并将代码生成 Pass@1 提升 4%。
摘要:
近年来,给定目标问题的文档字符串和目标函数签名,大语言模型(LLMs)不仅被用于生成源代码,还被用于生成测试用例,包括测试输入和断言(例如,以检查实际输出与期望输出是否一致的形式)。然而,正如我们对四个大语言模型为 HumanEval 基准生成的断言所进行的实证研究所显示的那样,超过 62% 的生成断言是错误的(即在真实问题解上失败)。为了检测错误断言(给定文档字符串、目标函数签名以及示例输入输出样本),本文提出了一种名为 DeCon 的新方法,通过大语言模型为目标问题生成的后置条件来有效检测错误断言(后置条件是在真实问题解执行之后必须始终为真的谓词)。我们的方法需要目标问题的一小组 I/O 示例(即示例输入输出样本)(例如,HumanEval 中目标问题文档字符串里包含的 I/O 示例)。我们使用给定的 I/O 示例来过滤掉那些至少被一个给定 I/O 示例违反的大语言模型生成的后置条件。然后,我们使用剩余的后置条件来检测错误断言,即那些违反至少一个剩余后置条件的断言。实验结果表明,DeCon 平均能够检测出四个最先进大语言模型生成的错误断言中超过 64% 的部分(GPT-3.5 和 GPT-4 分别检测出 63% 和 65.5%),并且 DeCon 还能在 Pass@1 指标上将这些大语言模型的代码生成有效性提高 4%。此外,尽管 DeCon 可能会过滤掉正确的断言,但剩余正确断言的故障发现能力仅略有下降。
英文摘要:
Recently, given the docstring for the target problem and the target function signature, large language models (LLMs) have been used not only to generate source code, but also to generate test cases, consisting of test inputs and assertions (e.g., in the form of checking an actual output against the expected output). However, as shown by our empirical study on assertions generated by four LLMs for the HumanEval benchmark, over 62% of the generated assertions are incorrect (i.e., failed on the ground-truth problem solution). To detect incorrect assertions (given the docstring and the target function signature along with a sample of example inputs and outputs), in this paper, we propose a new approach named DeCon to effectively detect incorrect assertions via LLM-generated postconditions for the target problem (a postcondition is a predicate that must always be true just after the execution of the ground-truth problem solution). Our approach requires a small set of I/O examples (i.e., a sample of example inputs and outputs) for the target problem (e.g., the I/O examples included in the docstring for a target problem in HumanEval). We use the given I/O examples to filter out those LLM-generated postconditions that are violated by at least one given I/O example. We then use the remaining postconditions to detect incorrect assertions as those assertions that violate at least one remaining postcondition. Experimental results show that DeCon can detect averagely more than 64% (63% and 65.5% detected by GPT-3.5 and GPT-4, respectively) incorrect assertions generated by four state-of-the-art LLMs, and DeCon can also improve the effectiveness of these LLMs in code generation by 4% in terms of Pass@1. In addition, although DeCon might filter out correct assertions, the fault-finding ability of the remaining correct assertions decreases only slightly.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。