Deep learning generative model to encode data representation
The basic scheme of a variational autoencoder. The model receives as input. The encoder compresses it into the latent space. The decoder receives as input the information sampled from the latent space and produces as similar as possible to.
In addition to being seen as anautoencoder neural network architecture, variational autoencoders can also be studied within the mathematical formulation ofvariational Bayesian methods, connecting a neural encoder network to its decoder through a probabilisticlatent space (for example, as amultivariate Gaussian distribution) that corresponds to the parameters of a variational distribution.
Thus, the encoder maps each point (such as an image) from a large complex dataset into a distribution within the latent space, rather than to a single point in that space. The decoder has the opposite function, which is to map from the latent space to the input space, again according to a distribution (although in practice, noise is rarely added during the decoding stage). By mapping a point to a distribution instead of a single point, the network can avoid overfitting the training data. Both networks are typically trained together with the usage of thereparameterization trick, although the variance of the noise model can be learned separately.[citation needed]
A variational autoencoder is a generative model with a prior and noise distribution respectively. Usually such models are trained using theexpectation-maximization meta-algorithm (e.g.probabilistic PCA, (spike & slab) sparse coding). Such a scheme optimizes a lower bound of the data likelihood, which is usually computationally intractable, and in doing so requires the discovery of q-distributions, or variationalposteriors. These q-distributions are normally parameterized for each individual data point in a separate optimization process. However, variational autoencoders use a neural network as an amortized approach to jointly optimize across data points. In that way, the same parameters are reused for multiple data points, which can result in massive memory savings. The first neural network takes as input the data points themselves, and outputs parameters for the variational distribution. As it maps from a known input space to the low-dimensional latent space, it is called the encoder.
The decoder is the second neural network of this model. It is a function that maps from the latent space to the input space, e.g. as the means of the noise distribution. It is possible to use another neural network that maps to the variance, however this can be omitted for simplicity. In such a case, the variance can be optimized with gradient descent.
To optimize this model, one needs to know two terms: the "reconstruction error", and theKullback–Leibler divergence (KL-D). Both terms are derived from the free energy expression of the probabilistic model, and therefore differ depending on the noise distribution and the assumed prior of the data, here referred to as p-distribution. For example, a standard VAE task such as IMAGENET is typically assumed to have a gaussianly distributed noise; however, tasks such as binarized MNIST require a Bernoulli noise. The KL-D from the free energy expression maximizes the probability mass of the q-distribution that overlaps with the p-distribution, which unfortunately can result in mode-seeking behaviour. The "reconstruction" term is the remainder of the free energy expression, and requires a sampling approximation to compute its expectation value.[8]
From the point of view of probabilistic modeling, one wants to maximize the likelihood of the data by their chosen parameterized probability distribution. This distribution is usually chosen to be a Gaussian which is parameterized by and respectively, and as a member of the exponential family it is easy to work with as a noise distribution. Simple distributions are easy enough to maximize, however distributions where a prior is assumed over the latents results in intractable integrals. Let us find viamarginalizing over.
where represents thejoint distribution under of the observable data and its latent representation or encoding. According to thechain rule, the equation can be rewritten as
In the vanilla variational autoencoder, is usually taken to be a finite-dimensional vector of real numbers, and to be aGaussian distribution. Then is a mixture of Gaussian distributions.
It is now possible to define the set of the relationships between the input data and its latent representation as
Prior
Likelihood
Posterior
Unfortunately, the computation of is expensive and in most cases intractable. To speed up the calculus to make it feasible, it is necessary to introduce a further function to approximate the posterior distribution as
with defined as the set of real values that parametrize. This is sometimes calledamortized inference, since by "investing" in finding a good, one can later infer from quickly without doing any integrals.
In this way, the problem is to find a good probabilistic autoencoder, in which the conditional likelihood distribution is computed by theprobabilistic decoder, and the approximated posterior distribution is computed by theprobabilistic encoder.
Like manydeep learning approaches that use gradient-based optimization, VAEs require a differentiable loss function to update the network weights throughbackpropagation.
For variational autoencoders, the idea is to jointly optimize the generative model parameters to reduce the reconstruction error between the input and the output, and to make as close as possible to. As reconstruction loss,mean squared error andcross entropy are often used.
As distance loss between the two distributions the Kullback–Leibler divergence is a good choice to squeeze under.[8][9]
The distance loss just defined is expanded as
Now define theevidence lower bound (ELBO):Maximizing the ELBOis equivalent to simultaneously maximizing and minimizing. That is, maximizing the log-likelihood of the observed data, and minimizing the divergence of the approximate posterior from the exact posterior.
The form given is not very convenient for maximization, but the following, equivalent form, is:where is implemented as, since that is, up to an additive constant, what yields. That is, we model the distribution of conditional on to be a Gaussian distribution centered on. The distribution of and are often also chosen to be Gaussians as and, with which we obtain by the formula forKL divergence of Gaussians:Here is the dimension of. For a more detailed derivation and more interpretations of ELBO and its maximization, seeits main page.
The scheme of the reparameterization trick. The randomness variable is injected into the latent space as external input. In this way, it is possible to backpropagate the gradient without involving stochastic variable during the update.
To efficiently search forthe typical method isgradient ascent.
It is straightforward to findHowever,does not allow one to put the inside the expectation, since appears in the probability distribution itself. Thereparameterization trick (also known as stochastic backpropagation[10]) bypasses this difficulty.[8][11][12]
The most important example is when is normally distributed, as.
The scheme of a variational autoencoder after the reparameterization trick
Since we reparametrized, we need to find. Let be the probability density function for, then[clarification needed]where is the Jacobian matrix of with respect to. Since, this is
Many variational autoencoders applications and extensions have been used to adapt the architecture to other domains and improve its performance.
-VAE is an implementation with a weighted Kullback–Leibler divergence term to automatically discover and interpret factorised latent representations. With this implementation, it is possible to force manifold disentanglement for values greater than one. This architecture can discover disentangled latent factors without supervision.[13][14]
The conditional VAE (CVAE), inserts label information in the latent space to force a deterministic constrained representation of the learned data.[15]
Some structures directly deal with the quality of the generated samples[16][17] or implement more than one latent space to further improve the representation learning.
After the initial work of Diederik P. Kingma andMax Welling,[22] several procedures were proposed to formulate in a more abstract way the operation of the VAE. In these approaches the loss function is composed of two parts :
the usual reconstruction error part which seeks to ensure that the encoder-then-decoder mapping is as close to the identity map as possible; the sampling is done at run time from the empirical distribution of objects available (e.g., for MNIST or IMAGENET this will be the empirical probability law of all images in the dataset). This gives the term:.
a variational part that ensures that, when the empirical distribution is passed through the encoder, we recover the target distribution, denoted here that is usually taken to be aMultivariate normal distribution. We will denote thispushforward measure which in practice is just the empirical distribution obtained by passing all dataset objects through the encoder. In order to make sure that is close to the target, aStatistical distance is invoked and the term is added to the loss.
We obtain the final formula for the loss:
The statistical distance requires special properties, for instance it has to be posses a formula as expectation because the loss function will need to be optimized bystochastic optimization algorithms. Several distances can be chosen and this gave rise to several flavors of VAEs:
the sliced Wasserstein distance used by S Kolouri, et al. in their VAE[23]
theenergy distance implemented in the Radon Sobolev Variational Auto-Encoder[24]
^Dilokthanakul, Nat; Mediano, Pedro A. M.; Garnelo, Marta; Lee, Matthew C. H.; Salimbeni, Hugh; Arulkumaran, Kai; Shanahan, Murray (2017-01-13). "Deep Unsupervised Clustering with Gaussian Mixture Variational Autoencoders".arXiv:1611.02648 [cs.LG].
^Kingma, Diederik P.; Welling, Max (2022-12-10). "Auto-Encoding Variational Bayes".arXiv:1312.6114 [stat.ML].
^Kolouri, Soheil; Pope, Phillip E.; Martin, Charles E.; Rohde, Gustavo K. (2019)."Sliced Wasserstein Auto-Encoders".International Conference on Learning Representations. International Conference on Learning Representations. ICPR.
^Gretton, A.; Li, Y.; Swersky, K.; Zemel, R.; Turner, R. (2017). "A Polya Contagion Model for Networks".IEEE Transactions on Control of Network Systems.5 (4):1998–2010.arXiv:1705.02239.doi:10.1109/TCNS.2017.2781467.
Kingma, Diederik P.; Welling, Max (2019). "An Introduction to Variational Autoencoders".Foundations and Trends in Machine Learning.12 (4). Now Publishers:307–392.arXiv:1906.02691.doi:10.1561/2200000056.ISSN1935-8237.