Optimal Neural Program Synthesis from Multimodal Specifications

Xi Ye, Qiaochu Chen, Isil Dillig, Greg Durrett

Abstract: Xi Ye, Qiaochu Chen, Isil Dillig, Greg Durrett. Findings of the Association for Computational Linguistics: EMNLP 2021.

2021.

Introduction

Program synthesis—the task of automatically generating code from a specification—is a long-standing challenge in AI. The primary difficulty lies in the "fuzzy" nature of user intent. Natural language (NL) is expressive but inherently ambiguous, while input-output (I/O) examples are precise but often underspecified, as many different programs can satisfy a small set of examples.

Existing multimodal approaches that combine NL and I/O examples often struggle with efficiency. Many rely on heuristic beam searches that do not guarantee finding the most probable program according to the model. Furthermore, these methods frequently fail to prune the search space early, wasting computation on partial programs that are destined to fail I/O constraints. This paper introduces OPSYNTH, a framework that formulates synthesis as an optimal search problem to efficiently find the highest-scoring program satisfying all hard constraints.

The OPSYNTH Framework

OPSYNTH integrates neural modeling with formal program analysis to navigate the search space effectively. The framework is built upon three key pillars:

Overview of the OPSYNTH framework, combining a tree-based model for scoring and a program analyzer for pruning during top-down search.

1. Optimal Synthesis Formulation

Rather than finding any satisfying program, OPSYNTH aims to find the program $P$ that satisfies I/O constraints $\phi$ while maximizing the conditional probability $P(P|NL)$ assigned by a neural model. This ensures the result aligns with the most likely interpretation of the user's natural language description.

2. Tree-Based Neural Model (ASN)

The system utilizes an Abstract Syntax Network (ASN) to construct programs top-down as Abstract Syntax Trees (ASTs). A critical property of this model is its "order-invariant" scoring. The score of a partial program remains consistent regardless of the expansion order, allowing the calculation of a mathematical upper bound on the score of any possible completion.

3. Infeasibility Pruning

To accelerate the search, OPSYNTH employs abstract interpretation to analyze partial programs. By creating over-approximations (potential matches) and under-approximations (definite matches), the system can identify "dead-end" branches early. If a partial program's over-approximation cannot satisfy a positive I/O example, or its under-approximation already matches a negative one, the branch is immediately pruned.

Illustration of infeasibility pruning where a partial program node is identified as having an empty set of possible completions, allowing the search to skip that branch.

The search process uses a best-first strategy with a priority queue. By always expanding the partial program with the highest potential score (the upper bound), the first complete program found that satisfies the I/O examples is guaranteed to be the optimal one.

Evaluation and Results

The authors evaluated OPSYNTH on STRUCTUREDREGEX, a dataset of 3,520 regular expression synthesis tasks with diverse human-written NL descriptions and I/O examples.

  • Accuracy: OPSYNTH solved 60.8% of the benchmarks, significantly outperforming the previous state-of-the-art method (TranX+P at 53.1%).
  • Efficiency: The framework achieved a 3x speedup in search time. By pruning infeasible paths early, OPSYNTH explored an order of magnitude fewer states than baseline neural search methods.
  • Search Quality: Compared to a beam search of size 20, OPSYNTH found the model-optimal program 14% more frequently.

Discussion

The success of OPSYNTH highlights that optimality is a strong proxy for intent; the program the neural model favors most is statistically the one the user intended. Furthermore, the top-down construction of ASTs is crucial for enabling formal feasibility checks, a capability lacking in standard sequence-to-sequence models.

While the current pruning logic is specific to the regular expression domain, the general framework of combining optimal search with formal pruning offers a robust path forward for program synthesis. Future work may involve extending these techniques to more complex general-purpose languages or integrating them with Large Language Models (LLMs) to provide formal verification for generated code.

Summary updated

BibTeX
@inproceedings{ye2021optimal,
  author = {Xi Ye and Qiaochu Chen and Isil Dillig and Greg Durrett},
  title = {{Optimal Neural Program Synthesis from Multimodal Specifications}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2021},
  url = {https://openreview.net/forum?id=t14QF7ulv-C},
}
Figure