The Reparameterization Trick: Differentiable Sampling
An interactive live film: moving randomness to an external standard noise epsilon isolates the stochastic node, enabling end-to-end backpropagation with low-variance pathwise gradients.
Narration
In variational autoencoders, training requires taking gradients through an expectation over the latent variable. But standard backpropagation cannot flow through a random sampling node.
If we sample z directly from a Gaussian distribution with mean mu and standard deviation sigma, the sampling operation acts as a barrier to reverse mode differentiation.
The reparameterization trick isolates the stochasticity outside the computational graph. We draw an auxiliary random vector epsilon from a standard normal distribution that does not depend on our network parameters.
We then form z through a deterministic affine transformation: mu plus sigma multiplied by epsilon. Each line joins a sample of epsilon below to its z above. Now the path from the parameters to the loss is deterministic, and the orange arrow is the gradient step it gives.
This works for location scale families, such as the Gaussian. For discrete latent variables there is no such map, and the Gumbel softmax relaxation is used instead.
Your turn. Drag the mean, and set the two standard deviations. Follow the gradient, and bring the expected loss below one tenth.
By separating deterministic parameters from external randomness, the reparameterization trick unlocks scalable deep generative modeling.
More from Chapter 16
Preview1:27Monte Carlo: Averages That Close In Like a FunnelChapter 16
Preview1:42Mean Field: Independent Factors for a Correlated PosteriorChapter 16
Preview1:45Posterior Collapse: When Latents Vanish into the PriorChapter 16
Preview1:36Expectation Maximization: Coordinate Ascent on the Lower BoundChapter 16
Preview1:55Importance-Weighted BoundsChapter 16