Inference Compilation and Universal Probabilistic Programming

Tuan Anh Le, Atilim Gunes Baydin, Frank Wood

TL;DR

This paper introduces "Inference Compilation," a framework that uses deep learning to dramatically speed up inference in universal probabilistic programs. By training a recurrent neural network to act as a smart "proposal engine" for Sequential Importance Sampling, the authors achieve massive speedups and state-of-the-art results in complex tasks like Captcha solving and object counting.

What Problem Does This Paper Address?

Probabilistic Programming Languages (PPLs) are incredibly expressive tools that allow researchers to define complex generative models using standard programming constructs (recursion, branching, etc.). However, "running the model in reverse"—performing inference to find the latent variables that explain observed data—is notoriously slow.

Standard inference algorithms like Sequential Importance Sampling (SIS) or Markov Chain Monte Carlo (MCMC) often struggle because they explore the high-dimensional space of possible solutions "blindly," requiring thousands or millions of samples to find a good fit. This paper aims to bridge the gap between the flexibility of universal PPLs and the inference speed of deep learning.

Methods

The authors propose a technique called Inference Compilation. The core idea is to treat the probabilistic program as a data generator.

  1. Compilation: During an "expensive" offline phase, the probabilistic program generates an infinite stream of synthetic training data (pairs of latent variables $x$ and observations $y$).
  2. Neural Network Training: This data is used to train a neural network (specifically an LSTM-based architecture) to approximate the posterior distribution $p(x|y)$. The network learns to predict the next "choice" the program should make given the observations and all previous choices.
  3. Adaptive Architecture: Because universal programs can have variable execution paths, the authors developed a dynamic architecture. It uses a central LSTM core but attaches specialized "embedding" and "proposal" layers on-the-fly as the program encounters different sample statements.
  4. Inference: At test time, the trained network serves as the proposal distribution for a Sequential Importance Sampling (SIS) engine. Instead of guessing randomly, the SIS engine uses the neural network's predictions to focus on the most likely parts of the state space.
Figure 1: Our approach to compiled inference. Given only a probabilistic program p(x, y), during compi- lation we automatically construct a neural network architecture comprising an LSTM core and various embedding and proposal layers specified by the proba- bilistic program and train this using an infinite stream of training data {x(m), y(m)} generated from the model. When this expensive compilation stage is complete, we are left with an artifact of weights φ and neural archi- tecture specialized for the given probabilistic program. During inference, the probabilistic program and the compilation artifact is used in a sequential importance sampling procedure, where the artifact parameterizes the proposal distribution q(x|y; φ).

Datasets

The method was evaluated on three distinct domains:

  • Gaussian Mixture Models (GMMs): Synthetic models where the number of clusters is unknown.
  • Captchas: Generative models for various Captcha styles, including Baidu, eBay, Yahoo, reCaptcha, Wikipedia, and Facebook. Training was done on synthetic data generated by the models; testing was performed on both synthetic and real-world images.
  • Object Counting: Using the PASCAL VOC 2007 dataset, the authors treated object detection as a probabilistic inference problem to count and localize objects like people, cats, and bicycles.

Key Insights and Ideas

  • Infinite Training Data: Because the generative model is the program, the authors can generate an infinite stream of labeled data. This effectively eliminates the risk of traditional overfitting to a fixed dataset.
  • The "Inference Network" as a Guide: The neural network doesn't replace the probabilistic model; it guides it. This is crucial because even if the neural network makes a mistake, the SIS framework provides a mathematical guarantee that the inference will eventually converge to the correct posterior.
  • Symmetry Breaking: To help the neural network learn effectively in models with symmetries (like GMMs, where cluster labels are interchangeable), the authors found that sorting latent variables (e.g., by distance from the origin) during training was essential.
The dynamic neural network architecture that adapts to the program's execution trace.

Key Results

  • Efficiency Gains: In GMM experiments, the compiled inference produced high-accuracy estimates with just a handful of particles, whereas standard SMC required orders of magnitude more computation to reach the same level of clarity.
  • Captcha Breaking: The system achieved near-perfect recognition rates on many Captcha sets (e.g., 99.8% on Baidu 2011 and 91.0% on Facebook).
  • Speed: Solving a Captcha took less than 100ms, compared to minutes for traditional MCMC-based PPL inference.
  • Real-World Generalization: Despite being trained on synthetic data, the models achieved 81% and 42% recognition rates on real Wikipedia and Facebook Captchas, respectively, after some minor tuning of the model's priors.
Comparison of standard SMC vs. Compiled Inference for GMMs. Compiled inference (bottom) is much clearer with fewer particles.

Limitations and Future Work

  • Model Misspecification: The biggest hurdle is the "synthetic gap." If the generative program doesn't perfectly match the real-world data (e.g., if the Captcha font or noise is slightly different), the neural network's proposals may be poor.
  • Manual Embedding Design: While the LSTM core is general, the "observation embeddings" (like the CNN used for Captcha images) still need to be hand-picked for the specific domain.
  • Future Directions: The authors suggest exploring ways to automatically derive the neural network architecture directly from the program's computational graph and automating the selection of pre-trained embeddings.

Summary updated

BibTeX
@inproceedings{le2017inference,
  author = {Tuan Anh Le and Atilim Gunes Baydin and Frank Wood},
  title = {{Inference Compilation and Universal Probabilistic Programming}},
  booktitle = {International Conference on Artificial Intelligence and Statistics},
  year = {2017},
  url = {https://openreview.net/forum?id=sJGL7l-IgGy},
}
Figure