NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

A Machine Learning Framework for Programming by Example

Aditya Krishna Menon, Omer Tamuz, Sumit Gulwani, Butler W. Lampson, Adam Kalai

TL;DR

This paper introduces a machine learning framework that dramatically speeds up Programming by Example (PBE)—the task of automatically generating code from a few input-output pairs. By using "textual clues" to weight a Probabilistic Context-Free Grammar (PCFG), the system learns to prioritize likely code components, achieving up to a 40x speedup over traditional search methods.

What Problem Does This Paper Address?

Programming by Example (PBE) is the technology behind features like Microsoft Excel’s "Flash Fill." The goal is simple: a user provides an example, and the system infers a program to automate that task for thousands of rows.

Programming by Example (PBE) demonstration

However, PBE faces two massive hurdles:

  1. The Search Problem: The space of possible programs is infinite. Searching for a valid composition of functions is like looking for a needle in a haystack where the haystack grows exponentially with program length.
  2. The Ranking Problem: There are often many programs that satisfy a single example, but most are "trivial" or incorrect for the broader dataset. How does the system pick the "intended" one?

Earlier systems relied on hand-coded heuristics or highly restricted "version space algebras" that were difficult to extend to new domains. This paper seeks a more general, learning-based approach.

Methods

The authors propose a framework that treats program generation as a search through a Probabilistic Context-Free Grammar (PCFG).

  • The Grammar: They define a base language of ~100 functions (like dedup, count, split, and concat).
  • Textual Clues: This is the core innovation. Instead of a blind search, the system uses "clues"—functions that look at the strings in the example and suggest specific grammar rules. For instance, if the output contains parentheses but the input doesn't, a clue might increase the probability of a concat rule involving ( and ).
  • Log-Linear Model: Each clue is assigned a weight. The probability of a specific program is the product of the weights of the rules used to build it.
  • Learning: The weights are learned from a training corpus of tasks. Because we don't always know the "correct" underlying program for a training example, the authors use a bootstrapping approach: they iteratively find the most likely program using current weights and then update the weights to favor that program.
  • Inference: At runtime, the system evaluates clues on the user's example, builds a task-specific PCFG, and enumerates programs in order of decreasing probability until it finds one that works.

Datasets

The authors evaluated their system on a suite of 280 text-processing tasks. These were a mix of hand-crafted scenarios and real-world problems distilled from Microsoft Excel help forums. The tasks involve complex string manipulations, such as reformatting dates, extracting substrings based on delimiters, and removing duplicates—tasks that often require multiple nested function calls (median depth of 4).

Key Insights and Ideas

  • Search as Distribution: The "aha moment" here is that we don't need to execute code to know if it's likely to be useful. By looking at the features of the strings (e.g., "Are there numbers in the output?"), we can create a prior distribution over the code itself.
  • Extensibility: Unlike previous PBE systems that were "hard-coded" for specific string patterns, this framework is a "plug-and-play" model. If you want the system to handle a new domain (like list processing), you just add new functions and corresponding clues; the ML handles the rest.
  • Learning Beats Heuristics: The "shortest program" heuristic (Occam's Razor) is a common fallback in PBE, but it often fails (e.g., the shortest program might just be a constant string). Learning from a corpus allows the system to discover that certain complex structures are actually more "plausible" than simpler ones in specific contexts.

Key Results

The results demonstrate that learning is not just an optimization—it's a necessity for complex tasks.

Performance improvements including timeout errors, ranking errors, and mean speedup
  • Massive Speedup: The learning-based approach achieved a mean speedup of up to 40x compared to a baseline search with uniform weights.
  • Solving the "Unsolvable": Many complex programs (depth 4 or greater) were found within seconds by the learning system, while the baseline timed out after 16 seconds.
  • Ranking Accuracy: The system was significantly better at picking the correct program among multiple candidates that fit the example, reducing "ranking errors" compared to the baseline.
  • Efficiency: In one specific example, a brute-force search took 30 seconds to find a solution; the learned model found it in just 0.5 seconds.

Limitations and Future Work

  • Negative Correlations: The current model focuses on "positive" clues (what to include). The authors note that learning what not to use (e.g., "if there are no numbers, don't use the count function") could further prune the search space but would require more complex parameter enforcement.
  • Feature Engineering: While the system learns weights, the "clues" themselves are still manually designed. Future work could involve automatically discovering these features.
  • Scaling the Library: As the library of functions grows into the thousands, maintaining a sparse and efficient set of clues will become a significant engineering challenge.

Summary updated

BibTeX
@inproceedings{menon2013machine,
  author = {Aditya Krishna Menon and Omer Tamuz and Sumit Gulwani and Butler W. Lampson and Adam Kalai},
  title = {{A Machine Learning Framework for Programming by Example}},
  booktitle = {International Conference on Machine Learning},
  year = {2013},
}
Figure