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

Learning Natural Programs from a Few Examples in Real-Time

Nagarajan Natarajan, Danny Simmons, Naren Datha, Prateek Jain, Sumit Gulwani

Abstract

Programming by Example (PBE) systems often struggle with intent disambiguation, where millions of programs may satisfy a single input-output pair, but only one is the user's intended solution. This paper introduces a novel machine learning framework integrated into the PROSE (Program Synthesis using Examples) system. By combining recursive program-spec embeddings with an interleaved ranking algorithm, the framework synthesizes "natural" programs from just one or two examples in real-time, outperforming both hand-tuned expert heuristics and state-of-the-art neural synthesis models.

Introduction

PBE allows non-programmers to automate repetitive tasks, such as string formatting in spreadsheets, by providing a few examples. The core technical challenge is finding the intended program within a massive search space. Existing solutions typically rely on symbolic systems with hand-crafted heuristics (e.g., "prefer shorter programs") which are difficult to maintain, or neural models that require vast synthetic data and often fail to produce programs that are strictly consistent with the provided examples.

This research seeks a middle ground: a system as fast as symbolic search but as adaptable as a machine learning model, capable of learning what a "natural" program looks like from real-world usage data.

Methodology

The proposed approach utilizes a two-pronged strategy within the PROSE framework:

Recursive Program-Spec Embedding

The authors developed a technique to embed heterogeneous programs and their input-output (I/O) specifications into a shared, fixed-dimensional vector space. This representation is recursive: the embedding of a program node is a weighted combination of its operator and the embeddings of its sub-programs. This allows the model to capture the semantic meaning of code snippets in context.

Figure 1: Illustration of the recursive program embedding process. Each node in the program tree (e.g., SubStr, PosPair) is associated with a vector representation (colored bars) derived from its sub-components.

Interleaved Ranking and Iterative Training

To maintain real-time performance, ranking is interleaved with the search process rather than applied post-hoc. Three formulations were explored:

  • ML-PROSE: Ranks only complete programs.
  • ML-PROSE-SubPRG: Ranks both final programs and their constituent sub-programs to provide "distant supervision."
  • MinMax: A formulation ensuring at least one correct program is ranked above all incorrect ones for a given task.

To address biased training data, the authors used an iterative bootstrapping process, synthesizing programs with the current ranker and retraining on the newly labeled data.

Experimental Results

The framework was evaluated on the FlashFill benchmark, consisting of 740 real-world string, date, and number manipulation tasks. The ML-based rankers were compared against standard baselines like "Shortest Program" and neural models like RobustFill.

Figure 3: Performance comparison of various ranking methods. The proposed ML-PROSE-SubPRG and MinMax methods significantly outperform traditional heuristics like Shortest Program, especially with only one example (m=1).

Key findings include:

  • High Accuracy with Minimal Data: Using just one I/O example, the MinMax method achieved 67% accuracy (Acc@1), compared to 44% for the best baseline. With two examples, accuracy exceeded 80%.
  • Superiority over Neural Models: On a subset of tasks, the proposed method achieved 70% Acc@1, while the neural-heavy RobustFill managed only 32%.
  • Competitive with Experts: The learned ranker performed competitively with manually tuned expert heuristics used in commercial products.

Conclusion

By learning to identify "natural" programs through recursive embeddings and interleaved ranking, this framework significantly improves the accuracy and efficiency of PBE systems. While currently dependent on a predefined Domain Specific Language (DSL), the success of this embedding technique suggests future applications in broader programming tasks like automated bug fixing and code completion.

Summary updated

BibTeX
@inproceedings{natarajan2019learning,
  author = {Nagarajan Natarajan and Danny Simmons and Naren Datha and Prateek Jain and Sumit Gulwani},
  title = {{Learning Natural Programs from a Few Examples in Real-Time}},
  booktitle = {International Conference on Artificial Intelligence and Statistics},
  year = {2019},
}
Figure