Skip to main content
QUICK REVIEW

[论文解读] Testing LLMs on Code Generation with Varying Levels of Prompt Specificity

Lincoln Murr, Morgan Grainger|arXiv (Cornell University)|Nov 10, 2023
Software Engineering Research被引用 6
一句话总结

本研究评估了提示具体性——尤其是包含测试用例——对 GPT-3.5、GPT-4、Claude-2 和 Bard 等 LLM 在 104 个 Python 编程问题上的代码生成性能的影响。结果表明,包含测试用例的提示显著提升了准确率和可靠性,其中 GPT-4 和 GPT-3.5 表现优于其他模型,凸显了测试驱动提示在实现稳健代码生成中的价值。

ABSTRACT

Large language models (LLMs) have demonstrated unparalleled prowess in mimicking human-like text generation and processing. Among the myriad of applications that benefit from LLMs, automated code generation is increasingly promising. The potential to transform natural language prompts into executable code promises a major shift in software development practices and paves the way for significant reductions in manual coding efforts and the likelihood of human-induced errors. This paper reports the results of a study that evaluates the performance of various LLMs, such as Bard, ChatGPT-3.5, ChatGPT-4, and Claude-2, in generating Python for coding problems. We focus on how levels of prompt specificity impact the accuracy, time efficiency, and space efficiency of the generated code. A benchmark of 104 coding problems, each with four types of prompts with varying degrees of tests and specificity, was employed to examine these aspects comprehensively. Our results indicate significant variations in performance across different LLMs and prompt types, and its key contribution is to reveal the ideal prompting strategy for creating accurate Python functions. This study lays the groundwork for further research in LLM capabilities and suggests practical implications for utilizing LLMs in automated code generation tasks and test-driven development.

研究动机与目标

  • 评估不同提示具体性(尤其是测试用例的包含)对 LLM 生成的 Python 代码质量的影响。
  • 比较主流 LLM(Bard、ChatGPT-3.5、ChatGPT-4、Claude-2)在不同提示策略下的性能表现。
  • 评估测试驱动提示是否能提升代码生成的准确率、时间效率和空间效率。
  • 建立一种最优的提示策略,以利用 LLM 生成正确且高效的 Python 函数。
  • 为在 AI 辅助软件开发中整合测试用例以提升可靠性提供实证依据。

提出的方法

  • 构建了一个包含 104 个多样化 Python 编程问题的基准测试集,每个问题均采用四种不同具体性与测试包含程度的提示类型。
  • 使用了四种提示类型:(1) 仅问题描述,(2) 包含输入/输出示例的问题,(3) 仅包含测试用例的问题,以及 (4) 同时包含示例和测试用例的问题。
  • 将每个问题与四种提示类型分别输入 LLM,评估生成代码的正确性、时间效率和空间效率。
  • 通过自动化测试执行验证代码正确性,时间与空间效率指标则通过运行时和内存使用分析测量。
  • 通过统计分析比较不同模型和提示类型之间的性能,识别在准确率和效率方面是否存在显著差异。
  • 本研究采用受控实验设计,使用标准化评估标准,以确保结果的可重现性与可靠性。

实验结果

研究问题

  • RQ1在提示中包含测试用例如何影响 LLM 生成代码的准确率?
  • RQ2GPT-3.5、GPT-4、Claude-2 和 Bard 在不同提示类型下生成正确 Python 函数的相对性能如何?
  • RQ3通过示例或测试用例提升提示具体性,是否能改善生成代码的时间与空间效率?
  • RQ4当提示中出现模糊或被遮蔽的函数名称时,LLM 的表现如何?
  • RQ5测试驱动提示在多大程度上能引导 LLM 生成功能正确且稳健的代码?

主要发现

  • 在提示中包含测试用例显著提升了所有评估 LLM 的代码生成准确率,其中 GPT-4 达到最高的正确率。
  • GPT-3.5 和 GPT-4 在所有提示类型下均表现出色,显示出对不同具体性水平的强大适应能力。
  • Claude-2 仅在高度具体化的提示下表现良好,表明其受益于明确指令,在面对模糊信息时表现欠佳。
  • 过时的 Text-davinci-002 模型显著落后于新型模型,证实了 LLM 架构的快速演进。
  • 遮蔽函数名称会降低模型性能,表明其在模糊情境下推理能力受限,凸显了 LLM 泛化能力的一项关键局限。
  • 启用测试的提示生成了更可靠且功能正确的代码,支持在基于 LLM 的开发工作流中整合 TDD 原则。

更好的研究,从现在开始

从阅读论文到最终审阅,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。