Skip to main content
QUICK REVIEW

[Paper Review] CodeT: Code Generation with Generated Tests

Bei Chen, Fengji Zhang|arXiv (Cornell University)|Jul 21, 2022
Software Testing and Debugging TechniquesComputer Science64 citations
TL;DR

CodeT automatically generates test cases with the same pre-trained language model used for code generation, then uses a dual execution agreement to select the best code solution from multiple samples, improving pass@1 across several benchmarks and models.

ABSTRACT

The task of generating code solutions for a given programming problem can benefit from the use of pre-trained language models such as Codex, which can produce multiple diverse samples. However, a major challenge for this task is to select the most appropriate solution from the multiple samples generated by the pre-trained language models. A natural way to evaluate the quality and correctness of a code solution is to run it against a set of test cases, but the manual creation of such test cases is often costly and time-consuming. In this paper, we propose a novel method, CodeT, that leverages the same pre-trained language models to automatically generate test cases for the code samples, thus reducing the human effort and increasing the coverage of the test scenarios. CodeT then executes the code samples using the generated test cases, and performs a dual execution agreement, which considers both the consistency of the outputs against the generated test cases and the agreement of the outputs with other code samples. We conduct comprehensive experiments on four benchmarks, HumanEval, MBPP, APPS and CodeContests, using five different pre-trained language models with varying sizes and capabilities. Our results show that CodeT can significantly improve the performance of code solution selection over previous methods, achieving remarkable and consistent gains across different models and benchmarks. For instance, CodeT improves the pass@1 metric on HumanEval to 65.8%, which represents an absolute improvement of 18.8% over the code-davinci-002 model, and an absolute improvement of more than 20% over the previous state-of-the-art results.

Motivation & Objective

  • Reduce reliance on manually crafted test cases by generating test cases automatically with the same LM used for code generation.
  • Improve code solution selection from multiple samples via execution-based consensus grounded in generated tests.
  • Increase robustness and coverage of evaluation by leveraging dual agreement between test outcomes and cross-solution consistency.
  • Demonstrate effectiveness across multiple benchmarks and model families in zero-shot settings.

Proposed method

  • Generate test cases for each programming problem by prompting the same pre-trained LM used for code generation to output input-output pairs.
  • Generate a large set of code solutions X from the problem context using the LM, without requiring labelled data.
  • Apply a dual execution agreement inspired by RANSAC to find consensus sets of (code, test) pairs that pass common test cases and agree with each other.
  • Rank consensus sets by f(S) = |Sx| * |Sy| and select the best code solution from the top consensus set.
  • Optionally, de-duplicate solutions and compare performance with and without deduplication (ablation shows little effect).
  • Evaluate using pass@k on multiple benchmarks and LM families, with zero-shot settings, using generated test cases rather than ground-truth-labelled data.

Experimental results

Research questions

  • RQ1How good are LM-generated test cases in quality and coverage for driving code selection?
  • RQ2Does dual execution agreement improve the selection of correct solutions across different models and benchmarks?
  • RQ3How does CodeT perform in zero-shot settings across diverse benchmarks and model sizes?
  • RQ4How sensitive is CodeT to the number of generated test cases and to test-case quality (toxicity, accuracy, coverage)?

Key findings

  • CodeT significantly improves pass@1 across benchmarks and models, e.g., with code-davinci-002 on HumanEval: 47.0% (baseline) to 65.8% (CodeT).
  • On MBPP with code-davinci-002, pass@1 improves from 58.1% to 67.7%.
  • For APPS Introductory, pass@1 improves from 27.2% to 34.6% with CodeT.
  • On CodeContests, pass@1 improves from 0.7% to 2.1% with CodeT (zero-shot).
  • CodeT achieves consistent gains across Codex, InCoder, and CodeGen families, and outperforms AlphaCode-C in all reported settings.
  • Test-case quality (accuracy, toxicity, coverage) correlates with CodeT gains; higher-quality test cases (e.g., from code-davinci-002) yield larger improvements.

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.