Jump to content

Reparameterization trick

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Cosmia Nebula (talk | contribs) at 03:17, 23 September 2024 (Variational autoencoder: full detail). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

The reparameterization trick (aka "reparameterization gradient estimator" or "pathwise derivative") is a technique used in machine learning, particularly in variational inference and stochastic optimization. It allows for the efficient computation of gradients through random variables, enabling the optimization of parametric probability models using stochastic gradient descent, and also in variance reduction of estimators.

This trick has been used in various machine learning applications, most notably in variational autoencoders (VAEs).

Mathematics

Let be a random variable with distribution , where are the parameters of the distribution. The reparameterization trick expresses as:Here, is a deterministic function parameterized by , and is a noise variable drawn from a fixed distribution .

REINFORCE estimator

Consider an objective function of the form:Without the reparameterization trick, estimating the gradient can be challenging, because the parameter appears in the random variable itself. In more detail, we haveThe REINFORCE estimator, widely used in reinforcement learning,[1] estimates the gradient byThis allows the gradient to be estimated:

The REINFORCE estimator has high variance, and many methods were developed to reduce its variance.[2]

Reparametrization estimator

With the reparameterization trick, we rewrite the expectation as:Now, the gradient can be estimated as:

Examples

For some common distributions, the reparameterization trick takes specific forms:

Normal distribution: For , we can use:

Exponential distribution: For , we can use:Discrete distribution can be reparametrized by the Gumbel distribution ("Gumbel-max trick" or "concrete distribution").[3]

The Gamma Beta, Dirichlet, and von Mises distributions, can be reparametrized by the implicit method proposed by Figurnov et al.[4]

Applications

Variational autoencoder

In Variational Autoencoders (VAEs), the VAE objective function, known as the Evidence Lower Bound (ELBO), is given by:

where is the encoder (recognition model), is the decoder (generative model), and is the prior distribution over latent variables. The gradient of ELBO with respect to is simplybut the gradient with respect to requires the trick. Express the sampling operation as:where and are the outputs of the encoder network, and denotes element-wise multiplication. Then we havewhere . This allows us to estimate the gradient using Monte Carlo sampling:where and for .

This formulation enables backpropagation through the sampling process, allowing for end-to-end training of the VAE model using stochastic gradient descent or its variants.

Variational inference

More generally, the trick allows using stochastic gradient descent for generic variational inference. Let the variational objective (ELBO) is be of the form:Using the reparameterization trick, we can estimate the gradient of this objective with respect to using Monte Carlo sampling:

Dropout

The reparameterization trick has been applied to reduce the variance in dropout, a regularization technique in neural networks. In variational dropout,[5] the dropout operation is reparameterized as:where is the weight matrix, is the input, and are the dropout rates.

The local reparameterization trick reduces its variance by pushing the noise to the activations:where and , with and being the mean and variance of the -th output neuron.

See also

References

  1. ^ Williams, Ronald J. (1992-05-01). "Simple statistical gradient-following algorithms for connectionist reinforcement learning". Machine Learning. 8 (3): 229–256. doi:10.1007/BF00992696. ISSN 1573-0565.
  2. ^ Greensmith, Evan; Bartlett, Peter L.; Baxter, Jonathan (2004). "Variance Reduction Techniques for Gradient Estimates in Reinforcement Learning". Journal of Machine Learning Research. 5 (Nov): 1471–1530. ISSN 1533-7928.
  3. ^ Maddison, Chris J.; Mnih, Andriy; Teh, Yee Whye (2017-03-05), The Concrete Distribution: A Continuous Relaxation of Discrete Random Variables, doi:10.48550/arXiv.1611.00712, retrieved 2024-09-23
  4. ^ Figurnov, Mikhail; Mohamed, Shakir; Mnih, Andriy (2018). "Implicit Reparameterization Gradients". Advances in Neural Information Processing Systems. 31. Curran Associates, Inc.
  5. ^ Kingma, Durk P; Salimans, Tim; Welling, Max (2015). "Variational Dropout and the Local Reparameterization Trick". Advances in Neural Information Processing Systems. 28.

Further reading