Skip to main content
QUICK REVIEW

[Paper Review] Testing LLMs on Code Generation with Varying Levels of Prompt Specificity

Lincoln Murr, Morgan Grainger|arXiv (Cornell University)|Nov 10, 2023
Software Engineering ResearchComputer Science6 citations
TL;DR

This study evaluates how prompt specificity—especially including test cases—affects code generation performance in LLMs like GPT-3.5, GPT-4, Claude-2, and Bard on 104 Python coding problems. Results show that test-inclusive prompts significantly improve accuracy and reliability, with GPT-4 and GPT-3.5 outperforming others, highlighting the value of test-driven prompting for robust code generation.

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.

Motivation & Objective

  • To evaluate the impact of varying prompt specificity—especially inclusion of test cases—on LLM-generated Python code quality.
  • To compare the performance of leading LLMs (Bard, ChatGPT-3.5, ChatGPT-4, Claude-2) across different prompting strategies.
  • To assess whether test-driven prompts enhance accuracy, time efficiency, and space efficiency in code generation.
  • To establish an optimal prompting strategy for generating correct and efficient Python functions using LLMs.
  • To provide empirical evidence for integrating test cases into prompts to improve reliability in AI-assisted software development.

Proposed method

  • A benchmark of 104 diverse Python coding problems was constructed, each with four distinct prompt types varying in specificity and test inclusion.
  • Four prompt types were used: (1) problem description only, (2) problem with input/output examples, (3) problem with test cases only, and (4) problem with both examples and test cases.
  • LLMs were prompted with each problem and prompt type, and generated code was evaluated for correctness, time efficiency, and space efficiency.
  • Code correctness was validated using automated test execution, while efficiency metrics were measured via runtime and memory usage analysis.
  • Performance was compared across models and prompt types using statistical analysis to identify significant differences in accuracy and efficiency.
  • The study employed a controlled experimental design with standardized evaluation criteria to ensure reproducibility and reliability of results.

Experimental results

Research questions

  • RQ1How does including test cases in prompts affect the accuracy of code generated by LLMs?
  • RQ2What is the relative performance of GPT-3.5, GPT-4, Claude-2, and Bard in generating correct Python functions across varying prompt types?
  • RQ3Does increased prompt specificity—through examples or test cases—improve time and space efficiency of generated code?
  • RQ4How do LLMs perform when faced with ambiguous or masked function names in prompts?
  • RQ5To what extent can test-driven prompts guide LLMs to produce functionally correct and robust code?

Key findings

  • Including test cases in prompts significantly improves code generation accuracy across all evaluated LLMs, with GPT-4 achieving the highest correctness rate.
  • GPT-3.5 and GPT-4 demonstrated robust performance across all prompt types, showing strong adaptability to varying levels of specificity.
  • Claude-2 performed well only with highly specific prompts, indicating it benefits from explicit instructions and struggles with ambiguity.
  • The outdated Text-davinci-002 model significantly underperformed compared to newer models, confirming rapid advancements in LLM architecture.
  • Masked function names reduced model performance, indicating difficulty in reasoning under ambiguity and highlighting a key limitation in LLM generalization.
  • Test-enabled prompts led to more reliable and functionally correct code, supporting the integration of TDD principles in LLM-based development workflows.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.