Efficient Pragmatic Program Synthesis with Informative Specifications

Saujas Vaduguru, Kevin Ellis, Yewen PuarXiv 2022

Abstract

Providing examples is one of the most common way for end-users to interact with program synthesizers. However, program synthesis systems assume that examples consistent with the program are chosen at random, and do not exploit the fact that users choose examples pragmatically. Prior work modeled program synthesis as pragmatic communication, but required an inefficient enumeration of the entire program space. In this paper, we show that it is possible to build a program synthesizer that is both pragmatic and efficient by approximating the joint distribution of programs with a product of independent factors, and performing pragmatic inference on each factor separately. This factored distribution approximates the exact joint distribution well when the examples are given pragmatically, and is compatible with a basic neuro-symbolic program synthesis algorithm. Surprisingly, we find that the synthesizer assuming a factored approximation performs better than a synthesizer assuming an exact joint distribution when evaluated on natural human inputs. This suggests that humans may be assuming a factored distribution while communicating programs.

Introduction

Program synthesis—the automatic generation of code from high-level specifications like input-output pairs—is often hindered by the "Pragmatic-Efficient Dilemma." While humans naturally provide helpful, informative examples to guide a synthesizer, most systems treat these examples as if they were chosen at random. Previous attempts to model this "pragmatic" communication using the Rational Speech Acts (RSA) framework were computationally prohibitive, requiring an exhaustive search of the entire program space. This paper introduces a method to bridge this gap, creating a synthesizer that is both computationally efficient and aligned with human intuition.

Methods: The Mean-Field Approximation

The core innovation is a Mean-Field Approximation that breaks complex programs into independent parts based on the grammar of the Domain-Specific Language (DSL).

  1. Factorization: Instead of treating a program as a single atomic unit, the authors treat each choice in the program's structure (e.g., selecting a specific primitive or loop type) as an independent factor.
  2. Factored RSA: Pragmatic inference is performed on these small factors separately. This turns a massive, exponential search problem into a series of manageable calculations.
  3. Neuro-Symbolic Integration: The model uses a neural network to predict the probability of each program part, which then guides a best-first search algorithm to find the most likely program fitting the user's examples.

Experimental Setup: The Layout Domain

The researchers evaluated their approach using a Layout Domain, where the task is to synthesize programs that generate patterns on a grid, such as placing red chickens or green trees in specific geometric arrangements.

The Layout Domain: Examples of grid patterns and their corresponding program parameters, such as object type, position, and repetition logic.

The study utilized both synthetic data generated by "perfect" models and a dataset of human-provided examples from prior work, where humans attempted to "teach" programs to a computer.

Key Results and Insights

The study revealed that the factored approximation is not just a computational shortcut but may actually reflect human cognitive processes:

  • The Human Advantage: Surprisingly, the factored model ($L_{F_0}$) performed better than the "exact" joint model ($L_{J_0}$) when dealing with real human input. This suggests that humans naturally think about and communicate programs in these factored chunks.
  • Pragmatism Creates Sparsity: While assuming program parts are independent is technically an approximation, the authors found that informative examples "concentrate" the probability mass. This makes the independence assumption work significantly better than it would with random examples.
  • Efficiency Gains: By factoring the distribution, the authors achieved pragmatic reasoning at a fraction of the inference cost required by previous methods.
Performance comparison showing the fraction of programs correctly inferred vs. the number of utterances. The left plot shows results on human data, where the factored model (dashed) outperforms the joint model (solid).

Limitations and Future Work

While the layout domain demonstrates the potential of this approach, future work is needed to test if this factorization holds up in more complex, recursive programming languages. Additionally, the authors noted "error accumulation" in the neural model ($L_{N_1}$), where small mistakes in predicting individual parts multiply when combined. Refining the neural component and testing the model in real-time interactive settings remain key areas for future exploration.

Summary updated

BibTeX
@misc{vaduguru2022efficient,
  author = {Saujas Vaduguru and Kevin Ellis and Yewen Pu},
  title = {{Efficient Pragmatic Program Synthesis with Informative Specifications}},
  year = {2022},
  eprint = {2204.02495},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2204.02495},
}
Figure