Skip to content
tezvyn:
Menu

Normalizing Flows: Shaping Simple Distributions into Complex Ones

Source: Wikipedia: Normalizing flowHardHow cards are made

Normalizing flows transform a simple probability distribution, like a Gaussian, into a complex one, like images. This allows generative models to explicitly calculate the probability of any data point. The footgun is that the transformation must be invertible.

Why it exists

Many generative models like GANs can create realistic data but cannot tell you the probability of a specific data point. Other models provide only an approximation. Normalizing flows were developed to create generative models that can compute the exact probability density of the data, which is critical for many statistical tasks.

The mental model

A normalizing flow is a sequence of invertible transformations. Imagine taking a simple, known probability distribution, like a uniform blob of points, and applying a series of learned "stretches" and "squishes". These operations "flow" the simple distribution into a shape that matches your complex target data distribution, such as images of faces. Because each step is invertible, you can always reverse the process.

How it works

A normalizing flow uses the change of variables formula from statistics to transform a simple distribution into a complex one. A model, f, maps a simple variable, z, from a known distribution (like a Gaussian) to a data point, x = f(z). The formula allows for computing the exact probability of x by using the probability of z and the determinant of the Jacobian of the inverse transformation. This requires the transformation to be invertible and its Jacobian determinant to be easy to compute, which heavily constrains the neural network design.

When to use it

Use a normalizing flow when you need a generative model that provides exact, tractable likelihoods. This is crucial for tasks like anomaly detection (low likelihood points are anomalies), data compression, and when you need a principled way to evaluate how well your model fits the data. They are used in flow-based generative models to explicitly model a probability distribution.

When not to use it

Avoid normalizing flows if your primary goal is just sample generation and you don't need exact likelihoods; other models are often more efficient for that specific task. The architectural constraints (invertibility, tractable Jacobian) can make them less expressive or slower to train than other generative models for a given parameter count.

One canonical example

A flow-based model like Glow can be trained on a dataset of faces. After training, you can sample a random vector from a simple Gaussian distribution, pass it through the trained flow, and generate a new, realistic-looking face. Crucially, you can also take an existing image of a face, pass it backward through the flow, and get its exact log-probability under the model's learned distribution.

Interview question

What is the primary advantage of Normalizing Flows over other generative models like GANs?

  • a.They can learn complex distributions without requiring invertible transformations.
  • b.They are capable of generating higher-resolution images with fewer artifacts.
  • c.They provide an explicit and exact calculation of the probability density for any data point.Correct
  • d.They are generally simpler to implement and require less computational power for training.
Why?

Normalizing flows are unique in their ability to compute the exact probability density of data points, which is crucial for tasks like anomaly detection. Other generative models often only approximate this or cannot compute it at all, and normalizing flows can be slower to train due to their architectural constraints.

Just read this? Test yourself on what you have been reading.

Read the original → en.wikipedia.org

Put your scrolling time to good use

Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on machine learning — each one lists the topics its interview covers.

See open roles