Log In Sign Up

Amortized Inference Regularization

The variational autoencoder (VAE) is a popular model for density estimation and representation learning. Canonically, the variational principle suggests to prefer an expressive inference model so that the variational approximation is accurate. However, it is often overlooked that an overly-expressive inference model can be detrimental to the test set performance of both the amortized posterior approximator and, more importantly, the generative density estimator. In this paper, we leverage the fact that VAEs rely on amortized inference and propose techniques for amortized inference regularization (AIR) that control the smoothness of the inference model. We demonstrate that, by applying AIR, it is possible to improve VAE generalization on both inference and generative performance. Our paper challenges the belief that amortized inference is simply a mechanism for approximating maximum likelihood training and illustrates that regularization of the amortization family provides a new direction for understanding and improving generalization in VAEs.


page 1

page 2

page 3

page 4


MAE: Mutual Posterior-Divergence Regularization for Variational AutoEncoders

Variational Autoencoder (VAE), a simple and effective deep generative mo...

Learnable Explicit Density for Continuous Latent Space and Variational Inference

In this paper, we study two aspects of the variational autoencoder (VAE)...

Quasi-symplectic Langevin Variational Autoencoder

Variational autoencoder (VAE) as one of the well investigated generative...

Importance Weighted Autoencoders

The variational autoencoder (VAE; Kingma, Welling (2014)) is a recently ...

Reducing the Amortization Gap in Variational Autoencoders: A Bayesian Random Function Approach

Variational autoencoder (VAE) is a very successful generative model whos...

HyperSPNs: Compact and Expressive Probabilistic Circuits

Probabilistic circuits (PCs) are a family of generative models which all...

Evaluating Combinatorial Generalization in Variational Autoencoders

We evaluate the ability of variational autoencoders to generalize to uns...

1 Introduction

Variational autoencoders are a class of generative models with widespread applications in density estimation, semi-supervised learning, and representation learning

kingma2013auto ; kingma2014semi ; kim2018disentangling ; chen2018isolating . A popular approach for the training of such models is to maximize the log-likelihood of the training data. However, maximum likelihood is often intractable due to the presence of latent variables. Variational Bayes resolves this issue by constructing a tractable lower bound of the log-likelihood and maximizing the lower bound instead. Classically, Variational Bayes introduces per-sample approximate proposal distributions that need to be optimized using a process called variational inference. However, per-sample optimization incurs a high computational cost. A key contribution of the variational autoencoding framework is the observation that the cost of variational inference can be amortized by using an amortized inference model that learns an efficient mapping from samples to proposal distributions. This perspective portrays amortized inference as a tool for efficiently approximating maximum likelihood training. Many techniques have since been proposed to expand the expressivity of the amortized inference model in order to better approximate maximum likelihood training kim2018semi ; kingma2016improved ; sonderby2016ladder ; burda2015importance .

In this paper, we challenge the conventional role that amortized inference plays in variational autoencoders. For datasets where the generative model is prone to overfitting, we show that having an amortized inference model actually provides a new and effective way to regularize maximum likelihood training. Rather than making the amortized inference model more expressive, we propose instead to restrict the capacity of the amortization family. Through amortized inference regularization (AIR), we show that it is possible to reduce the inference gap and increase the log-likelihood performance on the test set. We propose several techniques for AIR and provide extensive theoretical and empirical analyses of our proposed techniques when applied to the variational autoencoder and the importance-weighted autoencoder. By rethinking the role of the amortized inference model, amortized inference regularization provides a new direction for studying and improving the generalization performance of latent variable models.

2 Background and Notation

2.1 Variational Inference and the Evidence Lower Bound

Consider a joint distribution

parameterized by , where is observed and

is latent. Given a uniform distribution

over the dataset , maximum likelihood estimation performs model selection using the objective


However, marginalization of the latent variable is often intractable; to address this issue, it is common to employ the variational principle to maximize the following lower bound



is the Kullback-Leibler divergence and

is a variational family. This lower bound, commonly called the evidence lower bound (ELBO), converts log-likelihood estimation into a tractable optimization problem. Since the lower bound holds for any , the variational family can be chosen to ensure that is easily computable, and the lower bound is optimized to select the best proposal distribution for each .

2.2 Amortization and Variational Autoencoders

