Neural Program Synthesis with Query

Di Huang, Rui Zhang, Xing Hu, Xishan Zhang, Pengwei Jin, Nan Li, Zidong Du, Qi Guo, Yunji Chen

TL;DR

This paper introduces a query-based framework for neural program synthesis that moves away from the unrealistic assumption that users can provide "perfect" input-output examples. By training a query network to maximize mutual information in a novel "Functional Space" (F-space), the system interactively generates highly informative examples that can distinguish between candidate programs as effectively as—or even better than—expert-designed specifications.

What Problem Does This Paper Address?

Program synthesis—the task of automatically generating code that satisfies a user's intent—has seen significant progress using neural networks. However, most existing models rely on "privileged information": they assume the user provides a small set of perfectly crafted input-output (I/O) examples that cover all logical branches of the target program.

In the real world, this is a huge hurdle. Most users aren't expert programmers and don't know which edge cases are needed to disambiguate one program from another. If the provided examples are poor, the synthesizer's performance plummets. The authors tackle this "informativeness gap" by asking: Can we build a system that proactively asks the user for the right information?

Methods

The authors propose a framework consisting of two decoupled parts: a Query Network and a Synthesis Network.

The proposed query-based framework for program synthesis.
  1. The Query Network: Instead of waiting for examples, this network generates an input $x$, asks an "oracle" (the user or a simulator) for the output $y$, and repeats this iteratively to narrow down the possible programs.
  2. Functional Space (F-space): To make this process differentiable and optimizable, the authors map programs into a latent "Functional Space." In F-space, a program is represented as a vector, and a set of I/O examples is represented as a Normal distribution. As more queries are answered, the distribution "shrinks," representing a reduction in uncertainty.
  3. Information Gain via InfoNCE: The query network is trained to maximize the Mutual Information between the queries and the target program. They use the InfoNCE loss (a common tool in contrastive learning) to ensure that the generated queries help the model distinguish the "positive" (correct) program from "negative" (incorrect) candidates.
  4. Recurrent Training: To avoid "greedy" behavior (where the model only thinks about the immediate next query), they use a recurrent training process. This allows the gradient to propagate through multiple query steps, encouraging the model to plan a sequence of questions that efficiently identifies the program.
Recurrent training process using InfoNCE loss across multiple query steps.

Datasets

The framework was evaluated on two classic program synthesis benchmarks:

  • Karel: A DSL for a robot moving in a 2D grid world. This task is challenging because it involves complex control flow like loops and conditionals.
  • List Processing: A task (similar to DeepCoder) where programs manipulate lists of integers using functions like MAP, FILTER, and SORT. The authors tested two versions: D1 (program length 4) and D2 (program length up to 12).

Key Insights and Ideas

  • Programs as Points, Specifications as Volumes: The most elegant idea here is treating a set of I/O examples as a distribution in F-space. A single example might be satisfied by many programs, but the intersection of multiple examples (the product of their distributions) focuses on a specific region of the functional space.
  • Decoupling Query from Synthesis: Because the query network is a separate module, it acts as a "plug-and-play" component. You can theoretically attach this query network to any existing neural synthesizer without retraining the synthesizer itself.
  • Beyond Greedy Search: The authors found that simply picking the "best" next query often leads to local minima. Their recurrent training approach proves that "looking ahead" is vital for efficient information gathering.

Key Results

The query-based framework proved that machines can be better at "asking" than humans are at "telling":

  • Outperforming Experts: On the Karel task, the query-based examples achieved an Exact Match rate of 41.12%, virtually identical to the 41.16% achieved by "well-designed" expert examples, and far higher than random selection (29.44%).
  • List Processing Success: In the list processing task (D1), the query method actually outperformed well-designed examples (81.56% vs 81.21% exact match).
  • Efficiency: The model reached high accuracy with very few queries. The authors demonstrated that the entropy of the program distribution drops sharply after just a few interactions, showing the queries are highly surgical.

Limitations and Future Work

  • The Oracle Assumption: The framework requires a deterministic oracle that can provide an output for any given input. While this works for simulators or "black-box" programs, it might be taxing for a human user to manually compute complex outputs for a long sequence of queries.
  • Scalability to Long Programs: Like most synthesis models, performance drops as the target program grows longer (as seen in the D2 list processing results). The search space for programs grows exponentially, and even the best queries can only do so much if the underlying synthesizer struggles.
  • F-space Dimensionality: The F-space is a neural approximation. Exploring how to represent more complex, higher-dimensional program behaviors (like those in general-purpose languages like Python) remains an open challenge.

Summary updated

BibTeX
@inproceedings{huang2022neural,
  author = {Di Huang and Rui Zhang and Xing Hu and Xishan Zhang and Pengwei Jin and Nan Li and Zidong Du and Qi Guo and Yunji Chen},
  title = {{Neural Program Synthesis with Query}},
  booktitle = {International Conference on Learning Representations},
  year = {2022},
  url = {https://openreview.net/forum?id=uLGLID-uMp},
}
Figure