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

Program synthesis using natural language

Aditya Desai, Sumit Gulwani, Vineet Hingorani, Nidhi Jain, Amey Karkare, Mark Marron, Sailesh R, Subhajit Roy

TL;DR

This paper introduces a general "meta-synthesis" framework for building Natural Language to Domain-Specific Language (NL-to-DSL) synthesizers. By combining a bottom-up program generation algorithm with a novel machine-learning-based ranking system, the framework accurately translates ambiguous English instructions into executable code across multiple domains, achieving over 80% top-1 accuracy.

What Problem Does This Paper Address?

End-users frequently struggle to automate repetitive tasks because they lack the programming expertise to use Domain-Specific Languages (DSLs) like Excel formulas, regex, or SQL. While Programming by Example (PBE) systems (like Excel's Flash Fill) have made great strides, they fall short when tasks involve conditional logic (e.g., filter or reduce operations) or large contexts like entire text documents.

Natural Language (NL) is a highly intuitive alternative for specifying these complex, conditional tasks. However, NL is inherently imprecise and ambiguous. Previous NL-to-code systems were usually hardcoded for a single, specific domain (like smartphone automation or spreadsheet formulas) and required immense manual NLP engineering. The authors tackle the challenge of creating a general framework: a system that takes a DSL definition and a set of training examples, and automatically generates a highly accurate NL-to-DSL synthesizer for that specific language.

Methods

The framework operates in two main phases: training and synthesis.

1. The Synthesis Algorithm: When a user inputs an English sentence, the system translates it using a two-step process:

  • The Bag Algorithm: The system uses a learned dictionary to map English words to DSL terminals (functions or values). It then exhaustively generates all well-typed, consistent partial and complete programs from these terminals in a bottom-up manner.
  • Ranking: Because the Bag algorithm generates many spurious programs, the system ranks them using a weighted combination of three scores:
  • Coverage Score: Prefers programs that utilize a higher fraction of the words provided in the user's prompt.
  • Mapping Score: Uses a Naive Bayes classifier based on Part-of-Speech (POS) tags to determine the probability that a specific English word was correctly mapped to a specific DSL terminal.
  • Structure Score: Evaluates the "naturalness" of the program by comparing the Abstract Syntax Tree (AST) of the generated code to the natural language parse tree of the English sentence (looking at word order, distance, and hierarchy).

2. The Training Phase: To make the ranking work, the system must learn the optimal weights for combining the three scores. Because ranking discrete programs creates a discontinuous step-function (which breaks standard optimization techniques), the authors introduce a novel, globally continuous, and differentiable loss function. This smooths out the discrete max operations, allowing them to use standard stochastic gradient descent to learn the optimal scoring weights.

Datasets

The authors evaluated their framework across three distinct domains, compiling a corpus of 1,272 English-to-DSL training pairs:

  • Air Travel Information System (ATIS): 535 queries from a standard NLP benchmark for querying flight databases.
  • Automata Theory Tutoring: 245 descriptions of finite state automata (e.g., "strings with an even number of 0s") scraped from textbooks and online courses, mapped to a custom grading DSL.
  • Repetitive Text Editing: 492 descriptions of text manipulation tasks (e.g., "Remove the first word of lines which start with a number"). 265 were gathered via a user study, and 227 came from an independent corpus.

Key Insights and Ideas

  • Language and Code Share Structure: The Structure Score is the secret sauce of this system. The authors realized that the grammatical parse tree of a natural language sentence often mirrors the Abstract Syntax Tree of the intended program. Aligning these structures drastically filters out syntactically valid but logically incorrect programs.
  • Domain-Agnostic Learning: The weights learned for combining the Coverage, Mapping, and Structure scores are surprisingly universal. The authors found that weights trained on the ATIS database domain performed exceptionally well when applied directly to the Text Editing domain (with a maximum accuracy drop of only 5%).
  • Smoothing Discrete Math for ML: By using a log-exponential approximation of the max function, the authors successfully bridged the gap between discrete program synthesis outputs and continuous machine learning optimization, allowing standard gradient descent to tune the synthesizer.

Key Results

  • High Accuracy: Across all three domains, the synthesizer ranked the correct program as the #1 result for over 80% of the queries (88.4% for ATIS, 84.9% for Automata, 82.3% for Text Editing).
  • Top-3 Reliability: The correct program appeared in the top 3 results over 90% of the time across all domains.
  • Speed: The synthesis and ranking process is fast enough for real-time interactive use, averaging between 0.68 and 1.72 seconds per query.
  • Ablation Importance: Dropping the Structure Score caused the system's accuracy to plummet by up to 81.9%, proving that simply matching keywords (Coverage/Mapping) is vastly insufficient for program synthesis.

Limitations and Future Work

  • Implicit Context: The system struggles when users leave key information implicit. For example, if a user says "fly to Chicago on August 15," the system might fail because it doesn't explicitly know to set the departure city to the user's current location.
  • Abstraction Mismatch: The framework requires the target DSL to have a level of abstraction that roughly matches natural language. It cannot perform deep logical reasoning to bridge massive semantic gaps (e.g., translating an English description directly into a raw, complex Regular Expression).
  • Future Work: The authors suggest building specialized support for handling implicit contextual information and further generalizing the framework to support an even wider variety of target domains without requiring DSL modifications.

Summary updated

BibTeX
@inproceedings{desai2016program,
  author = {Aditya Desai and Sumit Gulwani and Vineet Hingorani and Nidhi Jain and Amey Karkare and Mark Marron and Sailesh R and Subhajit Roy},
  title = {{Program synthesis using natural language}},
  booktitle = {ICSE},
  year = {2016},
  doi = {10.1145/2884781.2884786},
}
Figure