InfoVAE: Information Maximizing Variational Autoencoders
Shengjia Zhao, Jiaming Song, Stefano Ermon
Introduction
Generative models have shown great promise in modeling complex distributions such as natural images and text (Radford et al., 2015; Zhu et al., 2017; Yang et al., 2017; Li et al., 2017). These are directed graphical models which represent the joint distribution between the data and a set of hidden variables (features) capturing latent factors of variation. The joint is factored as the product of a prior over the latent variables and a conditional distribution of the visible variables given the latent ones. Usually a simple prior distribution is provided for the latent variables, while the distribution of the input conditioned on latent variables is complex and modeled with a deep network.
Both learning and inference are generally intractable. However, using an amortized approximate inference distribution it is possible to use the evidence lower bound (ELBO) to efficiently optimize both (a lower bound to) the marginal likelihood of the data and the quality of the approximate inference distribution. This leads to a very successful class of models called variational autoencoders (Kingma & Welling, 2013; Jimenez Rezende et al., 2014; Kingma et al., 2016; Burda et al., 2015).
However, variational autoencoders have several problems. First, the approximate inference distribution is often significantly different from the true posterior. Previous methods have resorted to using more flexible variational families to better approximate the true posterior distribution (Kingma et al., 2016). However we find that the problem is rooted in the ELBO training objective itself. In fact, we show that the ELBO objective favors fitting the data distribution over performing correct amortized inference. When the two goals are conflicting (e.g., because of limited capacity), the ELBO objective tends to sacrifice correct inference to better fit (or worse overfit) the training data.
Another problem that has been observed is that when the conditional distribution is sufficiently expressive, the latent variables are often ignored (Chen et al., 2016). That is, the model only uses a single conditional distribution component to model the data, effectively ignoring the latent variables and fail to take advantage of the mixture modeling capability of the VAE. In addition, one goal of unsupervised learning is to learn meaningful latent representations but this fails because the latent variables are ignored. Some solutions have been proposed in (Chen et al., 2016) by limiting the capacity of the conditional distribution, but this requires manual and problem-specific design of the features we would like to extract.
In this paper we propose a novel solution by framing both problems as explicit modeling choices: we introduce new training objectives where it is possible to weight the preference between correct inference and fitting data distribution, and specify a preference on how much the model should rely on the latent variables. This choice is implicitly made in the ELBO objective. We make this choice explicit and generalize the ELBO objective by adding additional terms that allow users to select their preference on both choices. Despite of the addition of seemingly intractable terms, we find an equivalent form that can still be efficiently optimized.
Our new family also generalizes known models including the -VAE (Higgins et al., 2016) and Adversarial Autoencoders (Makhzani et al., 2015). In addition to deriving these models as special cases, we provide generic principles for hyper-parameter selection that work well in all the experimental settings we considered. Finally we perform extensive experiments to evaluate our newly introduced model family, and compare with existing models on multiple metrics of performance such as log-likelihood, sampling quality, and semi-supervised performance. An instantiation of our general framework called MMD-VAE achieves better or on-par performance on all metrics we considered. We further observe that our model can lead to better amortized inference, and utilize the latent variables even in the presence of a very flexible decoder.
Variational Autoencoders
A latent variable generative model defines a joint distribution between a feature space , and the input space . Usually we assume a simple prior distribution over features, such as Gaussian or uniform, and model the data distribution with a complex conditional distribution , where is often parameterized with a neural network. Suppose the true underlying distribution is (that is approximated by a training set), then a natural training objective is maximum (marginal) likelihood
We further average this over the data distribution to obtain the final optimization objective
There are several ways to equivalently rewrite the ELBO objective that will become useful in our following analysis. We define the joint generative distribution as
In fact we can correspondingly define a joint “inference distribution”
Note that the two definitions are symmetrical. In the former case we start from a known distribution and learn the conditional distribution on , in the latter we start from a known (empirical) distribution and learn the conditional distribution on . We also correspondingly define any conditional and marginal distributions as follows:
For the purposes of optimization, the ELBO objective can be written equivalently (up to an additive constant) as
We prove the first equivalence in the appendix. The second and third equivalence are simple applications of the additive property of KL divergence. All three forms of ELBO in Eqns. (2),(3),(4) are useful in our analysis.
Two Problems of Variational Autoencoders
Under ideal conditions, optimizing the ELBO objective using sufficiently flexible model families for and over will achieve both goals of correctly capturing and performing correct amortized inference. This can be seen by examining Eq. (3). This form indicates that the ELBO objective is minimizing the KL divergence between the data distribution and the (marginal) model distribution , as well as the KL divergence between the variational posterior and the true posterior . However, with finite model capacity the two goals can be conflicting and subtle tradeoffs and failure modes can emerge from optimizing the ELBO objective.
In particular, one limitation of the ELBO objective is that it might fail to learn an amortized inference distribution that approximates the true posterior . This can happen for two different reasons:
Inherent properties of the ELBO objective: the ELBO objective can be maximized (even to in pathological cases) even with a very inaccurate variational posterior .
Implicit modeling bias: common modeling choices (such as the high dimensionality of compared to ) tend to sacrifice variational inference vs. data fit when modeling capacity is not sufficient to achieve both.
We will explain in turn why these failures happen.
We first provide some intuition to this phenomena, then formally prove the result for a pathological case of continuous spaces and Gaussian distributions. Finally we justify in the experiments section that this happens in realistic settings on real datasets (in both continuous and discrete spaces).
Let be a dataset with two samples , and be selected from the family of all functions that map to a Gaussian on , and be selected from the family of all functions that map to a Gaussian on . Then can be maximized to when
1.2 Modeling Bias
In the above example we indicated a potential problem with the ELBO objective where the model tends to push the probability mass of too far from . This tendency is a property of the ELBO objective and true for any and . However this is made worse by the fact that is often higher dimensional compared to , so any error in fitting will be magnified compared to .
For example, consider fitting an dimensional distribution with using KL divergence, then
Regardless of the cause (properties of ELBO or modeling choices), this is generally an undesirable phenomenon for two reasons:
1) One may care about accurate inference more than generating sharp samples. For example, generative models are often used for down stream tasks such as semi supervised learning.
2) Overfitting: Because is an empirical (finite) distribution in practice, matching it too closely can lead to poor generalization.
Both issues are observed in the experiments section.
2 The Information Preference Property
Using a complex decoding distribution such as PixelRNN/PixelCNN (van den Oord et al., 2016b; Gulrajani et al., 2016) has been shown to significantly improve sample quality on complex natural image datasets. However, this approach suffers from a new problem: it tends to neglect the latent variables altogether, that is, the mutual information between and becomes vanishingly small. Intuitively, the reason is that the learned is the same for all , implying that the is not dependent on the input . This is undesirable because a major goal of unsupervised learning is to learn meaningful latent features which should depend on the inputs.
This effect, which we shall refer to as the information preference problem, was studied in (Chen et al., 2016) with a coding efficiency argument. Here we provide an alternative interpretation, which sheds light on a novel solution to solve this problem.
We inspect the ELBO in the form of Eq.(3), and consider the two terms respectively. We show that both can be optimized to without utilizing the latent variables.
The InfoVAE Model Family
In order to remedy these two problems we define a new training objective that will learn both the correct model and amortized inference distributions. We begin with the form of ELBO in Eq. (4)
First we add a scaling parameter to the divergence between and to increase its weight and counter-act the imbalance between and (cf. discussion in section 3.1.1). Next we add a mutual information maximization term that prefers high mutual information between and . This encourages the model to use the latent code and avoids the information preference problem. We arrive at the following objective
where is the mutual information between and under the distribution .
Even though we cannot directly optimize this objective, we can rewrite this into an equivalent form that we can optimize more efficiently (We prove this in the Appendix)
Note that in the proposition we have the additional requirement that the mutual information is bounded. This is inevitable because if the objective can be optimized to by simply increasing the mutual information infinitely. In our experiments simply ensuring that does not have vanishing variance is sufficient to regularize the behavior of the model.
Relation to Adversarial Autoencoders (AAE): When , and is chosen to be the Jensen Shannon divergence we get the adversarial autoencoders in (Makhzani et al., 2015). This paper generalizes AAE, but more importantly we provide a deeper understanding of the correctness and desirable properties of AAE. Furthermore, we characterize settings when AAE is preferable compared to VAE (i.e. when we would like to have ).
Our generalization introduces new parameters, but the meaning and effect of the various parameter choices is clear. We recommend setting to a value that makes the loss on approximately the same as the loss on . We also recommend setting when is a simple distribution, and when is a complex distribution and information preference is a concern. The final degree of freedom is the divergence to use. We will explore this topic in the next section. We will also show in the experiments that this design choice is also easy to choose: there is a choice that we find to be consistently better in almost all metrics of performance.
We consider and compare three divergences in this paper.
Adversarial Training: Adversarial autoencoders (AAE) proposed in (Makhzani et al., 2015) use an adversarial discriminator to approximately minimize the Jensen-Shannon divergence (Goodfellow et al., 2014) between and . However, when is a simple distribution such as Gaussian, there are preferable alternatives. In fact, adversarial training can be unstable and slow even when we apply recent techniques for stabilizing GAN training (Arjovsky et al., 2017; Gulrajani et al., 2017).
Maximum-Mean Discrepancy: Maximum-Mean Discrepancy (MMD) (Gretton et al., 2007; Li et al., 2015; Dziugaite et al., 2015) is a framework to quantify the distance between two distributions by comparing all of their moments. It can be efficiently implemented using the kernel trick. Letting be any positive definite kernel, the MMD between and is
Experiments
We first perform some simple experiments on toy data and MNIST to demonstrate that ELBO suffers from inaccurate inference in practice, and adding the scaling term in Eq.(5) can correct for this. Next, we will perform a comprehensive set of experiments to carefully compare different models on multiple performance metrics.
We verify the conclusions in Proposition 1 by using the same setting in that proposition. We use a three layer deep network with 200 hidden units in each layer to simulate the highly flexible function family. For InfoVAE we choose the scaling coefficient , information preference , and divergence optimized by MMD.
The results are shown in Figure 1. It can be observed that the predictions of the theory are reflected in the experiments: ELBO training leads to poor inference and a significantly over-estimated , while InfoVAE demonstrates a more stable behavior.
1.2 MNIST
To make this more intuitive we plot in Figure 3 the contour plot of when training on 500 examples. It can be seen that with ELBO matches very poorly, while InfoVAE matches significantly better.
To verify that ELBO trains inaccurate amortized inference we plot in Figure 4 the comparison between samples from the approximate posterior and samples from the true posterior computed by rejection sampling. The same trend can be observed. ELBO consistently gives very poor approximate posterior, while the InfoVAE posterior is mostly accurate.
Finally show the samples generated by the two models in Figure 5. ELBO generates very sharp reconstructions, but very poor samples when sampled ancestrally . InfoVAE, on the other hand, generates samples of consistent quality, and in fact, produces samples of reasonable quality after only training on a dataset of 500 examples. This reflect InfoVAE’s ability to control overfitting and demonstrate consistent training time and testing time behavior.
2 Comprehensive Comparison
In this section, we perform extensive qualitative and quantitative experiments on the binarized MNIST dataset to evaluate the performance of different models. We would like to answer these questions:
1) Compare the models on a comprehensive set of numerical metrics of performance. Also compare the stability and training speed of different models.
2) Evaluate and compare the possible types of divergences (Adversarial, Stein, MMD).
For all two questions, we find InfoVAE with MMD regularization to perform better in almost all metrics of performance and demonstrate the best stability and training speed. The details are presented in the following sections.
For models we use ELBO, Adversarial autoencoders, InfoVAE with Stein variational gradient, and InfoVAE with MMD ( because information preference is a concern, which can put the loss on and on the same order of magnitude). In this setting we also use a highly flexible PixelCNN as the decoder so that information preference is also a concern. Detailed experimental setup is explained in the Appendix.
We consider multiple quantitative evaluations, including the quality of the samples generated, the training speed and stability, the use of latent features for semi-supervised learning, and log-likelihoods on samples from a separate test set.
Distance between and : To measure how well approximates , we use two numerical metrics. The first is the full batch MMD statistic over the full data. Even though MMD is also used during training of MMD-VAE, it is too expensive to train using the full dataset, so we only use mini-batches for training. However during evaluation we can use the full dataset to obtain more accurate estimates. The second is the log determinant of the covariance matrix of . Ideally when is the standard Gaussian should be the identity matrix, so . In our experiments we plot the log determinant divided by the dimensionality of the latent space. This measures the average under/over estimation per dimension of the learned covariance.
The results are plotted in Figure 6 (A,B). This is different from the experiments in Figure 2 because in this case the decoder is a highly complex pixel recurrent model and the concern that we highlight is failure to use latent features rather than inaccurate posterior. MMD achieves the best performance except for ELBO. Even though ELBO achieves extremely low error, this is trivial because for this experimental setting of flexible decoders, ELBO learns a latent code that does not contain any information about , and for all .
Sample distribution: If the generative model has true marginal , then the distribution of different object classes should also follow the distribution of classes in the original dataset. On the other hand, an incorrect generative model is unlikely to generate a class distribution that is identical to the ground truth. We let denote the class distribution in the real dataset, and denote the class distribution of the generated images, computed by a pretrained classifier. We use cross entropy loss to measure the deviation from the true class distribution.
The results for this metric are plotted in Figure 6 (C). In general, Stein regularization performs well only with a small latent space with 2 dimensions, whereas the adversarial regularization performs better with larger dimensions; MMD regularization generally performs well in all the cases and the performance is stable with respect to the latent code dimensions.
Training Speed and Stability: In general we would prefer a model that is stable, trains quickly and requires little hyperparameter tuning. In Figure 6 (D) we plot the change of MMD statistic vs. the number of iterations. In this respect, adversarial autoencoder becomes less desirable because it takes much longer to converge, and sometimes converges to poor results even if we consider more power GAN training techniques such as Wasserstein GAN with gradient penalty (Gulrajani et al., 2017).
Log likelihood: To be consistent with previous results, we use the stochastically binarized version first used in (Salakhutdinov & Murray, 2008). Estimation of log likelihood is achieved by importance sampling. We use 5-dimensional latent features in our log likelihood experiments. The values are shown in Table 1. Our results are slightly worse than reported in PixelRNN (van den Oord et al., 2016b), which achieves a log likelihood of 79.2. However, all the regularizations perform on-par or superior compared to our ELBO baseline. This is somewhat surprising because we do not explicitly optimize a lower bound to the true log likelihood, unless we are using the ELBO objective.
Conclusion
Despite the recent success of variational autoencoders, they can fail to perform amortized inference, or learn meaningful latent features. We trace both issues back to the ELBO learning criterion, and modify the ELBO objective to propose a new model family that can fix both problems. We perform extensive experiments to verify the effectiveness of our approach. Our experiments show that a particular subset of our model family, MMD-VAEs perform on-par or better than all other approaches on multiple metrics of performance.
Acknowledgements
We thank Daniel Levy, Rui Shu, Neal Jean, Maria Skoularidou for providing constructive feedback and discussions.
References
Appendix A Proofs
where the unique valid solution is , therefore optimally
Let the dataset contain two samples , and be arbitrary one dimensional Gaussians, then by symmetry of the problem, at optimality for , we have
The optimal solution is achieved where
where the unique valid solution is , therefore optimally
Where is the tail probability of a Gaussian. In the limit , we have
Then in the limit of ,
Notice that by our condition of , we have . For convenience we will rename
In addition we consider our objective in two separate terms
We will prove that whenever , the two terms are maximized under the condition in the proposition respectively. First consider , because :
Therefore for any , that optimizes satisfies , , and we have for any given , the optimal is
where we use to denote the entropy of . Notice that is dependent on only by therefore when , is maximized regardless of the choice of . So we only have to independently maximize subject to fixed . Notice that is maximized when , and we show that this can be achieved. When is sufficiently flexible we simply have to partition the support set of into subsets , so that each subset satisfies . Similarly we partition the support set of into subsets , so that each subset satisfies . Then we construct mapping each to as follows
such that for any . It is easy to see that this distribution is normalized because
Also it is easy to see that . In addition
Therefore we have constructed a so that we have reached the maximum for both objectives
so there sum must also be maximized. Under this optimal solution we have that and , this implies , which implies that both and . ∎
Appendix B Stein Variational Gradient
as shown in Lemma 3.2 in (Liu & Wang, 2016). Intuitively is the steepest direction that transforms towards . In practice, can be represented by the particles in a mini-batch.
We propose to use Stein variational gradient to regularize variational autoencoders using the following process. For a mini-batch , we compute the corresponding mini-batch features . Based on this mini-batch we compute the Stein gradients by empirical samples
The gradients wrt. the model parameters are
In practice we can define a surrogate loss
where indicates that this term is treated as a constant during back propagation. Note that this is not really a divergence, but simply a convenient loss function that we can implement using standard automatic differentiation software, whose gradient is the Stein variational gradient of the true KL divergence.
Appendix C Experimental Setup
In all our experiments in Section 5.2, we choose the prior to be a Gaussian with zero mean and identity covariance, to be a PixelCNN conditioned on the latent code (van den Oord et al., 2016a), and to be a CNN where the final layer outputs the mean and standard deviation of a factored Gaussian distribution.
For MNIST we use a simplified version of the conditional PixelCNN architecture (van den Oord et al., 2016a). For CIFAR we use the public implementation of PixelCNN++ (Salimans et al., 2017). In either case we use a convolutional encoder with the same architecture as (Radford et al., 2015) to generate the latent code, and plug this into the conditional input for both models. The entire model is trained end to end by Adam (Kingma & Ba, 2014). PixelCNN on ImageNet take about 10h to train to convergence on a single Titan X, and CIFAR take about two days to train to convergence. We will make the code public upon publication.
Appendix D CIFAR Samples
We additional perform experiments on the CIFAR (Krizhevsky & Hinton, 2009) dataset. We show samples from models with different regularization methods - ELBO, MMD, Stein and Adversarial in Figure 7. In all cases, the model accurately matches with , and samples generated with Stein regularization and MMD regularization are more coherent globally compared to the samples generated with ELBO regularization.