kingma2013auto ; rezende2014stochastic proposed to construct using a parametric function , where is some family of distributions over , and is a family of functions indexed by parameters . To expedite training, they observed that it is possible to amortize the computational cost of variational inference by framing the per-sample optimization process as a regression problem; rather than solving for the optimal proposal directly, they instead use a recognition model to predict . The functions can be concisely represented as conditional distributions, where


The use of amortized inference yields the variational autoencoder, which is trained to maximize the variational autoencoder objective


We omit the dependency of on and on for notational simplicity. In addition to the typical presentation of the variational autoencoder objective (LHS), we also show an alternative formulation (RHS) that reveals the influence of the model capacities and distribution family capacities on the objective function. In this paper, we use interchangeably, depending on the choice of emphasis. To highlight the relationship between the ELBO in Eq. 2 and the standard variational autoencoder objective in Eq. 5, we shall also refer to the latter as the amortized ELBO.

2.3 Amortized Inference Suboptimality

For a fixed generative model, the optimal unamortized and amortized inference models are


A notable consequence of using an amortization family to approximate variational inference is that Eq. 5 is a lower bound of Eq. 2. This naturally raises the question of whether the learned inference model can accurately approximate the mapping . To address this question, cremer2018inference defined the inference, approximation, and amortization gaps as


Studies have found that the inference gap is non-negligible wu2016quantitative and primarily attributable to the presence of a large amortization gap cremer2018inference .

The amortization gap raises two critical considerations. On the one hand, we wish to reduce the training amortization gap . If the family is too low in capacity, then it is unable to approximate and will thus increase the amortization gap. Motivated by this perspective, kim2018semi ; krishnan2017challenges proposed to reduce the training amortization gap by performing stochastic variational inference on top of amortized inference. In this paper, we take the opposing perspective that an over-expressive hurts generalization (see Appendix A) and that restricting the capacity of is a form of regularization that can prevent both the inference and generative models from overfitting to the training set.

3 Amortized Inference Regularization in Variational Autoencoders

Many methods have been proposed to expand the variational and amortization families in order to better approximate maximum likelihood training kim2018semi ; kingma2016improved ; sonderby2016ladder ; burda2015importance ; maaloe2016auxiliary ; ranganath2016hierarchical . We argue, however, that achieving a better approximation to maximum likelihood training is not necessarily the best training objective, even if the end goal is test set density estimation. In general, it may be beneficial to regularize the maximum likelihood training objective.

Importantly, we observe that the evidence lower bound in Eq. 2 admits a natural interpretation as implicitly regularizing maximum likelihood training


This formulation exposes the ELBO as a data-dependent regularized maximum likelihood objective. For infinite capacity , is zero for all , and the objective reduces to maximum likelihood. When

is the set of Gaussian distributions (as is the case in the standard VAE), then

is zero only if is Gaussian for all . In other words, a Gaussian variational family regularizes the true posterior toward being Gaussian cremer2018inference . Careful selection of the variational family to encourage to adopt certain properties (e.g. unimodality, fully-factorized posterior, etc.) can thus be considered a special case of posterior regularization ganchev2010posterior ; zhu2014bayesian .

Unlike traditional variational techniques, the variational autoencoder introduces an amortized inference model and thus a new source of posterior regularization.


In contrast to unamortized variational inference, the introduction of the amortization family forces the inference model to consider the global structure of how maps to . We thus define amortized inference regularization as the strategy of restricting the inference model capacity to satisfy certain desiderata. In this paper, we explore a special case of AIR where a candidate model is penalized if it is not sufficiently smooth. We propose two models that encourage inference model smoothness and demonstrate that they can reduce the inference gap and increase log-likelihood on the test set.

3.1 Denoising Variational Autoencoder

In this section, we propose using random perturbation training for amortized inference regularization. The resulting model—the denoising variational autoencoder (DVAE)—modifies the variational autoencoder objective by injecting noise into the inference model


Note that the noise term only appears in the regularizer term. We consider the case of zero-mean isotropic Gaussian noise and denote the denoising regularizer as . At this point, we note that the DVAE was first described in im2017denoising . However, our treatment of DVAE differs from im2017denoising ’s in both theoretical analysis and underlying motivation. We found that im2017denoising incorrectly stated the tightness of the DVAE variational lower bound (see Appendix B). In contrast, our analysis demonstrates that the denoising objective smooths the inference model and necessarily lower bounds the original variational autoencoder objective (see Sections 3.1 and 3.1).

We now show that 1) the optimal DVAE amortized inference model is a kernel regression model and that 2) the variance of the noise

