Learning to select examples for program synthesis

Yewen Pu, Zachery Miranda, Armando Solar-Lezama, Leslie Pack KaelblingarXiv 2017

Abstract

Program synthesis often struggles to scale when faced with large datasets of input-output examples due to the massive overhead of encoding them as logical constraints. We present a neural network-based method to greedily select a small, highly representative subset of examples that maximally prunes the program search space. This approach significantly speeds up and stabilizes constraint-based synthesis solvers by providing a high-quality initial constraint set, effectively bypassing the volatility of standard Counter-Example Guided Inductive Synthesis (CEGIS).

1. Introduction

Program synthesis is the task of automatically generating source code that exactly maps a set of inputs to their corresponding outputs. Because this requires precise, combinatorial logic, it is usually framed as a Constraint Satisfaction Problem (CSP) and solved using SMT solvers like Z3. The core bottleneck is scalability: encoding thousands of input-output examples as constraints consumes prohibitive amounts of memory and time.

Standard approaches like CEGIS iteratively add counter-examples to a small subset. However, CEGIS is often volatile, selecting adversarial examples that leave the solver under-constrained. This pushes the solver into a "phase transition" where problems become exponentially harder. We address this by intelligently selecting a tiny, representative subset of examples that perfectly represents the entire dataset.

2. Methodology

We frame example selection as a greedy algorithm aimed at maximally pruning the search space of invalid programs.

2.1 Neural Approximation of Pruning Power

Ideally, one would use a "count oracle" to select examples that invalidate the most incorrect programs. As counting is intractable, we prove that under a uniform prior, the probability of an example being correct given a subset is inversely proportional to its pruning power. We train a neural network to predict this "anticipation probability" and greedily add the most "surprising" (least probable) examples.

2.2 Scaling with Committee Networks

To scale to large datasets, we utilize a "Committee Network." Instead of processing the entire subset, the network uses a domain-specific neighborhood function to identify the top-$k$ most relevant examples already in the subset. These act as a committee to predict the output of new candidate examples.

A sampled subset of 40 pixels used as constraints for the drawing synthesis task.

3. Experimental Evaluation

We evaluate our approach on three tasks: Ordering Synthesis, DFA Synthesis, and Programmatic Drawing Synthesis.

3.1 Programmatic Drawing Synthesis

In this task, the goal is to synthesize a drawing program (using a Domain Specific Language with loops and conditionals) to reproduce a 32x32 pixel target image. Each of the 1,024 pixels acts as an individual input-output constraint.

The programmatic drawing synthesis task involves generating code (left) to reproduce a target image (right).

4. Results and Discussion

Our approach demonstrated significant improvements in both speed and stability across all benchmarks:

  • Representativeness: In Ordering Synthesis, the algorithm discovered fully representative subsets 85% of the time, using only approximately twice the size of the mathematically optimal subset.
  • Efficiency: In Drawing Synthesis, the method achieved the stability of using the full 1,024-pixel dataset while only encoding roughly 15% of the pixels, drastically reducing computational overhead.
  • Stability: The neural approach matched highly-tuned domain heuristics in DFA synthesis and vastly outperformed standard CEGIS, which frequently failed or hung due to under-constrained subsets.

5. Conclusion

By linking probabilistic prediction to logical constraint power, we provide a robust mechanism for example selection in program synthesis. While currently dependent on domain-specific neighborhood functions, this approach offers a powerful "warm-start" for existing solvers, combining neural approximation with symbolic guarantees of correctness.

Summary updated

BibTeX
@misc{pu2017learning,
  author = {Yewen Pu and Zachery Miranda and Armando Solar-Lezama and Leslie Pack Kaelbling},
  title = {{Learning to select examples for program synthesis}},
  year = {2017},
  eprint = {1711.03243},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1711.03243},
}
Figure