Church: a language for generative models

Noah D. Goodman, Vikash K. Mansinghka, Daniel M. Roy, Kallista A. Bonawitz, Joshua B. TenenbaumUAI 2008

Introduction

Church is a pioneering universal probabilistic programming language (PPL) that brings the power of Lisp-style functional programming to generative modeling. By treating evaluation as sampling and introducing "stochastic memoization," it allows researchers to define complex, non-parametric, and recursive probabilistic models with unprecedented brevity and clarity.

The Challenge of Universal Modeling

Before Church, probabilistic models were typically described using a mix of natural language and mathematical notation, with inference algorithms implemented by hand for every new model. While languages like BUGS existed, they were often limited to specific types of graphical models, such as directed acyclic graphs with fixed structures.

The authors sought to create a "universal" language—one capable of describing any computable generative process. The challenge was to build a framework that supports modularity, recursion, and "random worlds" (where properties of objects are persistent and shared) while providing a generic way to perform inference (querying the model) without writing custom code for every scenario.

Core Methodology

Church is built on a pure subset of Scheme (a Lisp dialect). Its core philosophy rests on three pillars:

  1. Evaluation as Sampling: In Church, the primitive eval doesn't just return a value; it returns a sample from the stochastic process defined by the code.
  2. The query Primitive: This is the heart of the language's programming aspect. query generalizes sampling to conditional sampling. You provide a model and a predicate (a logical constraint), and Church returns samples from the model that satisfy that constraint.
  3. Stochastic Memoization (mem): This is the paper's most novel contribution. In standard programming, memoization caches results to save time. In Church, memoizing a random function ensures that the function returns the same random value every time it is called with the same arguments. This allows for the easy definition of "persistent" properties in a model, such as the "color" of a specific object in a scene.

For inference, the authors describe two approaches: Rejection Sampling, which is simple but slow, and Metropolis-Hastings (MCMC) on Computation Traces, a more sophisticated algorithm that performs a stochastic search over the program's execution history to find paths satisfying the query.

Expressive Power and Non-parametrics

A key insight of Church is that non-parametric models can be represented via DPmem (Dirichlet Process memoization). This allows Church to represent models with an infinite number of latent components, such as clusters or grammar rules, which are only instantiated as needed.

Non-parametric clustering demonstrating the expressive power of Church in defining infinite mixture models.

Planning as Inference

The paper demonstrates that complex behaviors, such as planning, can be elegantly framed as probabilistic queries. In a "red-light" game, an agent must decide when to "cheat" to reach a goal. The model correctly predicts that an agent is more likely to take risks when the goal is near but the light is red, demonstrating intuitive planning through inference.

Probability of choosing action 'go' versus position in the 'red-light' planning game.

Key Results and Limitations

The authors show that complex models like the Hierarchical Dirichlet Process Hidden Markov Model (HDP-HMM), which usually require pages of math, can be expressed in just a few lines of Church code. Furthermore, generic inference successfully captures "explain-away" effects in causal reasoning.

However, the primary drawback is efficiency. Generic inference is computationally expensive, making Church more of a "specification language" than a high-performance tool at this stage. Future work focuses on program analysis to automatically transform query expressions into more efficient forms and integrating mutable state while maintaining mathematical rigor.

Summary updated

BibTeX
@misc{goodman2008church,
  author = {Noah D. Goodman and Vikash K. Mansinghka and Daniel M. Roy and Kallista A. Bonawitz and Joshua B. Tenenbaum},
  title = {{Church: a language for generative models}},
  year = {2008},
  eprint = {1206.3255},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1206.3255},
}
Figure