- Introduced by
- Danilo Rezende & Shakir Mohamed
- Year
- 2015
- Type
- Generative model via invertible transformations
- Family
- Generative models
What does it do?
Normalizing flows are generative models that learn a complex probability distribution by applying a sequence of invertible, differentiable transformations to a simple base distribution such as a standard Gaussian.
Rezende and Mohamed (2015) applied them to variational inference, where they build more flexible approximate posteriors. Because the density of the transformed variable can be computed exactly, flows offer a likelihood-based alternative to VAEs for density estimation and generation.
The intuition behind the method
Imagine starting with a simple blob of probability mass—a standard Gaussian—and progressively squeezing, stretching, and bending it through a chain of invertible operations until it matches the shape of your complex data distribution. Because every step is invertible, you can always trace the path back, which lets you compute exactly how much probability mass ended up at any given point. This two-way street between simple and complex is the core intuition behind normalizing flows.
History
The change-of-variables principle on which flows rely is a general tool of probability theory for transforming random variables. Rezende and Mohamed (2015), the work cited for the idea of normalizing flows, applied invertible transformations to improve variational posteriors. Later architectures, including NICE (2014, Dinh et al.), RealNVP (2016), Glow (2018, Kingma & Dhariwal) and Neural Autoregressive Flows (2018), extended the framework to standalone generative models, each balancing expressiveness against computational cost.
When to use it
Choose normalizing flows when you need exact, tractable likelihood evaluation together with sampling, for example in density estimation, anomaly detection, or variational inference that requires a non-Gaussian posterior. They fit continuous data. They are practical when the chosen layers have cheap log-determinants, such as coupling or autoregressive layers; with dense Jacobians, the cost rises steeply as dimension grows. They are a poor fit for discrete data without dequantization or other adaptation, and for tasks that need a latent space of lower dimension than the data, where a VAE is the more natural choice. For very high-dimensional image synthesis, diffusion or score-based models are often considered instead, because flow architectures must keep their Jacobians structured.
Limitations and considerations
- Architectural constraints: every layer must be invertible and have a Jacobian determinant that can be computed cheaply, which restricts the set of usable architectures.
- Dimensionality preservation: the latent space must have the same dimension as the data, so the dimensionality reduction that a VAE can use for compression is not available.
- Cost in high dimensions: computing or approximating Jacobian determinants becomes expensive for high-dimensional data unless structured layers such as coupling or autoregressive layers are used.
- Training stability: the log-determinant terms accumulate over the K layers, and deep stacks can suffer from numerical instability and vanishing or exploding Jacobians.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Exact likelihood evaluation: because every layer is invertible with a tractable Jacobian, the log-probability of any data point can be computed directly, whereas GANs provide no likelihood at all.
- Sampling by a forward pass: generating a sample requires passing a base-distribution draw through the K layers, with no iterative denoising. The cost per pass still depends on the architecture; some autoregressive designs are sequential in the number of dimensions.
- One model for generation and inference: the same invertible map generates samples and encodes data into the latent space, so no separate encoder and decoder are needed.
- More flexible variational posteriors: when used as the posterior in variational inference, flows can represent non-Gaussian shapes, which can reduce the gap between the bound and the true log-evidence.
Applications
- Density estimation and anomaly detection on scientific and industrial sensor data
- Expressive approximate posterior inference in deep latent variable models
- Probabilistic time-series forecasting with exact likelihood scoring
- Image generation with exact likelihood scoring (e.g., Glow)
How it works
How it works
The process begins by sampling a latent variable z_0 from a tractable base distribution, which the mechanics specify as a standard Gaussian, N(0, I). All complex data distributions are derived from this simple starting point through successive transformations.
Formula
z_0 \sim p_0(z_0), \quad p_0 = \mathcal{N}(0, I)A sequence of K invertible, differentiable functions f_1 through f_K is composed and applied to z_0 to produce z_K. Invertibility is required so that the model can map in both directions: the forward map generates samples, and the inverse map recovers the base-distribution value of a given data point when its density is evaluated.
Formula
z_K = f_K \circ f_{K-1} \circ \cdots \circ f_1(z_0), \quad \text{each } f_k \text{ invertible}The log-density of z_K is computed exactly by the change-of-variables formula. Each layer contributes a log-absolute-determinant term, the logarithm of the absolute Jacobian determinant of that layer, which records how the layer locally stretches or compresses probability mass. Summing these K terms gives the correction to the base log-density, so the result remains a properly normalized density.
Formula
\ln p_K(z_K) = \ln p_0(z_0) - \sum_{k=1}^{K} \ln \left| \det \frac{\partial f_k}{\partial z_{k-1}} \right|In variational inference, the approximate posterior is built by pushing a simple initial sample through the K invertible maps. The objective F(x) = E_{q_0}[ln q_K(z_K)] - E_{q_0}[ln p(x, z_K)] is minimized, with gradients propagated through all invertible layers. Note the sign convention: F(x) is the negative of the evidence lower bound (ELBO = -F(x)), so minimizing F is equivalent to maximizing the ELBO. The two should not be treated as the same quantity.
Formula
\mathcal{F}(x) = \mathbb{E}_{q_0}\!\left[\ln q_K(z_K)\right] - \mathbb{E}_{q_0}\!\left[\ln p(x, z_K)\right]Common pitfalls
- Choosing transformations without tractable Jacobian determinants removes the exact likelihood advantage and can make training intractable.
- Applying flows directly to discrete data breaks the continuous, differentiable mapping assumption; dequantization or a continuous embedding is needed first.
- Assuming that more flow steps always improve the model: additional depth does not guarantee better results and can make optimization harder.
- Judging sample quality by log-likelihood alone can mislead, because a high likelihood does not always correspond to perceptually good samples.
Frequently asked questions
How do normalizing flows differ from variational autoencoders?
A VAE uses an approximate encoder and decoder and optimizes a lower bound on the likelihood; its approximate posterior is typically Gaussian, which introduces an approximation gap. Normalizing flows compute the density exactly through invertible transformations. They can also be used inside a VAE to replace the Gaussian approximate posterior with a more flexible one, which tightens the bound while the decoder remains.
Why must the transformation be invertible?
Invertibility allows the change-of-variables formula to apply exactly, so the model can compute the log-density of a transformed sample by tracing it back to the simple base distribution. Without invertibility, the Jacobian determinant is undefined or intractable, which makes exact likelihood computation and density evaluation impossible.
Can normalizing flows be used for discrete data such as text?
Not directly, because the change-of-variables formula requires continuous, differentiable mappings. Practitioners typically apply dequantization, which adds continuous noise to discrete values, or work in a continuous embedding space. Discrete flow variants exist but involve additional approximations and are less mature than continuous flows.
Related methods
Sources
Rezende, D. J., & Mohamed, S. (2015). Variational inference with normalizing flows. International Conference on Machine Learning (ICML), 1530–1538.
Open publication reference