controls the smoothness of the optimal inference model.

[] For fixed and infinite capacity , the inference model that optimizes the DVAE objective in Eq. 13 is the kernel regression model


where and is the RBF kernel.

Section 3.1 shows that the optimal denoising inference model is dependent on the noise level . The output of is the proposal distribution that minimizes the weighted Kullback-Leibler (KL) divergence from to each , where the weighting depends on the distance and the bandwidth . When , the amortized inference model forces neighboring points to have similar proposal distributions. Note that as increases, , where is the number of training samples. Controlling thus modulates the smoothness of (we say that is smooth if it maps similar inputs to similar outputs under some suitable measure of similarity). Intuitively, the denoising regularizer approximates the true posteriors with a “-smoothed” inference model and penalizes generative models whose posteriors cannot easily be approximated by such an inference model. This intuition is formalized in Section 3.1.

[] Let be a minimal exponential family with corresponding natural parameter space . With a slight abuse of notation, consider . Under the simplifying assumption that is contained within and parameterized by , and that has infinite capacity, then the optimal inference model in Section 3.1 returns , where


and Lipschitz constant of is bounded by .

We wish to address Section 3.1’s assumption that the true posteriors lie in the variational family. Note that for sufficiently large exponential families, this assumption is likely to hold. But even in the case where the variational family is Gaussian (a relatively small exponential family), the small approximation gap observed in (cremer2018inference, ) suggests that it is plausible that posterior regularization would encourage the true posteriors to be approximately Gaussian.

Given that modulates the smoothness of the inference model, it is natural to suspect that a larger choice of results in a stronger regularization. To formalize this notion of regularization strength, we introduce a way to partially order a set of regularizers .

Suppose two regularizers and share the same minimum . We say that is a stronger regularizer than if for all .

Note that any two regularizers can be modified via scalar addition to share the same minimum. Furthermore, if is stronger than , then and share at least one minimizer. We now apply Section 3.1 to characterize the regularization strength of as increases.

We say that is closed under input translation if for all , where .

[] Consider the denoising regularizer . Suppose is closed under input translation and that, for any , there exists such that maps to the prior all . Furthermore, assume that there exists such that . Then is stronger when ; i.e., and for all .

Sections 3.1 and 3.1 show that as we increase , the optimal inference model is forced to become smoother and the regularization strength increases. Figure 1 is consistent with this analysis, showing the progression from under-regularized to over-regularized models as we increase .

It is worth noting that, in addition to adjusting the denoising regularizer strength via , it is also possible to adjust the strength by taking a convex combination of the VAE and DVAE objectives. In particular, we can define the partially denoising regularizer as


Importantly, we note that is still strictly non-negative and, when combined with the log-likelihood term, still yields a tractable variational lower bound.

3.2 Weight-Normalized Amortized Inference

In addition to DVAE, we propose an alternative method that directly restricts

to the set of smooth functions. To do so, we consider the case where the inference model is a neural network encoder parameterized by weight matrices

and leverage salimans2016weight ’s weight normalization technique, which proposes to reparameterize the columns of each weight matrix as


where are trainable parameters. Since it is possible to modulate the smoothness of the encoder by capping the magnitude of , we introduce a new parameter and define


The norm

is thus bounded by the hyperparameter

. We denote the weight-normalized regularizer as , where is the amortization family induced by a -weight-normalized encoder. Under similar assumptions as Section 3.1, it is easy to see that for any and that for all when (since ). We refer to the resulting model as the weight-normalized inference VAE (WNI-VAE) and show in Table 1 that weight-normalized amortized inference can achieve similar performance as DVAE.

3.3 Experiments

We conducted experiments on statically binarized MNIST, statically binarized OMNIGLOT, and the Caltech 101 Silhouettes datasets. These datasets have a relatively small amount of training data and are thus susceptible to model overfitting. For each dataset, we used the same decoder architecture across all four models (VAE, DVAE

, DVAE , WNI-VAE) and only modified the encoder, and trained all models using Adam kingma2014adam (see Appendix E for more details). To approximate the log-likelihood, we proposed to use importance-weighted stochastic variational inference (IW-SVI), an extension of SVI hoffman2013stochastic which we describe in detail in Appendix C. Hyperparameter tuning of DVAE’s and WNI-VAE’s is described in Table 7.





