TL;DR
TensorFlow Distributions (TFD) is a powerful library that bridges the gap between classical probability theory and modern deep learning. By providing a suite of differentiable, composable building blocks—namely Distributions and Bijectors—it enables researchers to build complex probabilistic models (like Variational Auto-encoders and Normalizing Flows) that are as efficient and scalable as standard neural networks.
What Problem Does This Paper Address?
While deep learning has revolutionized perceptual tasks, integrating it with probabilistic reasoning has historically been difficult. Traditional statistical libraries (like those in R or SciPy) were not designed for the modern deep learning stack. They often lack:
- Automatic Differentiation: The ability to backpropagate through probabilistic operations.
- Hardware Acceleration: Native support for GPUs and TPUs.
- Vectorization: Efficiently handling "batches" of distributions.
- Composability: The ability to easily transform and nest distributions to create complex, high-dimensional models.
TFD was created to provide a "backend" for probability that lives natively within the TensorFlow ecosystem, allowing for end-to-end differentiable computation.
Methods
The library is built on two primary abstractions:
- Distributions: These are the sources of stochasticity. Each distribution provides methods for sampling, computing log-densities, and calculating statistics (like mean or entropy). They follow a "Tensor-in, Tensor-out" pattern, ensuring they play nicely with the rest of TensorFlow.
- The library includes a wide variety of parameters for construction, as seen in this breakdown of the
Distributionconstructor: Constructor arguments for TFD Distributions
- Bijectors: These are deterministic, invertible transformations. They allow you to take a simple distribution (like a Normal) and "warp" it into something much more complex while keeping track of how the probability volume changes (the Jacobian). This is the foundation for Normalizing Flows.
A critical innovation in TFD is its Shape Semantics. To make vectorization efficient, TFD partitions a Tensor's shape into three distinct groups:
- Sample Shape: Independent, identically distributed draws.
- Batch Shape: Independent, but not identically distributed draws (e.g., a batch of examples where each has its own mean).
- Event Shape: The dimensions of a single draw from the distribution (e.g., a vector or a matrix).
Datasets
The paper demonstrates the library's utility through several generative modeling examples:
- MNIST: Used to demonstrate a standard Variational Auto-encoder (VAE) with a Bernoulli decoder.
- Small ImageNet: Used to showcase a high-dimensional PixelCNN distribution acting as a fully-visible autoregressive density estimator on $32 \times 32 \times 3$ RGB images.
Key Insights and Ideas
- Differentiable Sampling: TFD emphasizes "fully reparameterized" distributions. This uses the "reparameterization trick" (e.g., $y = \mu + \sigma \epsilon$), which allows gradients to flow through samples, making variational inference much easier to implement.
- Higher-Order Distributions: You can build distributions that take other distributions as inputs. For example, a
Mixturedistribution or aTransformedDistributionthat applies a Bijector to a base distribution. - Automatic Caching: Bijectors automatically cache their operations. If you sample from a transformed distribution and then immediately calculate its log-density, TFD reuses the intermediate values, significantly speeding up algorithms like Importance Sampling.
- Numerical Stability: The library is designed to handle floating-point edge cases gracefully, offering mutually exclusive parameters (like
logitsvsprobs) to ensure computations remain stable even in deep networks.
Key Results
At the time of publication, TFD provided:
- 56 Distributions ranging from simple scalars to complex multivariate structures.
- 22 Bijectors for sophisticated transformations.
- Seamless Integration: It serves as the backend for higher-level probabilistic programming languages like Edward and integrates directly with the TensorFlow Estimator API for production-grade machine learning.
- Performance: By leveraging XLA (Accelerated Linear Algebra) and device-specific kernels, TFD achieves high computational efficiency on CPUs, GPUs, and TPUs.
Limitations and Future Work
The authors acknowledge that TFD does not aim for "Universality" in the sense of general-purpose probabilistic programming. It specifically avoids:
- Non-polynomial time operations: If a distribution's log-density can't be computed efficiently, it's generally excluded.
- Approximate Inference: TFD provides the building blocks, but the actual inference algorithms (like MCMC or VI) are left to higher-level libraries like Edward.
Future directions include:
- Expanding the set of supported distributions and bijectors.
- Improving support for SparseTensors.
- Deepening hardware acceleration for specialized statistical functions (like the Gamma function) on TPUs.
Summary updated