Skip to main content
QUICK REVIEW

[Paper Review] From Words to Code: Harnessing Data for Program Synthesis from Natural Language

Anirudh Khatry, Joyce Cahoon|arXiv (Cornell University)|May 2, 2023
Software Engineering ResearchComputer Science6 citations
TL;DR

This paper proposes a novel program synthesis framework that enhances code generation from natural language by leveraging data context through execution-based semantic reranking and temperature mixing. By executing candidate programs on input data and re-ranking them using output-based signals—semantic filtering, interleaving, and score tuning—it achieves up to 45% top-1 accuracy gains and 34% top-3 accuracy improvements across SQL, Pandas, and Power Query M benchmarks using only in-context learning with GPT-4 and Codex.

ABSTRACT

Creating programs to correctly manipulate data is a difficult task, as the underlying programming languages and APIs can be challenging to learn for many users who are not skilled programmers. Large language models (LLMs) demonstrate remarkable potential for generating code from natural language, but in the data manipulation domain, apart from the natural language (NL) description of the intended task, we also have the dataset on which the task is to be performed, or the "data context". Existing approaches have utilized data context in a limited way by simply adding relevant information from the input data into the prompts sent to the LLM. In this work, we utilize the available input data to execute the candidate programs generated by the LLMs and gather their outputs. We introduce semantic reranking, a technique to rerank the programs generated by LLMs based on three signals coming the program outputs: (a) semantic filtering and well-formedness based score tuning: do programs even generate well-formed outputs, (b) semantic interleaving: how do the outputs from different candidates compare to each other, and (c) output-based score tuning: how do the outputs compare to outputs predicted for the same task. We provide theoretical justification for semantic interleaving. We also introduce temperature mixing, where we combine samples generated by LLMs using both high and low temperatures. We extensively evaluate our approach in three domains, namely databases (SQL), data science (Pandas) and business intelligence (Excel's Power Query M) on a variety of new and existing benchmarks. We observe substantial gains across domains, with improvements of up to 45% in top-1 accuracy and 34% in top-3 accuracy.

Motivation & Objective

  • Address the challenge of low accuracy in natural language to code generation for data manipulation tasks, where existing methods underutilize input data context.
  • Overcome the limitation of relying solely on prompt engineering by incorporating actual program execution outputs for better candidate ranking.
  • Improve top-K accuracy in program synthesis by introducing a data-aware reranking mechanism that leverages program outputs and semantic similarity.
  • Enable high-accuracy code generation without requiring fine-tuning or user-provided test cases, relying only on natural language descriptions and input data.
  • Provide theoretical justification for semantic interleaving and introduce practical techniques like temperature mixing to enhance diversity and quality of LLM-generated candidates.

Proposed method

  • Generate multiple candidate programs (top-N) from an LLM using a mix of high and low temperature sampling to increase diversity.
  • Execute each candidate on a sample of the input dataset to collect actual outputs, filtering out syntactically invalid or non-executable programs (semantic filtering).
  • Apply semantic reranking using three signals: (a) well-formedness and semantic filtering to discard malformed outputs, (b) semantic interleaving to cluster and reorder candidates based on output similarity, and (c) output-based score tuning using predicted outputs from the LLM.
  • Use temperature mixing to combine samples from different temperature settings, improving the likelihood of capturing high-quality candidates.
  • Re-rank candidates using a composite score that integrates log probabilities, execution success, and output similarity to prioritize correct programs.
  • Introduce a novel output-prediction-based score tuning technique that aligns generated program outputs with LLM-predicted outputs for improved ranking.

Experimental results

Research questions

  • RQ1Can leveraging actual program execution outputs from input data significantly improve the accuracy of NL-to-code synthesis compared to relying only on prompt engineering?
  • RQ2How effective is semantic interleaving in re-ranking candidate programs based on output similarity, and can it be theoretically justified?
  • RQ3To what extent does temperature mixing enhance the diversity and quality of LLM-generated candidates in program synthesis tasks?
  • RQ4Can output-based score tuning improve ranking performance by aligning generated outputs with LLM-predicted outputs?
  • RQ5Does the proposed framework achieve state-of-the-art performance across diverse data manipulation domains (SQL, Pandas, Power Query M) without requiring fine-tuning or user-provided test cases?

Key findings

  • The proposed framework achieves up to 45% improvement in top-1 accuracy and 34% improvement in top-3 accuracy across databases, data science, and business intelligence tasks.
  • Using the Codex model, the approach reaches 76% top-1 execution accuracy, surpassing state-of-the-art methods through prompt engineering and execution feedback alone.
  • Semantic reranking with execution feedback significantly outperforms standard logprob-based ranking, especially in reducing the rank of incorrect or malformed programs.
  • Temperature mixing increases candidate diversity and improves the likelihood of including the correct program in the top-N set, contributing to higher top-K accuracy.
  • Theoretical justification is provided for semantic interleaving, showing that clustering and reordering candidates by output similarity enhances ranking performance.
  • The method achieves strong results without requiring user-provided test cases or model fine-tuning, relying only on natural language descriptions and input data samples.

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.