Table 1: Test set evaluation of VAE, DVAE, and WNI-VAE. The performance metrics are log-likelihood , the amortized ELBO , and the inference gap . All three proposed models out-perform VAE across most metrics.
Figure 1: Evaluation of the log-likelihood performance of all three proposed models as we vary the regularization parameter value. The regularization parameter is defined in Table 7. When the parameter value is too small, the model overfits and the test set performance degrades. When the parameter value is too high, the model underfits.

Table 1 shows the performance of VAE, DVAE, and WNI-VAE. Regularizing the inference model consistently improved the test set log-likelihood performance. On the MNIST and Caltech 101 Silhouettes datasets, the results also show a consistent reduction of the test set inference gap when the inference model is regularized. We observed differences in the performance of DVAE versus WNI-VAE on the Caltech 101 Silhouettes dataset, suggesting a difference in how denoising and weight normalization regularizes the inference model; an interesting consideration would thus be to combine DVAE and WNI. As a whole, Table 1 demonstrates that AIR benefits the generative model.

The denoising and weight normalization regularizers have respective hyperparameters and that control the regularization strength. In Figure 1, we performed an ablation analysis of how adjusting the regularization strength impacts the test set log-likelihood. In almost all cases, we see a transition from overfitting to underfitting as we adjust the strength of AIR. For well-chosen regularization strength, however, it is possible to increase the test set log-likelihood performance by nats—a non-trivial improvement.

3.4 How Does Amortized Inference Regularization Affect the Generator?

Table 1 shows that regularizing the inference model empirically benefits the generative model. We now provide some initial theoretical characterization of how a smoothed amortized inference model affects the generative model. Our analysis rests on the following proposition.

[] Let be an exponential family with corresponding mean parameter space and sufficient statistic function . With a slight abuse of notation, consider . Define , where is a fixed inference model. Supposing has infinite capacity, then the optimal generative model in Eq. 5 returns , where


Section 3.4 generalizes the analysis in bousquet2017optimal which determined the optimal generative model when is Gaussian. The key observation is that the optimal generative model outputs a convex combination of , weighted by . Furthermore, the weights are simply density ratios of the proposal distributions . As we increase the smoothness of the amortized inference model, the weight should tend toward for all . This suggests that a smoothed inference model provides a natural way to smooth (and thus regularize) the generative model. 11todo: 1maybe prove this

4 Amortized Inference Regularization in Importance-Weighted Autoencoders

In this section, we extend AIR to importance-weighted autoencoders (IWAE-). Although the application is straightforward, we demonstrate a noteworthy relationship between the number of importance samples and the effect of AIR. To begin our analysis, we consider the IWAE- objective


where are samples from the proposal distribution to be used as importance-samples. Analysis by cremer2017reinterpreting allows us to rewrite it as a regularized maximum likelihood objective


where (or equivalently ) is the unnormalized distribution


and is the Kullback-Leibler divergence extended to unnormalized distributions. For notational simplicity, we omit the dependency of on . Importantly, cremer2017reinterpreting showed that the IWAE with importance samples drawn from the amortized inference model is, on expectation, equivalent to a VAE with importance sample drawn from the more expressive inference model .

4.1 Importance Sampling Attenuates Amortized Inference Regularization

We now consider the interaction between importance sampling and AIR. We introduce the regularizer as follows


which corresponds to a regularizer where weight normalization, denoising, and importance sampling are simultaneously applied. By adapting Theorem 1 from burda2015importance , we can show that

[] Consider the regularizer . Under similar assumptions as Section 3.1, then is stronger than when ; i.e., and for all . 22todo: 2maybe show the asymptotic convergence rate

A notable consequence of Section 4.1 is that as increases, AIR exhibits a weaker regularizing effect on the posterior distributions . Intuitively, this arises from the phenomenon that although AIR is applied to , the subsequent importance-weighting procedure can still create a flexible . Our analysis thus predicts that AIR is less likely to cause underfitting of IWAE-’s generative model as increases, which we demonstrate in Figure 2. In the limit of infinite importance samples, we also predict AIR to have zero regularizing effect since (under some assumptions) can always approximate any posterior. However, for practically feasible values of , we show in Tables 3 and 3 that AIR is a highly effective regularizer.

4.2 Experiments





Table 3: Test set evaluation of the four models when trained with importance samples. .




Table 2: Test set evaluation of the four models when trained with importance samples. denotes the amortized ELBO using importance samples. .

