NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

From Words to Code: Harnessing Data for Program Synthesis from Natural Language

Anirudh Khatry, Joyce Cahoon, Jordan Henkel, Shaleen Deep, K. Venkatesh Emani, Avrilia Floratou, Sumit Gulwani, Vu Le, Mohammad Raza, Sherry Shi, Mukul Singh, Ashish TiwariarXiv 2023 · DOI

Abstract

Large Language Models (LLMs) have demonstrated remarkable capabilities in generating code from natural language descriptions. However, in the domain of data manipulation, these models often produce syntactically plausible but semantically incorrect programs. This paper presents a framework that leverages the execution of candidate programs on actual data to perform semantic reranking. By filtering and prioritizing programs based on their outputs, the proposed method achieves significant improvements in top-1 accuracy across SQL, Pandas, and Power Query M, with gains of up to 45% in low-resource programming languages.

Introduction

The challenge of program synthesis from natural language (NL) lies in bridging the gap between ambiguous human intent and precise executable code. While state-of-the-art LLMs like GPT-4 excel at generating code, they are prone to "hallucinations"—generating code that fails to execute or produces incorrect results. Traditional approaches incorporate data context (e.g., table schemas) during the prompting phase but neglect the rich information available in the execution output of generated candidates. This work addresses this gap by introducing a post-processing pipeline that uses execution results to verify and rank candidate programs.

The Semantic Reranking Pipeline

The core of the proposed approach is a multi-stage pipeline designed to move beyond simple probability-based ranking of code tokens.

The multi-stage pipeline for semantic reranking of LLM-generated code.

The pipeline consists of four primary components:

  1. Temperature Mixing: To balance stability and diversity, the system combines samples generated at temperature 0 (high probability) with those at temperature 0.6 (high diversity).
  2. Semantic Filtering: Every candidate program is executed against the target dataset. Programs that result in runtime errors are immediately pruned from the candidate set.
  3. Semantic Interleaving: Recognizing that different code structures can produce identical outputs, the system groups candidates by their execution results. It then interleaves these groups to ensure the top-K results presented to the user are semantically diverse.
  4. Output-Prediction based Score Tuning: For languages where the LLM has lower confidence (like Power Query M), the model is tasked with predicting the expected output data for a given NL query. Candidate programs whose execution results match this predicted output receive a score boost.

Experimental Setup

The framework was evaluated across three distinct domains:

  • SQL: Benchmarked using the standard Spider and KaggleDBQA datasets.
  • Data Science (Pandas): Evaluated on the Jigsaw dataset.
  • Business Intelligence (Power Query M): Tested on three new benchmarks: Forum (scraped from help sites), Product (real-world Microsoft benchmarks), and JigsawM (a Pandas-to-M adaptation).

Results and Discussion

The implementation of semantic reranking led to substantial performance improvements. In the Power Query M domain, specifically on the JigsawM benchmark, top-1 accuracy increased by an absolute 45%. For SQL tasks on the Spider benchmark, the system achieved 76% top-1 accuracy, setting a new state-of-the-art.

Example of natural language query to Power Query M code synthesis with candidate filtering.

A key insight from this work is that execution serves as the ultimate arbiter of truth in data tasks. By prioritizing diversity over raw token probability, semantic interleaving ensures that the top results represent distinct logical interpretations of the user's query. Furthermore, the "alternative task" strategy—predicting data transformations rather than just code—provides a powerful cross-verification mechanism for low-resource languages.

Conclusion and Future Work

While highly effective, the reliance on code execution introduces challenges regarding safety and latency. Executing arbitrary code in general-purpose languages like Python requires robust sandboxing to prevent side effects. Additionally, the computational overhead of executing multiple candidates and predicting outputs must be optimized for real-time applications. Future research will explore non-execution-based clustering and the extension of these techniques to non-data-centric programming domains.

Summary updated

BibTeX
@misc{khatry2023from,
  author = {Anirudh Khatry and Joyce Cahoon and Jordan Henkel and Shaleen Deep and K. Venkatesh Emani and Avrilia Floratou and Sumit Gulwani and Vu Le and Mohammad Raza and Sherry Shi and Mukul Singh and Ashish Tiwari},
  title = {{From Words to Code: Harnessing Data for Program Synthesis from Natural Language}},
  year = {2023},
  eprint = {2305.01598},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2305.01598},
}
Figure