TL;DR
NICE is a 2014 paper by Laurent Dinh, David Krueger and Yoshua Bengio. It learns a model of complicated high-dimensional data by learning one invertible transform that maps each data point to a code whose parts are statistically independent. Because the transform is built so that its inverse and its volume change are cheap, the model gives an exact likelihood for each example and can generate new examples by running the transform backwards. On four image datasets it gave good generative results.
Builds on: Normalizing Flow, Bijective Function, Feedforward Neural Network · Leads to: Flow Matching for Generative Modeling, Flow Straight and Fast: Learning to Generate and Transfer Data with Rectified...
Why it mattered
NICE was one of the early deep models that was a true flow: an invertible map with an exact change of variables, trained by maximum likelihood, with no sampling inside training. Many later flow models kept the idea of invertible blocks with a tractable Jacobian, and the coupling layer it introduced became a common building block of later flow architectures. The paper also made a practical point that became standard. A deterministic encoder whose inverse is exact avoids the approximate posterior and the reconstruction noise that variational autoencoders need. That point shaped how people compare flows with variational autoencoders and with the autoregressive models that were popular at the time.
The paper is also a clear example of the idea that a good representation is one in which the data is easy to model. The authors use that idea to make the code factorial, which is a strong and checkable structure, rather than only hoping that a learned code is useful.
History
By the early 2010s, generative modelling of high-dimensional data had two main routes. Undirected models such as deep Boltzmann machines were powerful, but their likelihood was intractable and their sampling was slow. Directed models such as variational autoencoders gave fast sampling with a lower bound on the likelihood. Independent component analysis had long asked a related question, whether data is a mixture of independent sources, but its classic form used orthogonal maps, which were costly to fit.
The paper's authors combined the change of variables rule with a deep, invertible map. The key engineering step was the coupling layer, whose Jacobian is triangular by construction. NICE appeared in 2014, in the same period as the variational autoencoder and the generative adversarial network, and it caught on because it gave exact likelihoods with a clear training objective. Later flow work, such as the flow-matching and rectified-flow papers linked below, continued this line of research.
The problem
A generative model should assign a probability to each data point, and it should be possible to draw new points from it. For image-like data the space has hundreds or thousands of dimensions, and the probability of a point is hard to write down. Three families were available in 2014, and each had a cost.
Undirected models such as deep Boltzmann machines need Markov chain sampling, and their likelihood is intractable, so it can only be estimated. Variational autoencoders train with a lower bound on the likelihood and use a noisy stochastic encoder. Autoregressive models give exact likelihoods, but they generate one dimension at a time, which is slow for images.
The question NICE asks is this: can we find a flexible transform whose inverse is cheap, whose volume change is cheap, and whose output has a simple distribution? If yes, the likelihood is exact, and sampling is one pass through the inverse.
How it works
The walkthrough below follows one data point and one training step through the model. Each step adds one idea.
flowchart LR X["data x (D numbers)"] --> F["encoder f: a stack of coupling layers and one scaling layer"] F --> H["code h = f(x), independent parts"] H --> P["score h under a factorial prior p_H"] P --> L["log-likelihood = log p_H(h) + log det Jacobian"] H -. "sampling: h drawn from p_H, then x = f inverse of h" .-> X
-
Start with data and a goal. Take a data point
xwithDnumbers, for example the pixels of a small image. We want a densityp_X(x). We will not model it directly. We will model a simpler densityp_Hon a codehand link the two with a maph = f(x)that can be inverted. -
Use the change of variables rule. If
fis invertible and mapsDnumbers toDnumbers, the density ofxis the density ofhtimes how muchfstretches space atx. In logarithms,log p_X(x) = log p_H(f(x)) + log |det Jacobian of f at x|. The Jacobian term is the stretch factor. It is what stops the model from cheating by squashing data into a small region. -
Choose a factorial prior. Pick
p_Hso that itsDparts are independent. Then the prior term splits into a sum of one-dimensional terms, and the code is encouraged to have independent parts. A standard logistic distribution is a common choice for each part. Check: ath = 0the logistic density is1/4, and its log is about-1.386. -
Make the Jacobian easy: a coupling layer. Split the input into two blocks,
x1andx2. Keepx1as it is and changex2by adding a function ofx1:y1 = x1andy2 = x2 + m(x1). The functionmcan be any neural network. Check: the Jacobian is a block matrix with an identity block in the top-left and a triangular structure, so its determinant is1. Check: the inverse isx2 = y2 - m(y1), which costs the same as the forward pass. -
Make every dimension change. One coupling layer leaves
x1unchanged, so the next layer swaps the roles of the two blocks. A composition of two layers changes every dimension. The paper observes that at least three coupling layers are needed for all dimensions to influence one another, and it generally uses four. -
Fix the volume problem with a scale. Every additive coupling layer has determinant
1, so their product does too. That means the model cannot change the overall volume at all. The fix is a diagonal scaling layer at the top,h_i = S_ii x_i, which adds a termlog |S_ii|for each dimension. The scale lets the model give more variation to some dimensions than others. -
Train by maximum likelihood. Sum the terms for one data point and average over the data. The training signal is only the exact log-likelihood. No sampling is needed, and no reconstruction term appears.
-
Sample. Draw
hfrom the factorial prior, then computex = f inverse of hby running the coupling layers backwards. This is ancestral sampling in the directed graphh to x, and it is one pass with no iteration.
Worked examples
Example 1 (tiny, by hand): inverting one coupling layer. Take D = 2, d = 1, and let m(x1) = 2 x1.
- Input
x = (1, 3). Herex1 = 1andx2 = 3. - The layer keeps
y1 = x1 = 1. - It computes
y2 = x2 + m(x1) = 3 + 2 * 1 = 5. So the output isy = (1, 5). - Invert:
x1 = y1 = 1. - Invert:
x2 = y2 - m(y1) = 5 - 2 * 1 = 3. We get back(1, 3).
The inverse used only one evaluation of m, the same cost as the forward pass. Interpretation: an additive coupling layer can be undone exactly, whatever m is.
Example 2 (standard): the log-likelihood of one point. Use the same layer, with a factorial logistic prior, log p(h) = -log(1 + e^h) - log(1 + e^{-h}) for each coordinate. The map has determinant 1.
- The code is
h = (1, 5), from Example 1. - For
h_1 = 1:log(1 + e) = 1.31326andlog(1 + e^{-1}) = 0.31326, solog p(1) = -1.62652. - For
h_2 = 5:log(1 + e^5) = 5.00672andlog(1 + e^{-5}) = 0.00672, solog p(5) = -5.01343. - Add the two prior terms:
log p_H(h) = -1.62652 - 5.01343 = -6.63995. - The log-determinant is
log 1 = 0. - So
log p_X(x) = -6.63995, about-6.64.
Interpretation: the point (1, 3) lies in a region where this toy model puts low density, because h_2 = 5 is far out in the tail of the logistic prior. A better m would move h_2 toward the centre of the prior and raise the score.
Example 3 (realistic): a scaled model on images. The paper's MNIST model uses four coupling layers, each with a network of five hidden layers of 1000 rectified units, then a diagonal scale. Dequantisation adds uniform noise of size 1/256 to each pixel, and the data is rescaled to [0, 1], so that discrete pixel values become a continuous density. The paper reports a test log-likelihood of 1980.50 on MNIST.
- Dequantise: add noise of size
1/256to each pixel (the MNIST setting), so the data is continuous. - Rescale to
[0, 1]^D, the domain of the prior. - Apply four coupling layers, alternating which half of the pixels is changed, with
m^(1)tom^(4)each a five-layer network. - Apply the diagonal scale
exp(s)on top. Its log-determinant is\sum_i s_i, which is the term the training objective adds. - Score the code under the logistic prior and add the terms.
- Average over the training set. The paper trained with Adam, learning rate
10^{-3}, and kept the best validation model after 1500 epochs.
Try it: a coupling layer with m(x1) = -x1 takes the input x = (2, 4) to an output y. Compute y, then apply the inverse to y and check that you get (2, 4) back. Answer: m(x1) = -2, so y1 = 2 and y2 = 4 + (-2) = 2, giving y = (2, 2). The inverse keeps x1 = y1 = 2 and gives x2 = y2 - m(y1) = 2 - (-2) = 4, so (2, 4) comes back. The inverse subtracts the same quantity the forward pass added.
The math
Definition (NICE criterion). Let f be an invertible map from D numbers to D numbers with components f_d, and let p_H be a factorial prior with densities p_{H_d}. The NICE model defines the density of x as
The first sum is the prior term. The last term is the log of the stretch factor. Training maximises this quantity over the data set.
Step 2 in symbols: the change of variables
If h = f(x), the Jacobian matrix J has entries J_ij = \partial f_i / \partial x_j. The density of x is p_X(x) = p_H(f(x)) |det J|. Taking logs gives the formula above. The determinant of a triangular matrix is the product of its diagonal entries, which is why the architecture is designed around triangular Jacobians.
Step 4 in symbols: the additive coupling layer
Write x = (x1, x2) with x1 of size d and x2 of size D - d. The layer is
Its Jacobian is
a block lower-triangular matrix with ones on the diagonal. Its determinant is 1, so log |det| = 0. The inverse is x_1 = y_1 and x_2 = y_2 - m(y_1).
Step 5 in symbols: composing layers
If f = f_L \circ \cdots \circ f_1, the Jacobian of f is the product of the Jacobians of the layers, and the log-determinant is the sum of the layer log-determinants. For additive coupling layers that sum is zero. For the scale layer it is \sum_i \log |S_ii|. So the whole model's log-determinant is
Step 6 in symbols: the scaled criterion
With the scaling layer on top, the NICE criterion becomes
Larger S_ii makes h_i larger, which the prior term penalises, while the determinant term log |S_ii| rewards it, so training balances the two. The paper relates these scale values to the eigenspectrum of PCA: a large S_ii marks a dimension with little variation, which is an unimportant direction.
Step 8 in symbols: sampling
Sampling draws h_d from p_{H_d} independently for each d, and returns x = f^{-1}(h). The inverse of each layer is applied in reverse order.
Results
The paper trains on four datasets: MNIST, the Toronto Face Dataset (TFD), Street View House Numbers (SVHN) and CIFAR-10. The reported test log-likelihoods are:
| Dataset | Test log-likelihood (paper) |
|---|---|
| MNIST | 1980.50 |
| TFD | 5514.71 |
| SVHN | 11496.55 |
| CIFAR-10 | 5371.78 |
For TFD and CIFAR-10 the paper compares with the best results it knew of, from deep mixtures of factor analysers: 5250 on TFD and 3622 on CIFAR-10. The paper notes that those numbers are lower bounds, not exact log-likelihoods, so the comparison is not like-for-like. For MNIST the paper says no fair comparison is possible, because the usual evaluation of continuous MNIST models uses Parzen window estimates.
The paper also shows unbiased samples drawn from the prior and passed through the inverse, which are the visual evidence for generation. For inpainting, the model is not trained for the task. The observed pixels are clamped to their values, and the masked pixels are found by projected gradient ascent on the likelihood. The authors describe the output as reasonable in quality but note the occasional presence of spurious modes. With middle masks there is almost no information left about the digit, so the fill-in cannot recover it.
Limits. The results are log-likelihoods on each dataset's test split after its own preprocessing: uniform noise of size 1/256 with data in for MNIST, TFD and SVHN, and noise of size 1/128 with data in for CIFAR-10. Different preprocessing gives different log-likelihoods, so the numbers are not directly comparable across datasets. The paper selects the best model by validation log-likelihood after 1500 epochs. The paper's main claim is that the architecture gives tractable likelihood and sampling with competitive results, and that is what the numbers support.
Common mistakes and tradeoffs
It is tempting to think that a good likelihood means the model has learned a good code. In fact the likelihood can rise by squashing data into a small region, which is what the Jacobian term prevents, because it penalises contraction. Only the combination of the prior term and the Jacobian term gives a meaningful score.
It is tempting to think that a coupling layer with a deep network inside is slow to invert. In fact the inverse of an additive coupling layer costs the same as its forward pass, because m is only evaluated, never inverted.
It is tempting to think that one coupling layer is enough. In fact one layer leaves one block unchanged, and at least three are needed for all dimensions to influence one another.
It is tempting to think that the scale layer is optional. In fact without a scale, every additive coupling layer has unit determinant, so the model cannot change volume, and the likelihood cannot reflect how much variation each dimension has.
Tradeoffs. NICE gives an exact likelihood and one-pass sampling, and its training is simple. Its layers must be invertible, which limits the design, and each layer keeps half the input unchanged. Compared with autoregressive models, which generate one dimension at a time, NICE samples in one pass through the inverse. Use a flow like this when exact likelihood and fast sampling matter and the data is continuous. Do not use it when the data has a very different dimension at the code level, or when a discrete model fits better.
Recap
- A change of variables turns a simple density into a complicated one, and the stretch factor keeps the density honest.
- An additive coupling layer keeps one block fixed and shifts the other by a neural function, so its inverse and its determinant are both trivial.
- At least three coupling layers, usually four, are needed so every dimension can influence every other.
- A diagonal scale restores the volume the coupling layers cannot change, and the factorial prior encourages independent code parts.
- Training maximises the exact log-likelihood, and sampling runs the inverse once.
Read next: Flow Matching for Generative Modeling and Flow Straight and Fast: Learning to Generate and Transfer Data with Rectified... for later flows built on the same invertible-map idea.
Reading guide
- Abstract and Section 1 need Normalizing Flow and Change of Variables Formula for the central equation.
- Section 2 needs Probability Density Function, Maximum Likelihood Estimation and Jacobian Matrix.
- Section 3 (architecture) needs Bijective Function, Determinant and Feedforward Neural Network, since
mis a rectified network. - Section 3.4 (prior) needs Multivariate Gaussian for the Gaussian option and Statistical Independence for the factorial prior.
- Section 4 (related methods) needs Latent Variable Model, Variational Autoencoder and Autoregressive Model.
- Section 5 (experiments) needs Generative Model for the sampling claims and Kullback–Leibler Divergence for the variational comparison.
Check yourself
QuestionWhy does an additive coupling layer have a Jacobian determinant of 1?Show answer
QuestionA coupling layer has m(x1) = 3 x1. The input is x = (2, 1). Compute the output y and check the inverse.Show answer
QuestionWhy does the NICE model need a diagonal scaling layer, when the coupling layers already give a flexible map?Show answer
QuestionA factorial logistic prior has log density -log(1 + e^h) - log(1 + e^{-h}) per coordinate. A code is h = (0, 0) and the Jacobian determinant is 1. What is the log-likelihood of x?Show answer
QuestionA data set of images is dequantised by adding uniform noise of size 1/256 to each pixel. Why is this step needed before maximum likelihood?Show answer
Sources
- Dinh, L., Krueger, D., and Bengio, Y. (2014). NICE: Non-linear Independent Components Estimation. arXiv:1410.8516. https://arxiv.org/abs/1410.8516
- Normalizing flow, Wikipedia. https://en.wikipedia.org/wiki/Normalizing_flow