arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2406.06864cs.SEcs.AI
收藏

使用变形提示测试验证 LLM 生成的程序

Validating LLM-Generated Programs with Metamorphic Prompt Testing

The University of Texas at San Antonio(德克萨斯大学圣安东尼奥分校)

Xiaoyin Wang, Dakai Zhu

AI总结:

本文提出变形提示测试,通过提示改写生成多版本代码并交叉验证语义一致性,以检测 LLM 程序缺陷;在 HumanEval 上可检出 GPT-4 错误程序的 75%,假阳性率 8.6%。

摘要:

软件开发领域最新的范式转变带来了由大型语言模型(LLM)提供的创新与自动化,其代表是 Generative Pre-trained Transformer(GPT);该模型已展现出自主生成代码的显著能力,可大幅减少各类编程任务所需的人工工作。尽管 LLM 生成代码的潜在收益巨大,尤其是在效率和快速原型构建方面,但随着 LLM 日益融入软件开发生命周期乃至供应链,复杂且多方面的挑战也随之出现,因为这些语言模型生成的代码在质量和正确性方面带来了深刻问题。需要开展研究,以全面探究围绕 LLM 生成代码的这些关键关切。在本文中,我们提出一种名为变形提示测试的新型解决方案来应对这些挑战。我们的直观观察是:正确代码片段之间始终存在内在一致性,而有缺陷的代码片段之间则可能不存在这种一致性,因此可以通过检测不一致性来发现代码中的缺陷。为此,我们可以通过改写将给定提示变换为多个提示,并要求 LLM 获得多个版本的生成代码,从而通过交叉验证来检验所获得代码中的语义关系是否仍然成立。我们在 HumanEval 上的评估表明,变形提示测试能够检测出 GPT-4 生成的错误程序中的 75%,假阳性率为 8.6%。

英文摘要:

The latest paradigm shift in software development brings in the innovation and automation afforded by Large Language Models (LLMs), showcased by Generative Pre-trained Transformer (GPT), which has shown remarkable capacity to generate code autonomously, significantly reducing the manual effort required for various programming tasks. Although, the potential benefits of LLM-generated code are vast, most notably in efficiency and rapid prototyping, as LLMs become increasingly integrated into the software development lifecycle and hence the supply chain, complex and multifaceted challenges arise as the code generated from these language models carry profound questions on quality and correctness. Research is required to comprehensively explore these critical concerns surrounding LLM-generated code. In this paper, we propose a novel solution called metamorphic prompt testing to address these challenges. Our intuitive observation is that intrinsic consistency always exists among correct code pieces but may not exist among flawed code pieces, so we can detect flaws in the code by detecting inconsistencies. Therefore, we can vary a given prompt to multiple prompts with paraphrasing, and to ask the LLM to acquire multiple versions of generated code, so that we can validate whether the semantic relations still hold in the acquired code through cross-validation. Our evaluation on HumanEval shows that metamorphic prompt testing is able to detect 75 percent of the erroneous programs generated by GPT-4, with a false positive rate of 8.6 percent.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