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

Neural Programming by Example

Chengxun Shu, Hongyu Zhang

Abstract

Neural Programming by Example (NPBE) introduces a deep learning framework for automatically generating string manipulation programs from a single input-output example. By leveraging a modular architecture comprising string encoders, a transformation analyzer, and a program generator with attention, NPBE learns to induce the underlying logic of transformations rather than simple sequence mappings. Experimental results demonstrate that NPBE significantly outperforms standard sequence-to-sequence models, achieving high accuracy and robust generalization to unseen argument combinations.

Introduction

Programming by Example (PBE) aims to democratize programming by allowing users to specify intent through examples rather than code. A classic application is Microsoft Excel's Flash Fill, which automates string manipulations based on user-provided patterns. Traditionally, PBE systems rely on complex, hand-designed search algorithms to navigate a "version space" of possible programs. NPBE addresses the challenge of whether a Deep Neural Network (DNN) can learn to perform this synthesis, moving away from manual search toward a model that can "reason" about the relationship between input and output strings.

System Architecture

The NPBE model consists of four modular neural components designed to capture the semantics of string transformations:

  1. String Encoder: Utilizes a bidirectional LSTM to create embeddings for every character and the string as a whole, capturing the structural context of the data.
  2. Input/Output (I/O) Analyzer: A multi-layer perceptron that processes the embeddings of the input and output strings to produce a "transformation embedding." This represents the core logic required to map the input to the output.
  3. Program Generator: The heart of the system, which operates for several steps (up to $T=5$). At each step, it produces a function embedding and an argument embedding. It employs an attention mechanism to reference the original strings when selecting specific arguments like delimiters or indices.
  4. Symbol Selector: Decodes these embeddings into human-readable code, selecting from a library of seven atomic functions (e.g., Split, Select, ToLower, Concatenate) and a set of constant arguments.
The NPBE architecture consists of specialized modules for encoding strings, analyzing transformations, and generating program steps.

The model is trained end-to-end using an adaptive curriculum, which prioritizes difficult tasks during training to ensure the system masters complex logic.

Experimental Evaluation

The authors evaluated NPBE on a synthetic dataset of 45 string manipulation tasks, ranging from simple case changes to nested splits and concatenations. To test true logic induction, a generalization set of 19 tasks featured "unseen" argument combinations—delimiters or integers paired with functions in ways not encountered during training.

Key Results

NPBE achieved a Top-1 accuracy of 74.1% across all tasks, which rose to 91.0% when considering the Top-5 guesses. Crucially, standard sequence-to-sequence models (like LSTMs with attention used in translation) failed, achieving only ~22% accuracy. This highlights the necessity of NPBE's specialized architecture for program synthesis.

Examples of input-output pairs and the corresponding multi-step programs synthesized by NPBE.

Generalization and Logic Induction

On the "unseen arguments" test, the model maintained an accuracy of 87.4%. This suggests that NPBE learns the functional relationship between strings rather than just memorizing mappings. One notable finding was that the model's primary source of error was "counting"—specifically, selecting the correct integer index for the Select function, a known challenge for neural architectures.

Conclusion and Future Work

NPBE demonstrates that neural networks can effectively synthesize programs from minimal examples by learning transformation logic. While currently limited to a fixed library of seven functions and specific task types, future work aims to expand the atomic library and improve numerical reasoning. The ultimate goal is a system that understands the semantic meaning of functions, allowing it to generalize to entirely novel task compositions without task-specific training data.

Summary updated

BibTeX
@inproceedings{shu2017neural,
  author = {Chengxun Shu and Hongyu Zhang},
  title = {{Neural Programming by Example}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2017},
  doi = {10.1609/aaai.v31i1.10734},
}
Figure