Abstract
Inference in universal probabilistic programming languages (PPLs) is often computationally prohibitive due to the mismatch between model priors and observed data. This paper introduces Inference Compilation, a framework that amortizes the cost of inference by training a deep neural network to serve as a proposal distribution for Sequential Importance Sampling (SIS). By leveraging the generative model as a data source, the framework achieves significant speedups in complex tasks like Captcha breaking and object localization, reducing inference times from minutes to milliseconds.
Introduction
Probabilistic programming languages (PPLs) allow researchers to define complex generative models using the full power of Turing-complete code. However, performing inference—calculating the "hidden" variables that explain observed data—is notoriously slow. Standard algorithms like Sequential Monte Carlo (SMC) or MCMC often require thousands of iterations to converge because they sample from the model's "prior" distribution, which rarely matches the actual data being observed. This paper addresses this "inference bottleneck" by combining the flexibility of universal PPLs with the execution speed of trained neural networks.
The Inference Compilation Framework
The core idea is to treat the probabilistic program as a simulator that generates an infinite stream of training data. This leads to a two-phase approach:
- Compilation Phase (Offline): The system runs the probabilistic program many times to generate pairs of latent variables ($x$) and observations ($y$). It uses this data to train a neural network (the "compilation artifact") to approximate the posterior distribution $p(x|y)$. The training objective is to minimize the Kullback–Leibler (KL) divergence between the true posterior and the network's proposals.
- Inference Phase (Online): At test time, the trained network is used to provide "smart proposals" for a Sequential Importance Sampling (SIS) engine. Instead of guessing blindly, the network looks at the observed data and suggests likely values for the latent variables.
Adaptive LSTM Architecture
Because universal PPLs can have variable-length execution traces and stochastic branching, a static network architecture is insufficient. The authors utilize a Long Short-Term Memory (LSTM) core that reconfigures its input and output layers on-the-fly. This reconfiguration is based on the specific "address" (location in code) of the current random variable being sampled, allowing the network to adapt to any program trace dynamically.
Experimental Results
The authors evaluated their method on three distinct domains:
- Gaussian Mixture Models (GMM): In open-universe experiments, the compiled proposal with just 1 particle was more accurate than standard SMC using 10,000 particles.
- Captcha Breaking: The method achieved state-of-the-art results on several datasets, reaching 99.8% accuracy on Baidu 2011 and 91% on Facebook. Running inference on a test Captcha took less than 100ms, compared to minutes for previous MCMC-based approaches.
- Object Localization: Using the PASCAL VOC 2007 dataset, the model was tasked with identifying the number and location of objects like people, cats, and bicycles. Despite being trained on synthetic data, the models generalized well to real-world images.
Key Insights
- Amortization is Key: By spending time "compiling" inference into a neural network once, you save time every single time you run the model thereafter.
- Programs as Data Generators: You don't need a manually labeled dataset. If you can write a generative model (e.g., a program that renders a Captcha), you have an infinite source of perfectly labeled training data.
- Symmetry Breaking: In models like GMMs, sorting latent variables (e.g., by distance from the origin) during training helps the neural network learn much more effectively by resolving label-switching ambiguities.
Limitations and Future Work
The neural network is only as good as the generative program it was trained on. If the program doesn't accurately reflect real-world data (the "synthetic gap"), the network will struggle. Future work aims to explore architectures where the neural artifact and the program's computational graph have an even tighter, more automatic correspondence, and to automate the design of observation embeddings.
Summary updated