Tables 3 and 3 extends the model evaluation to IWAE- and IWAE-. We see that the denoising IWAE (DIWAE) and weight-normalized inference IWAE (WNI-IWAE) consistently out-perform the standard IWAE on test set log-likelihood evaluations. Furthermore, the regularized models frequently reduced the inference gap as well. Our results demonstrate that AIR is a highly effective regularizer even when a large number of importance samples are used.

Our main experimental contribution in this section is the verification that increasing the number of importance samples results in less underfitting when the inference model is over-regularized. In contrast to , where aggressively increasing the regularization strength can cause considerable underfitting, Figure 2 shows that increasing the number of importance samples to and makes the models much more robust to mis-specified choices of regularization strength. Interestingly, we also observed that the optimal regularization strength (determined using the validation set) increases with (see Table 7 for details). The robustness of importance sampling when paired with amortized inference regularization makes AIR an effective and practical way to regularize IWAE.

Figure 2: Evaluation of the log-likelihood performance of all three proposed models as we vary the regularization parameter (see Table 7 for definition) and number of importance samples . To compare across different ’s, the performance without regularization (IWAE- baseline) is subtracted. We see that IWAE- is the least likely to underfit when the regularization parameter value is high.

4.3 Are High Signal-to-Noise Ratio Gradients Necessarily Better?

We note the existence of a related work rainforth2018tighter that also concluded that approximating maximum likelihood training is not necessarily better. However, rainforth2018tighter focused on increasing the signal-to-noise ratio of the gradient updates and analyzed the trade-off between importance sampling and Monte Carlo sampling under budgetary constraints. An in-depth discussion of these two works within the context of generalization is provided in Appendix D.

5 Conclusion

In this paper, we challenged the conventional role that amortized inference plays in training deep generative models. In addition to expediting variational inference, amortized inference introduces new ways to regularize maximum likelihood training. We considered a special case of amortized inference regularization (AIR) where the inference model must learn a smoothed mapping from and showed that the denoising variational autoencoder (DVAE) and weight-normalized inference (WNI) are effective instantiations of AIR. Promising directions for future work include replacing denoising with adversarial training goodfellow2014explaining and weight normalization with spectral normalization miyato2018spectral . Furthermore, we demonstrated that AIR plays a crucial role in the regularization of IWAE, and that higher levels of regularization may be necessary due to the attenuating effects of importance sampling on AIR. We believe that variational family expansion by Monte Carlo methods hoffman2017learning may exhibit the same attenuating effect on AIR and recommend this as an additional research direction.


This research was supported by TRI, NSF (#1651565, #1522054, #1733686 ), ONR, Sony, and FLI. Toyota Research Institute provided funds to assist the authors with their research but this article solely reflects the opinions and conclusions of its authors and not TRI or any other Toyota entity.


Appendix A Overly Expressive Amortization Family Hurts Generalization

In the experiments by [10], they observed that an overly expressive amortization family increases the test set inference gap, but does not impact the test set log-likelihood. We show in Table 4 that [10]’s observation is not true in general, and that an overly expressive amortization family can in fact hurt test set log-likelihood. Details regarding the architectures are provided in Appendix E.

IWAE (Large Encoder)





Table 4: Performance evaluation when an over-expressive amortization family is used (i.e. a larger encoder). Comparison is made against models that use a smaller encoder. The results show that using a large encoder consistently hurts generalization by over nat.

Appendix B Revisiting [17]’s Denoising Variational Autoencoder Analysis

In [17]’s Lemma 1, they considered a joint distribution . They introduced an auxiliary variable into their inference model (here takes on the role of the perturbed input . To avoid confusion, we stick to the notation used in their Lemma) and considered the inference model


They considered two ways to use this inference model. The first approach is to marginalize the auxiliary latent variable . This defines the resulting inference model


This yields the lower bound


Next, they considered an alternative lower bound


[17]’s Lemma 1 claims that

  1. and are valid lower bounds of

  2. .

Using Lemma 1, [17] motivated the denoising variational autoencoder by concluding that it provides a tighter bound than marginalization of the noise variable. Although statement 1 is correct, statement 2 is not. Their proof of statement 2 is presented as follows


We indicate the mistake with ; their proof of statement 2 relied on the assumption that


Crucially, the RHS is ill-defined since it does not take the expectation over , whereas the LHS explicitly specifies an expectation over . This difference, while subtle, invalidates the subsequent steps. If we fix Eq. 28 and attempt to see if the rest of the proof still follows, we will find that