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

DreamCoder: Growing generalizable, interpretable knowledge with wake-sleep Bayesian program learning

Kevin Ellis, Catherine Wong, Maxwell I. Nye, Mathias Sablé-Meyer, Luc Cary, Lucas Morales, Luke B. Hewitt, Armando Solar-Lezama, Joshua B. Tenenbaum

DreamCoder is a "wake-sleep" learning system that solves complex problems by writing programs while simultaneously building its own domain-specific programming languages. By alternating between solving tasks (waking), abstracting common code patterns into new primitives (abstraction sleep), and training a neural network to "intuit" solutions (dreaming sleep), it bootstraps itself from a beginner to an expert across domains ranging from graphics to classical physics.

The Challenge of Program Induction

Program induction—the idea of an AI "writing code" to solve a task—is a holy grail of AI because programs are naturally interpretable, highly generalizable, and incredibly sample-efficient. However, it faces two massive bottlenecks:

  1. The Language Gap: To solve problems efficiently, you need a specialized language (a Domain-Specific Language or DSL). Traditionally, humans have to hand-engineer these languages.
  2. The Search Problem: The space of all possible programs is astronomically large. Searching for the right one is like looking for a needle in a haystack the size of the solar system.

DreamCoder aims to solve both by "learning to learn." It starts with a tiny set of generic primitives and iteratively builds its own library of concepts and a neural "intuition" to navigate them.

Methods: The Wake-Sleep Cycle

The core of DreamCoder is a three-phase Wake-Sleep cycle:

  • Wake Phase: The system attempts to solve a set of training tasks. It uses a neural recognition model to predict which program components are likely to be useful, guiding a search for the best program (the one that solves the task and is shortest in the current language).
  • Sleep Phase 1 (Abstraction): The system looks at the programs it successfully wrote during the Wake phase. It identifies common sub-expressions and "refactors" them into new, higher-level library primitives. This effectively "shrinks" the depth of the search tree for future, more complex problems.
  • Sleep Phase 2 (Dreaming): The system uses its current library to generate random programs ("fantasies") and their corresponding outputs. It then trains the neural recognition model to predict the program from the output. This allows the model to practice on an infinite stream of data, developing the "intuition" needed to narrow the breadth of the search.
Overview of DreamCoder domains and the hierarchical library of concepts learned to solve tasks like sorting.

Evaluation and Key Insights

The authors evaluated DreamCoder across eight diverse domains, including list processing, text editing (SyGuS benchmark), LOGO graphics, tower building, regex inference, and symbolic regression for physical laws.

Synergy of Symbolic and Neural

DreamCoder treats the library (symbolic) as the "prior" and the neural network as the "inference engine." The library makes hard problems "shorter" to express, while the neural network makes them "faster" to find. By "dreaming" up random programs, the system creates its own training data, allowing it to learn complex tasks from only a handful of real-world examples.

Hierarchical Discovery and Change of Basis

The system rediscovers fundamental concepts of computer science. For example, it starts with basic recursion and eventually invents "map" and "filter," then uses those to invent "sort." In the physics domain, the system starts with list-processing primitives and eventually "rotates" its entire language into a physics-style basis, discovering concepts like vector sums and inverse-square laws.

Results

  • Text Editing: Before learning, DreamCoder solved only 3.7% of the SyGuS benchmark tasks. After its wake-sleep cycles, it solved 79.6%, performing comparably to state-of-the-art hand-engineered synthesizers.
  • Efficiency: In the list-processing domain, a solution for "Sort List" that would have taken $10^{72}$ years to find via brute force was discovered in less than 10 minutes after the system learned the right abstractions.
  • Interpretability: Unlike "black box" neural networks, DreamCoder’s learned libraries are human-readable. It literally "invents" functions for circles, polygons, and arches that look like code a human would write.

Limitations and Future Work

While sample-efficient in terms of data, DreamCoder is compute-heavy. Learning functional programming from scratch took approximately one year of CPU time. Additionally, the current system excels at "crisp" symbolic logic but struggles with the messy noise found in many real-world datasets. Moving to general commonsense reasoning will require further innovation in program-based knowledge representation.

Summary updated

BibTeX
@inproceedings{ellis2023dreamcoder,
  author = {Kevin Ellis and Catherine Wong and Maxwell I. Nye and Mathias Sablé-Meyer and Luc Cary and Lucas Morales and Luke B. 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