Skip to main content
QUICK REVIEW

[Paper Review] Interactive Code Generation via Test-Driven User-Intent Formalization

Shuvendu K. Lahiri, Fakhoury, Sarah|arXiv (Cornell University)|Aug 11, 2022
Software Engineering ResearchComputer Science24 citations
TL;DR

The paper proposes Interactive Test-Driven Code Generation (ITDCG) implemented as TiCoder, which uses lightweight user feedback via generated tests to formalize intent and prune/rank code suggestions, improving pass@k metrics on MBPP and HumanEval.

ABSTRACT

Large language models (LLMs) have shown great potential in automating significant aspects of coding by producing natural code from informal natural language (NL) intent. However, when interacting with LLMs, users have no guarantees that the code suggestions produced correctly satisfy the intent they provided. In fact, it is hard to define a notion of correctness since natural language can be ambiguous and lacks a formal semantics. In this paper, we propose the workflow of {\it interactive test-driven code generation}, which leverages lightweight user feedback to (a) formalize the user intent using generated tests that can be useful for debugging, and (b) produce an improved set of code suggestions by pruning and ranking candidate code suggestions. We describe a language-agnostic abstract algorithm and a concrete implementation TiCoder. We perform an automated evaluation of TiCoder on the \emph{MBPP} and \emph{HumanEval} code generation benchmarks. Our results are promising with using the OpenAI Codex LLM: our best algorithm improves the \passk{1} code generation accuracy (in absolute percentages) between $22.49\%$ to $37.71\%$ for MBPP and between $24.79\%$ to $53.98\%$ for HumanEval using between 1 to 5 simulated user queries.

Motivation & Objective

  • Formalize user intent for code generation via generated tests that serve as lightweight, runnable specifications
  • Prune and rank LLM-generated code suggestions using runtime feedback from user-considered tests
  • Provide a language-agnostic, abstract ITDCG algorithm and a concrete implementation (TiCoder)
  • Evaluate ITDCG on Python datasets MBPP and HumanEval with Codex as the underlying LLM
  • Demonstrate contributions of interaction, prompts, mutation, and ranking over a purely LLM-based baseline

Proposed method

  • Describe an abstract InteractiveTestDrivenCodeGen algorithm parameterized by components for pruning, mutating, and ranking tests
  • Implement TiCoder with CodePrompt and TestPrompt to generate code and tests from a problem description
  • Use syntactic and dynamic mutation (SyntacticMutateTests and DynMutateTests) to expand test sets
  • Rank tests (RankTests) to select queries that maximize pruning impact, and prune or keep code candidates accordingly
  • Rank code suggestions (RankCodes) by how many tests they satisfy (passing-tests)
  • Evaluate using pass@k@m and accept@{m} metrics, with m representing user queries
  • Use an oracle (reference implementation) to simulate user responses for offline evaluation

Experimental results

Research questions

  • RQ1How does the interactive workflow improve the accuracy of code suggestions (pass@k@m) compared to baselines?
  • RQ2How does the correctness of generated code and tests improve with the number of simulated user queries?
  • RQ3What is the impact of design choices (prompts, mutation, ranking) on the overall effectiveness of ITDCG?

Key findings

  • TiCoder achieves pass@1@1 of 70.73% on MBPP and 55.28% on HumanEval with one user query, outperforming Codex baseline and several baselines.
  • With five user queries, TiCoder attains pass@1@1 of 70.73% (MBPP) and 55.28% (HumanEval) in the reported configurations, and can reach near IdealRanking performance.
  • TiCoder consistently outperforms Baseline and Codex without interaction across k in {2,5,10} for both MBPP and HumanEval.
  • Using the oracle-based evaluation, TiCoder approaches IdealRanking with increased user queries, indicating substantial benefit from test-driven disambiguation.
  • The default TiCoder configuration (TestGenPrompt = pass, StaticMutateTests = single-assert, DynMutateTests = assert-rewrite-all, TestRanking = discriminative, CodeRanking = passing-tests) was chosen for strong pass@1@1 performance.
  • An average of 1.7 user queries suffices to generate a unit test consistent with user intent for 87.12% of MBPP and 95.73% of HumanEval examples.

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.