TL;DR
Program synthesis—generating code from examples—is often "ill-posed" because many different programs can satisfy the same few examples. This paper introduces a "pragmatic" synthesizer that uses linguistic principles to infer user intent. Instead of just asking "which program fits these examples?", it asks "why would a rational human choose these specific examples to describe this program?"
The Problem: Ambiguity in Specifications
Imagine using a tool like Excel’s FlashFill. You provide a single example: Richard Feynman $\rightarrow$ Mr Feynman. A literal computer might conclude that the underlying program is simply "always print 'Mr Feynman' regardless of the input." Technically, that satisfies your example, but it’s obviously not what you meant.
This highlights the core challenge of Program Synthesis: the search space of possible programs is massive, and user specifications (like input-output examples) are almost always ambiguous. Traditionally, researchers solve this by baking in "inductive biases," such as a preference for shorter or "simpler" programs. However, these hand-crafted rules often fail to capture the nuance of human communication. The authors argue that synthesis should instead be treated as a Reference Game—a cooperative act of communication where the machine assumes the user is being helpful and didactic.
Methods: The Rational Speech Act Framework
To solve this, the researchers adapt the Rational Speech Act (RSA) framework from computational linguistics to the world of code. They model the interaction through three levels of recursive reasoning:
- Literal Listener ($L_0$): A "naive" synthesizer that considers all programs consistent with the provided examples to be equally likely.
- Pragmatic Speaker ($S_1$): A model of a "helpful" user. This speaker chooses examples that would most likely lead the Literal Listener ($L_0$) to the correct program, favoring examples that are highly informative and parsimonious.
- Pragmatic Listener ($L_1$): The final "smart" synthesizer. When it sees examples, it performs Bayesian inference to find the program that a Pragmatic Speaker ($S_1$) would have been most likely to use to communicate that specific intent.
To make this computationally feasible, the authors used Version Space Algebra (VSA). Instead of searching through millions of programs for every step, VSA allows the system to efficiently represent and intersect sets of consistent programs, using aggressive precomputation to keep the complex "pragmatic" math from slowing down the system.
Experimental Setup: The Grid Domain
The paper evaluates the approach in a custom-built environment known as the Grid Domain. This involves a Domain Specific Language (DSL) for creating 7x7 grid patterns (e.g., rings of "pigs" or "chickens" in different colors). After de-duplication, the space contained 17,976 unique programs.
To test the system, the authors recruited 48 participants via Amazon Mechanical Turk to interact with two "robots"—one literal ($L_0$) and one pragmatic ($L_1$). Participants were tasked with communicating specific grid patterns to the robots using as few examples as possible.
Key Insights and Results
- The "Why" Matters: The breakthrough here is moving from "What does the code do?" to "Why did the user choose this example?" If a user provides examples of the corners of a square, a pragmatic listener infers the user is defining the boundary of the shape, whereas a literal listener might still be confused about the interior.
- Humans Expect Pragmatics: The study found that humans naturally communicate as if the machine is smart. When the machine acts literally, humans find it frustrating and "deaf." The pragmatic synthesizer aligns the machine's expectations with the human's natural teaching style.
- Efficiency and Preference: Human participants were significantly more efficient with the pragmatic synthesizer, requiring an average of 2.8 fewer moves to communicate their intended program compared to the literal version. Furthermore, a resounding 77% of participants reported that the pragmatic robot was easier to work with.
- Superiority over "Simplicity" Priors: The authors compared their pragmatic model ($L_1$) against a synthesizer using a hand-crafted "simplicity" prior (preferring fewer symbols/colors). The pragmatic model outperformed the hand-crafted prior, suggesting that communicative principles are more effective than arbitrary syntactic rules.
Limitations and Future Work
The primary limitation of this approach is scalability. The current implementation relies on being able to enumerate or represent the entire program space using VSA. While this works for a 7x7 grid or simple string transformations, it would struggle with general-purpose programming (like Python or C++) where the state space is effectively infinite.
Future work could involve approximating pragmatics using neural networks to "guess" the pragmatic value of examples in larger domains, building systems that learn a specific user’s "dialect" over time, and moving beyond grids to more complex data structures and algorithmic synthesis.
Summary updated