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

DreamCoder: growing generalizable, interpretable knowledge with wake–sleep Bayesian program learning

Kevin Ellis, Lionel Wong, Maxwell Nye, Mathias Sablé-Meyer, Luc Cary, Lore Anaya Pozo, Luke Hewitt, Armando Solar-Lezama, Joshua B. Tenenbaum

Abstract

Expert problem-solving is driven by powerful languages for thinking about problems and their solutions. Acquiring expertise means learning these languages—systems of concepts, alongside the skills to use them. We present DreamCoder, a system that learns to solve problems by writing programs. It builds expertise by creating domain-specific programming languages for expressing domain concepts, together with neural networks to guide the search for programs within these languages. A 'wake-sleep' learning algorithm alternately extends the language with new symbolic abstractions and trains the neural network on imagined and replayed problems. DreamCoder solves both classic inductive programming tasks and creative tasks such as drawing pictures and building scenes. It rediscovers the basics of modern functional programming, vector algebra and classical physics, including Newton's and Coulomb's laws. Concepts are built compositionally from those learned earlier, yielding multilayered symbolic representations that are interpretable and transferrable to new tasks, while still growing scalably and flexibly with experience.

Introduction: Bridging Symbolic Reasoning and Neural Networks

In the quest for "human-like" AI, two major paradigms often clash: symbolic reasoning and neural networks. Symbolic systems are interpretable and generalizable but difficult to scale. Conversely, neural networks are scalable and flexible but often act as "black boxes" requiring massive amounts of data.

Program induction—the ability of a machine to learn by writing code—offers a promising middle ground. However, it faces two significant bottlenecks:

  1. The DSL Problem: Finding a program typically requires a hand-crafted Domain-Specific Language (DSL) that provides the necessary "building blocks."
  2. The Search Problem: The space of possible programs is combinatorial; searching for the correct one is like finding a needle in an infinite haystack.

DreamCoder addresses both by "learning to learn." It doesn't just search for programs; it grows the language it uses to describe them and trains a neural network to guide its search.

Methods: The Wake–Sleep Cycle

The system operates in a three-phase "wake–sleep" cycle:

  • Wake Phase: The system attempts to solve tasks by searching for programs. A recognition model (a neural network) predicts which library components are likely to be useful, effectively pruning the search space.
  • Sleep (Abstraction) Phase: The system analyzes successful programs from the Wake phase, identifying common sub-structures and refactors them into new, higher-level library primitives. This follows a compression objective: a better library makes programs shorter and easier to find.
  • Sleep (Dreaming) Phase: To train the recognition model, the system "dreams" by sampling random programs from its current library and executing them to create synthetic (input, output) pairs. This provides an infinite stream of self-generated data for the neural network to practice on.

Diverse Domains and Learned Concepts

DreamCoder was evaluated across eight diverse domains, demonstrating its generality:

  • List Processing: Classic functional programming tasks like sorting.
  • Text Editing: String transformations (e.g., "Alan Turing" → "A.T.").
  • LOGO Graphics: Drawing shapes and patterns using turtle graphics.
  • Tower Building: Planning block stacks to replicate target structures.
  • Symbolic Regression: Fitting mathematical equations to data points.
  • Generative Text Modeling: Inferring probabilistic Regular Expressions (Regex).
  • Physical Laws: Learning 60 equations from physics "cheat sheets."
  • Recursive Programming: Starting from minimal 1959 Lisp primitives.
DreamCoder's diverse problem domains (a) and its learned library of concepts (b), illustrating how complex solutions are built from simpler primitives.

Key Insights: Bootstrapping Expertise

  • Hierarchical Learning: The system follows a self-made curriculum. It learns simple concepts (like filter) first, then uses them to define complex ones (like sort or Newton's Law).
  • Interpretability through Composition: Because the library consists of symbolic code, the acquired knowledge is human-readable. The AI effectively "invents" vector algebra to solve physics problems.
  • The Power of "Fantasies": The dreaming phase overcomes the "small data" problem. By training on its internal world model, the neural network becomes an expert at navigating the evolving DSL.
  • Origami Programming: Starting with minimal primitives, the system rediscovered that nearly all recursive data processing can be expressed through fold and unfold operations.

Key Results

  • Efficiency Gains: In text editing, DreamCoder improved from solving 3.7% of tasks to 79.6% after learning a library, with average search times dropping to 40 seconds.
  • Scientific Discovery: The system learned 93% of the physical laws in its dataset, undergoing a "change of basis" from raw list processing to a specialized physics language.
  • Complexity Reduction: For list-sorting, the final program used five function calls. In the original primitives, this would have required 32 calls—a complexity that would take $10^{72}$ years to find via brute-force search.

Limitations and Future Directions

While powerful, DreamCoder requires significant initial computation; rediscovering the "origami" basis took roughly one year of CPU time. It also currently focuses on "crisp" symbolic problems, and handling noisy real-world sensor data remains a challenge. Future work may involve active learning, where the system autonomously invents its own problems to expand its library.

Summary updated

BibTeX
@inproceedings{ellis2023dreamcoder,
  author = {Kevin Ellis and Lionel Wong and Maxwell Nye and Mathias Sablé-Meyer and Luc Cary and Lore Anaya Pozo and Luke Hewitt and Armando Solar-Lezama and Joshua B. Tenenbaum},
  title = {{DreamCoder: growing generalizable, interpretable knowledge with wake–sleep Bayesian program learning}},
  booktitle = {Philosophical},
  year = {2023},
  doi = {10.1098/rsta.2022.0050},
}
Figure