N O MCMC FOR ME : A MORTIZED SAMPLING FOR FAST AND STABLE TRAINING OF ENERGY - BASED MODELS
A BSTRACT
Energy-Based Models (EBMs) present a ﬂexible and appealing way to represent uncertainty.
Despite recent advances, training EBMs on high-dimensional data remains a challenging problem as the state-of-the-art approaches are costly, unstable, and require considerable tuning and domain expertise to apply successfully.
In this work we present a simple method for training EBMs at scale which uses an entropy-regularized generator to amortize the MCMC sampling typically used in EBM training.
We improve upon prior MCMC-based entropy regularization methods with a fast variational approximation.
We demonstrate the effectiveness of our approach by using it to train tractable likelihood models.
Next, we apply our estimator to the recently proposed Joint Energy Model (JEM), where we match the original performance with faster and stable training.
This allows us to extend
JEM models to semi-supervised classiﬁcation on tabular data from a variety of continuous domains.
I NTRODUCTION
Energy-Based Models (EBMs) have recently regained popularity within machine learning, partly inspired by the impressive results of Du & Mordatch (2019) and Song & Ermon (2020) on largescale image generation.
Beyond image generation, EBMs have also been successfully applied to a wide variety of applications including: out-of-distribution detection (Grathwohl et al., 2019; Du & Mordatch, 2019; Song & Ou, 2018), adversarial robustness (Grathwohl et al., 2019; Hill et al., 2020; Du & Mordatch, 2019), reliable classiﬁcation (Grathwohl et al., 2019; Liu & Abbeel, 2020) and semi-supervised learning (Song & Ou, 2018; Zhao et al.).
Strikingly, these EBM approaches outperform alternative classes of generative models and rival hand-tailored solutions on each task.
Despite progress, training EBMs is still a challenging task.
As shown in Table 1, existing training methods are all deﬁcient in at least one important practical aspect.
Markov chain Monte Carlo (MCMC) methods are slow and unstable during training (Nijkamp et al., 2019a; Grathwohl et al., 2020).
Score matching mechanisms, which minimize alternative divergences are also unstable and most methods cannot work with discontinuous nonlinearities (such as ReLU)
(Song & Ermon, 2019b; Hyv¨arinen, 2005; Song et al., 2020; Pang et al., 2020b; Grathwohl et al., 2020; Vincent, 2011).
Noise contrastive approaches, which learn energy functions through density ratio estimation, typically don’t scale well to high-dimensional data (Gao et al., 2020; Rhodes et al., 2020; Gutmann & Hyv¨arinen, 2010; Ceylan & Gutmann, 2018).
[Table]
In this work, we present a simple method for training EBMs which performs as well as previous methods while being faster and substantially easier to tune.
Our method is based on reinterpreting maximum likelihood as a bi-level variational optimization problem, which has been explored in the past for EBM training (Dai et al., 2019).
This perspective allows us to amortize away MCMC sampling into a GAN-style generator which is encouraged to have high entropy.
We accomplish this with a novel approach to entropy regularization based on a fast variational approximation.
This leads to the method we call Variational Entropy Regularized Approximate maximum likelihood (VERA).
Concretely, we make the following contributions:
• We improve the MCMC-based entropy regularizer of Dieng et al.
with a parallelizable variational approximation.
• We show that an entropy-regularized generator can be used to produce a variational bound on the EBM likelihood which can be optimized more easily than MCMC-based estimators.
• We demonstrate that models trained in this way achieve much higher likelihoods than methods trained with alternative EBM training procedures.
• We show that our approach stabilizes and accelerates the training of recently proposed Joint Energy Models (Grathwohl et al., 2019).
• We show that the stabilization of our approach allows us to use JEM for semi-supervised learning, outperforming virtual adversarial training when little prior domain knowledge is available (e g., for tabular data).
E NERGY B ASED M ODELS
An energy-based model (EBM) is any model which parameterizes a density as
[Equation]
where f θ : R D
→ R and Z ( θ ) = (cid:82) e f θ ( x ) d x is the normalizing constant which is not explicitly modeled.
Any probability distribution can be represented in this way for some f θ .
The energy-based parameterization has been used widely for its ﬂexibility, ease of incorporating known structure, and relationship to physical systems common in chemistry, biology, and physics (Ingraham et al., 2019;
Du et al., 2020; No´e et al., 2019).
The above properties make EBMs an appealing model class, but because they are unnormalized many tasks which are simple for alternative model classes become challenging for EBMs.
For example, exact samples cannot be drawn and likelihoods cannot be exactly computed (or even lowerbounded).
This makes training EBMs challenging as we cannot simply train them to maximize likelihood.
The most popular approach to train EBMs is to approximate the gradient of the maximum likelihood objective.
This gradient can be written as:
[Equation]
MCMC techniques are used to approximately generate samples from p θ ( x ) (Tieleman, 2008).
Practically, this approach suffers from poor stability and computational challenges from sequential sampling.
Many tricks have been developed to overcome these issues (Du & Mordatch, 2019), but they largely still persist.
Alternative estimators have been proposed to circumvent these challenges, including score matching (Hyv¨arinen, 2005), noise contrastive estimation (Gutmann & Hyv¨arinen, 2010), and variants thereof.
These suffer from their own challenges in scaling to high dimensional data, and sacriﬁce the statistical efﬁciency of maximum likelihood.
In Figure 1 we visualize densities learned with our approach and Persistent Contrastive Divergence (Tieleman, 2008)
(PCD) training.
As we see, the sample quality of the PCD models is quite high but the learned density models do not match the true model.
This is due to accrued bias in the gradient estimator from approximate MCMC sampling (Grathwohl et al., 2020).
Prior work (Nijkamp et al., 2019b) has argued that this objective actually encourages the approximate MCMC samples to match the data rather than the density model.
Conversely, we see that our approach (with proper entropy regularization) recovers a high quality model.
V ARIATIONAL M AXIMUM L IKELIHOOD
We seek the energy function which maximizes likelihood given in Equation 1.
We examine the intractable component of the log-likelihood, the log partition-function log Z ( θ )
= log (cid:82)
e f θ ( x ) d x .
We can re-write this quantity as the optimum of
[Equation]
where q is a distribution and H ( q ) =
− E q ( x ) [log q ( x )] denotes its entropy 1 (see the Appendix A. for the derivation).
Plugging this into our original maximum likelihood statement we obtain:
[Equation]
which gives us an alternative method for training EBMs.
We introduce an auxiliary sampler q φ which we train online to optimize the inner-loop of Equation 4.
This objective was used for EBM training in Kumar et al.
; Abbasnejad et al.
Dai et al. (2017), Dai et al.
(2019) (motivated by
Fenchel Duality (Wainwright & Jordan, 2008)).
Abbasnejad et al.
(2019) use an implicit generative model and Dai et al.
(2019) propose to use a sampler which is inspired by MCMC sampling from p θ ( x ) and whose entropy can be computed exactly.
Below we describe our approach which utilizes the same objective with a simpler sampler and a new approach to encourage high entropy.
We note that when training p θ ( x ) and q ( x ) online together, the inner maximization will not be fully optimized.
This leads our training objective for p θ ( x ) to be an upper bound on log p θ ( x ) .
In Section 5.1 we explore the impact of this fact and ﬁnd that the bound is tight enough to train models that achieve high likelihood on high-dimensional data.
M ETHOD
We now present a method for training an EBM p θ ( x ) =
e f θ ( x ) /Z
( θ ) to optimize Equation 4.
We introduce a generator distribution of the form q φ ( x ) =
(cid:82)
z q φ ( x | z ) q ( z )d
z such that:
[Equation]
where g ψ is a neural network with parameters ψ and thus, φ = { ψ, σ 2 } .
This is similar to the decoder of a variational autoencoder (Kingma & Welling, 2013).
With this architecture it is easy to optimize the ﬁrst and second terms of Equation 4 with reparameterization, but the entropy term requires more care.
4. E NTROPY R EGULARIZATION
Estimating entropy or its gradients is a challenging task.
Multiple, distinct approaches have been proposed in recent years based on Mutual Information estimation (Kumar et al., 2019), variational upper bounds (Ranganath et al., 2016), Denoising Autoencoders (Lim et al., 2020), and nearest neighbors (Singh & P´oczos, 2016).
The above methods require the training of additional auxiliary models or do not scale well to high dimensions.
Most relevant to this work are Dieng et al.
; Titsias & Ruiz (2019) which present a method for encouraging generators such as ours to have high entropy by estimating ∇ φ H ( q φ ) .The
estimator takes the following form:
[Equation]
where we have written x ( z, (cid:15) )
=
g ψ ( z ) + σ(cid:15) .
All quantities in Equation 6 can be easily computed except for the score-function ∇ x log q φ ( x ) .
The following estimator for this quantity can be easily derived (see Appendix A.2):
[Equation]
which requires samples from the posterior q φ ( z | x ) to estimate.
Dieng et al.
; Titsias & Ruiz (2019) generate these samples using Hamiltonian Monte Carlo (HMC) (Neal et al., 2011), a gradientbased MCMC algorithm.
As used in Dieng et al.
(2019), 28 sequential gradient computations must be made per training iteration.
Since a key motivation of this work is to circumvent the costly sequential computation of MCMC sampling, this is not a favourable solution.
In our work we propose a more efﬁcient solution that we ﬁnd works just as well empirically.
4. V ARIATIONAL A PPROXIMATION WITH I MPORTANCE S AMPLING
We propose to replace HMC sampling of q φ ( z | x ) with a variational approximation ξ ( z | z 0 )
≈ q φ ( z | x ) where z 0 is a conditioning variable we will deﬁne shortly.
We can use this approximation with self-normalized importance sampling to estimate
[Equation]
where { z i } ki =1 ∼ ξ ( z | z 0 ) and w i ≡ q φ ( z i ,x ) ξ
( z i | z 0 ) .
We use k = 20 importance samples for all experiments in this work.
This approximation holds for any conditioning information we would like to use.
To choose this, let us consider how samples x ∼ q φ ( x ) are drawn.
We ﬁrst sample z 0 ∼ N (0 , I ) and then x ∼ q φ ( x | z 0 ) .
In our estimator we want a variational approximation to q φ ( z | x ) and by construction, z 0 is a sample from this distribution.
For this reason we let our variational approximation be
[Equation]
or simply a diagonal Gaussian centered at the z 0 which generated x .
For this approximation to be useful we must tune the variance η 2 .
We do this by optimizing the standard Evidence Lower-Bound at every training iteration
[Equation]
We then use ξ η ( z | z 0 ) to approximate ∇ x log q φ ( x ) which we plug into Equation 6 to estimate ∇ φ H ( q φ ) for training our generator.
A full derivation and discussion can be found in Appendix A.3.
Combining the tools presented above we arrive at our proposed method which we call Variational
Entropy Regularized Approximate maximum likelihood (VERA), outlined in Algorithm 1.
We found it helpful to further add an (cid:96) 2 -regularizer with weight 0 .
1 to the gradient of our model’s likelihood as in Kumar et al.
In some of our larger-scale experiments we reduced the weight of the entropy regularizer as in Dieng et al.
We refer to the entropy regularizer weight as λ .
Algorithm Input : EBM p θ ( x ) ∝ e f θ ( x ) , generator q φ ( x, z ) , approximate posterior ξ η ( z | z 0 ) , entropy weight λ , gradient penalty γ = .
Output: Parameters θ such that p θ ≈ p while True do
Sample mini-batch x , and generate mini-batch x g , z 0 ∼ q φ ( x, z )
Compute L ELBO ( η ; z 0 , x g ) and update η // Update posterior
Compute log f θ ( x ) − log f θ ( x g ) + γ ||∇ x log f θ ( x ) || 2 and update θ // Update EBM
Sample { z i } ki =1 ∼ ξ η ( z | z 0 )
Compute s = (cid:101) ∇ x log q φ ( x ; { z i } ki =1 , z 0 ) //
Estimate score fn (Eq.8)
Compute g
=
s T ∇ φ x g // Estimate entropy gradient (Eq.6)
Update φ with ∇ φ log f θ ( x g )
+ λg //
Update generator end
EBM T RAINING E XPERIMENTS
We present results training various models with VERA and related approaches.
In Figure 1 we visualize the impact of our generator’s entropy on the learned density model and compare this with
MCMC sampling used in PCD learning.
In Section 5.1, we explore this quantitatively by training tractable models and evaluating with test-likelihood.
In Section 5.2 we explore the bias of our entropy gradient estimator and the estimator’s effect on capturing modes.
5. F ITTING T RACTABLE M ODELS
Optimizing the generator in VERA training minimizes a variational upper bound on the likelihood of data under our model.
If this bound is not sufﬁciently tight, then training the model to maximize this bound will not actually improve likelihood.
To demonstrate the VERA bound is tight enough to train large-scale models we train NICE models (Dinh et al., 2014) on the MNIST dataset.
NICE is a normalizing ﬂow (Rezende & Mohamed, 2015) model – a ﬂexible density estimator which enables both exact likelihood computation and exact sampling.
We can train this model with VERA (which does not require either of these abilities), evaluate the learned model using likelihood, and generate exact samples from the trained models.
Full experimental details 2 can be found in Appendix B. and additional results can be found in Appendix C.1.
[Figure] We compare the performance of VERA with maximum likelihood training as well as a number of approaches for training unnormalized models; Maximum Entropy Generators (MEG) (Kumar et al., 2019), Persistent
Contrastive Divergence (PCD), Sliced Score
Matching (SSM) (Song et al., 2020), Denoising
Score Matching (DSM) (Vincent, 2011), Curvature Propagation (CP-SM)
(Martens et al., 2012), and CoopNets (Xie et al., 2018).
As an ablation we also train VERA with the HMCbased entropy regularizer of Dieng et al.
(2019), denoted VERA-(HMC).
Table 2 shows that VERA outperforms all approaches that do not require a normalized model.
Figure 2 shows exact samples from our NICE models.
For PCD we can see (as observed in Figure 1) that while the approximate MCMC samples resemble the data distribution, the true samples from the model do not.
This is further reﬂected in the reported likelihood value which falls behind all methods besides DSM.
CoopNets perform better than PCD, but exhibit the same behavior of generator samples resembling the data, but not matching true samples.
We attribute this behavior to the method’s reliance on MCMC sampling.
Conversely, models trained with VERA generate coherent and diverse samples which reasonably capture the data distribution.
We also see that the samples from the learned generator much more closely match true samples from the NICE model than PCD and MEG.
When we remove the entropy regularizer from the generator ( λ = 0 . 0 ) we observe a considerable decrease in likelihood and we ﬁnd that the generator samples are far less diverse and do not match exact samples at all.
Intriguingly, entropy-free VERA outperforms most other methods.
We believe this is because even without the entropy regularizer we are still optimizing a (weak) bound on likelihood.
Conversely, the score-matching methods minimize an alternative divergence which will not necessarily correlate well with likelihood.
Further, Figure 2 shows that MEG performs on par with entropy-free VERA indicating that the Mutual Information-based entropy estimator may not be accurate enough in high dimensions to encourage high entropy generators.
[Table]
5. U NDERSTANDING O UR E NTROPY R EGULARIZER
In Figure 3, we explore the quality of our score function estimator on a PCA (Tipping & Bishop, 1999) model ﬁt to MNIST, a setting where we can compute the score function exactly (see Appendix B.4 for details).
The importance sampling estimator (with 20 importance samples) has somewhat larger variance than the HMC-based estimator but has a notably lower bias of . 12 .
The HMC estimator using 2 burn-in steps (recommended in Dieng et al.
(2019)) has a bias of . 48 .
Increasing the burn-in steps to 500 reduces the bias to .
20 while increasing variance.
We ﬁnd the additional variance of our estimator is remedied by mini-batch averaging and the reduced bias helps explain the improved performance in Table 2.
Further, we compute the effective sample size (Kong, 1992) (ESS) of our importance sampling proposal on our CIFAR10 and MNIST models and achieve an ESS of 1.32 and 1.29, respectively using 20 importance samples.
When an uninformed proposal ( N (0 , I ) ) is used, the ESS is 1.0 for both models.
This indicates our gradient estimates are informative for training.
More details can be found in Appendix B.6.
Next, we count the number of modes captured on a dataset with 1,000 modes consisting of 3 MNIST digits stacked on top of one another (Dieng et al., 2019; Kumar et al., 2019).
We ﬁnd that both VERA and VERA (HMC) recover 999 modes, but training with no entropy regularization recovers 998 modes.
We conclude that entropy regularization is unnecessary for preventing mode collapse in this setting.
A PPLICATIONS TO J OINT E NERGY M ODELS
[Figure] Joint Energy Models (JEM) (Grathwohl et al., 2019) are an exciting application of EBMs.
They reinterpret standard classiﬁers as EBMs and train them as such to create powerful hybrid generative/discriminative models which improve upon purely-discriminative models at outof-distribution detection, calibration, and adversarial robustness.
Traditionally, classiﬁcation tasks are solved with a function f θ : R D
→ R K which maps from the data to K unconstrained real-valued outputs (where k is the number of classes).
This function parameterizes a distribution over labels y given data x : p θ ( y | x ) =
e f ( x )[ y ] / (cid:80) y (cid:48)
e f θ ( x )[ y (cid:48) ] .
The same function f θ can be used to deﬁne an EBM for the joint distribution over x and y as: p θ ( x, y ) =
e f θ ( x )[ y ] /Z
( θ ) .
The label y can be marginalized out to give an unconditional model p θ ( x ) = (cid:80)
y
e f θ ( x )[ y ] /Z
( θ ) .
JEM models are trained to maximize the factorized likelihood:
[Equation]
where α is a scalar which weights the two terms.
The ﬁrst term is optimized with cross-entropy and the second term is optimized using EBM training methods.
In Grathwohl et al.
PCD was used to train the second term.
We train JEM models on CIFAR10, CIFAR100, and SVHN using VERA instead of PCD.
We examine how this change impacts accuracy, generation, training speed, and stability.
Full experimental details can be found in Appendix B.7.
Speed and Stability While the results presented in Grathwohl et al.
(2019) are promising, training models as presented in this work is challenging.
MCMC sampling can be slow and training can easily diverge.
Our CIFAR10 models train 2.8x faster than the ofﬁcial JEM implementation 3 with the default hyper-parameters.
With these default parameters JEM models would regularly diverge.
To train for the reported 200 epochs training needed to be restarted multiple times and the number of MCMC steps needed to be quadrupled, greatly increasing run-time.
Conversely, we ﬁnd that VERA was much more stable and our models never diverged.
This allowed us to remove the additive Gaussian noise added to the data which is very important to stabilize
MCMC training (Grathwohl et al., 2019; Nijkamp et al., 2019a; Du & Mordatch, 2019).
Hybrid Modeling In Tables 3 and 4 we compare the discriminative and generative performance of JEM models trained with VERA, PCD (JEM), and HDGE (Liu & Abbeel, 2020).
With α =
we ﬁnd that VERA leads to models with poor classiﬁcation performance but strong generation performance.
With α = 100 VERA obtains stronger classiﬁcation performance than the original
JEM model while still having improved image generation over JEM and HDGE (evaluated with
FID (Heusel et al., 2017)).
[Table] [Table]
Unconditional samples can be seen from our CIFAR10 and CIFAR100 models in Figure 4.
Samples are reﬁned through a simple iterative procedure using the latent space of our generator, explained in
Appendix B.7.1.
Additional conditional samples can be found in Appendix C.
Out-of-Distribution Detection JEM is a powerful approach for out-of-distribution detection (OOD), greatly outperforming tractable likelihood models like VAEs and ﬂows (Nalisnick et al., 2018).
In Table 5, reporting AUROC (Hendrycks & Gimpel, 2016), we see
VERA outperforms JEM with PCD training but under-performs contrastive training (HDGE).
Intriguingly, VERA performs poorly on CelebA.
This result, along with the unreliable performance of DSM models at this task (Li et al., 2019) leads to questions regarding special beneﬁts of MCMC training that are lost in our method as well as DSM.
We leave this to future work.
[Table]
6. T ABULAR D ATA
Training with VERA is much more stable and easy to apply to domains beyond images where EBM training has been extensively tuned.
To demonstrate this we show that JEM models trained with
VERA can provide a beneﬁt to semi-supervised classiﬁcation on datasets from a variety of domains.
Considerable progress has been made in semi-supervised learning but the most impressive results require considerable domain knowledge (Chen et al., 2020).
In domains like images, text, and audio such knowledge exists but for data from particle accelerators, gyroscopes, and satellites, such intuition may not be available and these techniques cannot be applied.
In these settings there are far fewer options for semi-supervised learning.
We present VERA as one such option.
We train semi-supervised JEM models on data from a variety of continuous domains.
We perform no data augmentation beyond removing redundant features and standardizing the remaining features.
To further demonstrate the versatility of VERA we use an identical network for each dataset and method.
Full experimental details can be found in Appendix
B.8.
In Table 6, we ﬁnd on each dataset tested, we ﬁnd that VERA outperforms the supervised baseline and outperforms VAT which is the strongest domain agnostic semi-supervised learning method we are aware of.
R ELATED W ORK
Kumar et al.
(2019) train EBMs using entropy-regularized generators, attempting to optimize the same objective as our own.
The key difference is how the generator’s entropy is regularized.
Kumar [Table] et al.
(2019) utilize a Mutual Information estimator to approximate the generator’s entropy whereas we approximate the gradients of the entropy directly.
The method of Kumar et al.
(2019) requires the training of an additional MI-estimation network, but our approach only requires the optimization of the posterior variance which has considerably fewer parameters.
As demonstrated in Section 5.1, their approach does not perform as well as VERA for training NICE models and their generator collapses to a single point.
This is likely due to the notorious difﬁculty of estimating MI in high dimensions and the unreliability of current approaches for this task (McAllester & Stratos, 2020;
Song & Ermon, 2019a).
Dai et al.
(2019) train EBMs using the same objective as VERA.
The key difference here is in the architecture of the generator.
Dai et al.
(2019) use generators with a restricted form, inspired by various MCMC sampling methods.
In this setting, a convenient estimator for the generator’s entropy can be derived.
In contrast, our generators have an unconstrained architecture and we focus on entropy regularization in the unconstrained setting.
Abbasnejad et al.
(2019) train EBMs and generators as well to minimize the reverse KL-divergence.
Their method differs from ours in the architecture of the generator and the method for encouraging high entropy.
Their generator deﬁnes an implicit density (unlike ours which deﬁnes a latent-variable model).
The entropy is maximized using a series approximation to the generator function’s Jacobian log-determinant which approximates the change-of-variables for injective functions.
Gao et al.
(2020) train EBMs using Noise Contrastive Estimation where the noise distribution is a normalizing ﬂow.
Their training objective differs from ours and their generator is restricted to having a normalizing ﬂow architecture.
These architectures do not scale as well as the GAN-style architectures we use to large image datasets.
As well there exist CoopNets (Xie et al., 2018) which cooperatively train an EBM and a generator network.
Architecturally, they are similar to VERA but are trained quit differently.
In CoopNets, the generator is trained via maximum likelihood on its own samples reﬁned using MCMC on the EBM.
This maximum likleihood step requires MCMC as well to generate posterior samples as in Pang et al.
(2020a).
In contrast, the generator in VERA is trained to minimize the reverse KL-divergence.
Our method requires no MCMC and was speciﬁcally developed to alleviate the difﬁculties of MCMC sampling.
The estimator of Dieng et al.
(2019) was very inﬂuential to our work.
Their work focused on applications to GANs.
Our estimator could easily be applied in this setting and to implicit variational inference (Titsias & Ruiz, 2019) as well but we leave this for future work.
C ONCLUSION
In this work we have presented VERA, a simple and easy-to-tune approach for training unnormalized density models.
We have demonstrated our approach learns high quality energy functions and models with high likelihood (when available for evaluation).
We have further demonstrated the superior stability and speed of VERA compared to PCD training, enabling much faster training of
JEM (Grathwohl et al., 2019) while retaining the performance of the original work.
We have shown that VERA can train models from multiple data domains with no additional tuning.
This enables the applications of JEM to semi-supervised classiﬁcation on tabular data – outperforming a strong baseline method for this task and greatly outperforming JEM with PCD training.
A K EY D ERIVATIONS A. D ERIVATION OF V ARIATIONAL L OG -P ARTITION F UNCTION
Here we show that the variational optimization given in equation 3 recovers log Z ( θ ) .
[Equation]
A. S CORE F UNCTION E STIMATOR
Here we derive the equivalent expression for ∇ x log q φ ( x ) given in Equation 7.
[Equation]
A. E NTROPY G RADIENT E STIMATOR
From Equation 6 we have
[Equation] [Equation]
where { z i } ki =1 ∼ ξ ( z | z 0 ) and w i ≡ q φ ( z i ,x ) ξ
( z i | z 0 ) .
We discuss when the approximations in Equation 13 will hold.
The importance sampling estimator will be biased when q ψ ( z | x ) differs greatly from ξ ( z | z 0 ) .
Since the generator function g ψ ( z ) is a smooth, Lipschitz function (as are most neural networks) and the output Gaussian noise is small, the space of z values which could have generated x should be concentrated near z 0 . In these settings, z 0 should be useful for predicting q ( z | x ) .
The accuracy of this approximation is based on the dimension of z compared to x and the Lipschitz constant of g ψ . In all settings we tested, dim ( z ) (cid:28) dim ( x ) where this approximation should hold. If dim ( z ) (cid:29) dim ( x ) the curse of dimensionality would take effect and z 0 would be less and less informative about q ( z | x ) . In settings such as these, we do not believe our approach would be as effective.
Thankfully, almost all generator architectures we are aware of have dim ( z ) (cid:28) dim ( x ) . The approximation could also break down if the Lipschitz constant blew up. We ﬁnd this does not happen in practice, but this can be addressed with many forms of regularization and normalization.
B E XPERIMENTAL D ETAILS B. H YPERPARAMETER R ECOMMENDATIONS
[Table] [Table]
α > 1 , learning rates were divided
[Table]
† We found λ = 10 − 4 to work best on large image datasets, but in general we recommend starting with λ = 1 and trying successively smaller values of λ until training is stable.
We give some general tips on how to set hyperparameters when training VERA in Table 7.
In all
VERA experiments, we use the gradient norm penalty with weight 0 .
This was not tuned during our experiments.
When using VERA and MEG we train with Adam (Kingma & Ba, 2014) and set β 1 = 0 , β 2 = .
9 as is standard in the GAN literature (Miyato et al., 2018).
In general, we recommend setting the learning rate for the generator to twice the learning rate of the energy function and equal to the learning rate of the approximate posterior sampler.
B.1. I MPACT OF λ
Let us rewrite the generator’s training objective
[Equation]
We can easily see that this objective is equivalent (up to a multiplicative constant) to
[Equation]
From this, it is clear that maximizing Equation 14 is the same as minimizing the KL-divergence between q and a tempered version of p θ ( x ) deﬁned as
[Equation]
Tempering like this is standard practice in EBM training and is done in many recent works.
Tempering has the effect of increasing the weight of the gradient signal in SGLD sampling relative to the added Gaussian noise.
In all of Du & Mordatch (2019); Grathwohl et al.
; Nijkamp et al.
(2019a;b) the SGLD samplers used a temperature of 1 /λ = 20,000.
This value is near the value of 10 , 000 that we use in this work.
Thus we can see that our most important hyper-parameter is actually the temperature of the sampler’s target distribution.
Ideally this temperature would be set to 1, but this can lead to unstable training (as it does with SGLD).
To train high quality models, we recommend setting λ as close to 1 as possible, decreasing if training becomes unstable.
B. T OY D ATA V ISUALIZATIONS
We train simple energy functions on a 2D toy data.
The EBM is a 2-layer MLP with 100 hidden units per layer using the Leaky-ReLU nonlinearity with negative slope .
The generator is a 2-layer
MLP with 100 hidden units per layer and uses batch normalization (Ioffe & Szegedy, 2015) with
ReLU nonlinearities.
All models were trained for 100,000 iterations with all learning rates set to .001 and used the Adam optimizer (Kingma & Ba, 2014).
The PCD models were trained using an SGLD sampler and a replay buffer with 10,000 examples, reinitialized every iteration with 5% probability.
We used 20 steps of SGLD per training iteration to make runtime consistent with VERA.
We tested σ values outside of the presented range but smaller values did not produce decent samples or energy functions and for larger values, training diverged.
B. T RAINING NICE M ODELS
The NICE models were exactly as in Song et al.
They have 4 coupling layers and each coupling layer had 5 hidden layers.
Each hidden layer has 1000 units and uses the Softplus nonlinearity.
We preprocessed the data as in Song et al.
by scaling the data to the range [0 , 1] , adding uniform noise in the range [ − 1 / 512 , 1 / 512] , clipping to the range [ . 001 , . 999] and applying the logit transform log( x ) − log(1 − x ) .
All models were trained for 400 epochs with the Adam optimizer (Kingma & Ba, 2014) with β 1 = 0 and β 2 = .
We use a batch size of 128 for all models.
We re-ran the score matching model of Song et al.
(2020) to train for 400 epochs as well and found it did not improve performance as its best test performance happens very early in training.
For all generator-based training methods we use the same ﬁxed generator architecture.
The generator has a latent-dimension of 100 and 2 hidden layers with 500 units each.
We use the Softplus nonlinearity and batch-normalization (Ioffe & Szegedy, 2015) as is common with generator networks.
For VERA the hyper-parameters we searched over were the learning rates for the NICE model and for the generator.
Compared to Song et al.
(2020) we needed to use much lower learning rates.
We searched over learning rates in { . 0003 , . 00003 , . 000003 } for both the generator and energy function.
We found .
000003 to work best for the energy function and .
0003 to work best for the generator.
This makes intuitive sense since the generator needs to be fully optimized for the bound on likelihood to be tight.
When equal learning rates were used ( . 0003 , .
we observed high sample quality from the generator but exact samples and likelihoods from the NICE model were very poor.
For PCD we search over learning rates in { . 0003 , .
000003 } , the number of MCMC steps in { 20 , 40 } and the SGLD noise standard-deviation in { 1 . 0 , 0 . 1 } .
All models with 20 steps and
SGLD standard-deviation 1.0 quickly diverged.
Our best model used learning rate .000003, stepsize 0.1, and 40 steps.
We tested the gradient-norm regularizer from Kumar et al.
and found it decreased performance for PCD trained models.
Most models with 20 MCMC steps diverged early in training.
For review the MCMC sampler we use is stochastic gradient Langevin dynamics (Welling & Teh, 2011).
This sampler updates its samples by
[Equation]
[Equation]
where σ is the noise standard-deviation and is a parameter of the sampler.
For Maximum Entropy Generators (MEG) (Kumar et al., 2019)
we must choose a mutualinformation estimation network.
We follow their work and use an MLP with LeakyReLU nonlinearities with negative slope .
Our network mirrors the generator and has 3 hidden layers with 500 units each.
We searched over the same hyper-parameters as VERA.
We found MEG to perform almost identically to training with no entropy regularization at all.
We believe this has to do with the challenges of estimating MI in high dimensions Song & Ermon (2019a).
For CoopNets (Xie et al., 2018)
we use the same ﬂow and generator architectures as VERA.
Following the MNIST experiments in Xie et al.
we train using 10 SGLD steps per iteration.
We tried the recommended learning rates of .007 and .0001 for the ﬂow and generator, respectively but found this to lead quick divergence.
For this reason, we search over learning rates for the ﬂow and generator from { . 0003 , .
000003 } as we did for VERA and found the best combination to be .
000003 for the ﬂow and .
0003 for the generator.
Other combinations resulted in higher quality generator samples but much worse likelihood values.
We tested the recommended SGLD step-size of . 002 and found this to lead to divergence as well in this setup.
Thus, we searched over larger values of { . 002 , .
1 } found .
1 to perform the best, as with PCD.
B. E STIMATION OF B IAS OF E NTROPY R EGULARIZER
If we restrict the form of our generator to a linear function
[Equation]
then we have
[Equation]
= N
[Equation]
meaning we can exactly compute log q ( x ) , and ∇ x log q ( x ) which is the quantity that VERA (HMC) approximates with the HMC estimator from Dieng et al.
and we approximate with VERA.
To explore this, we ﬁt a PCA model on MNIST and recover the parameters W, µ of the linear generator and the noise parameter σ .
Samples from this model can be seen in Figure 5.
Both VERA and VERA (HMC) have some parameters which are tuned automatically to improve the estimator throughout training.
For VERA this is the posterior variance which is optimized according to Equation 10 with Adam with default hyperparameters.
For VERA (HMC) this is the stepsize of
HMC which is tuned automatically as outlined in (Dieng et al., 2019).
Both estimators were trained with a learning rate of .
for 500 iterations with a batch size of 5000.
Samples from the estimators during training were taken with the default parameters, in particular the number of burn-in steps or the number of importance samples was not varied as they were during evaluation.
The bias of the estimators were evaluated on a batch of 10 samples from the generator.
For each example in the batch, 5000 estimates were taken from the estimator and averaged to be taken as an estimate of the score function for this batch example.
This estimate of the score function was subtracted from the true score function and then averaged over all dimensions and examples in the batch and taken as an estimate of the bias per dimension.
For VERA (HMC) we varied the number of burn-in steps used for samples to evaluate the bias of the estimator.
We also tried to increase the number of posterior samples taken off the chain, but we found that this did not clearly reduce the bias of this estimator as the number of samples increased.
For VERA we computed the bias on the default of 20 importance samples.
B. M ODE C OUNTING
We train VERA without labels on the S TACKED MNIST dataset.
This dataset consists of 60, examples of 3 stacked MNIST images sampled with replacement from the original 60,000 MNIST train set.
As in (Dieng et al., 2019) we resize the images to 64 × 64 and use the DCGAN (Radford et al., 2015) architecture for both the energy-function and generator.
We use a latent code ofdimensions.
We train for 17 epochs with a learning rate of .
001 and batch size 100 .
We estimate the number of modes captured by taking S = 10 , 000 samples as in (Dieng et al., 2019) and classifying each digit of the 3 stacked images separately with a pre-trained classiﬁer on MNIST.
B. E FFECTIVE S AMPLE S IZE
When performing importance sampling, the quality of the proposal distribution has a large impact.
If the proposal is chosen poorly, then typically 1 sample will dominate in the expectation.
This can be quantiﬁed using the effective sample size (Kong, 1992) (ESS) which is deﬁned as
[Equation]
where p ( x ) is the target distribution, q ( x ) is the proposal distribution and N is the number of samples.
If the self-normalized importance weights are dominated by one weight close to 1 then the
ESS will be 1.
If the proposal distribution is identical to the target, so that the self-normalized importance weights are then uniform, then the ESS will be N .
When ESS = N , importance sampling is as efﬁcient as using the target distribution.
To understand the effect of the proposal distribution on ESS we plot the ESS when doing importance sampling with 20 importance samples from a 128-dimensional Gaussian target distribution with µ = 0 and Σ
= I .
We use a proposal which is a 128-dimensional Gaussian with µ increasing from 0 to 5 .
Results can be seen in Figure 6.
We see when the means differ by greater than 2, the ESS is approximately 1.0 and importance sampling has effectively failed.
[Figure]
Our energy function used the same architecture as in Grathwohl et al.
; Liu & Abbeel (2020), a Wide ResNet Zagoruyko & Komodakis (2016) 28-10 with batch-norm removed and with dropout.
Our generator architecture is identical to Miyato et al.
As in Grathwohl et al.
; Liu &
Abbeel (2020) we set the learning rate for the energy function equal to 0.0001.
We set the learning rate for the generator equal to 0.0002.
We train for 200 epochs using the Adam optimizer with β 1 = 0 and β 2 = .
We set the batch size to 64.
Results presented are from the models afterepochs with no early stopping.
We believe better results could be obtained from further training.
We trained models with α ∈ { 1 , 30 , 100 } and found classiﬁcation to be best with α = 100 and generation to be best with α = 1 .
Prior work on PCD EBM training (Grathwohl et al., 2019; Du & Mordatch, 2019; Nijkamp et al., 2019a;b) recommends adding Gaussian noise to the data to stabilize training.
Without this, PCD training of JEM models very quickly diverges.
Early in our experiments we found training with
VERA was stable without the addition of Gaussian noise so we do not use it.
As mentioned in Dieng et al.
(2019), when the strength of the entropy regularizer λ is too high, the generator may fall into a degenerate optimum where it just outputs high-entropy Gaussian noise.
To combat this, as suggested in Dieng et al.
(2019), we decrease the strength of λ to .0001 for all JEM experiments.
This value was chosen by decreasing λ from 1.0 by factors of 10 until learning took place (quantiﬁed by classiﬁcation accuracy).
B.7. MCMC S AMPLE R EFINEMENT
Our generator q φ ( x ) is trained to approximate our EBM p θ ( x ) .
After training, the samples from the generator are of high quality (see Figures 9 and 10, left) but they are not exactly samples from p θ ( x ) .
We can use MCMC sampling to improve the quality of these samples.
We use a simple
MCMC reﬁnement procedure based on the Metropolis Adjusted Langevin Algorithm (Besag, 1994) applied to an expanded state-space deﬁned by our generator and perform the Accept/Reject step in the data space.
We can reparameterize a generator sample x ∼ q φ ( x ) as a function x
( z, (cid:15) )
=
g ψ ( z ) + (cid:15)σ , and we can deﬁne an unnormalized density over { z, (cid:15) } , log h ( z, (cid:15) ) ≡ f θ ( g ψ ( z ) + (cid:15)σ ) − log Z ( θ, φ ) which is the density (under p θ ( x ) ) of the generator sample.
Starting with an initial sample z 0 , (cid:15) 0 ∼ N (0 , I ) we deﬁne the proposal distribution
[Equation]
) and accept a new sample with probability
[Equation]
Here, δ is the step-size and is a parameter of the sampler.
We tune δ with a burn-in period to target an acceptance rate of 0 . 57 .
A similar sampling procedure was proposed in Kumar et al.
and Che et al.
and in both works was found to improve sample quality.
In all experiments,
We clarify that this procedure is not a valid MCMC sampler for p θ ( x ) due to the augmented variables and the change in density of g ψ which are not corrected for.
The density of the samples will be a combination of p θ ( x ) and q φ ( x ) .
As the focus of this work was training and not sampling/generation, we leave the development of more correct generator MCMC-sampling to future work.
Regardless, we ﬁnd this procedure to improve visual sample quality.
In Figure 7 we visualize a sampling chain using the above method applied to our JEM model trained on SVHN.
B.7. I MAGE Q UALITY M ETRICS
We present results on Inception Score (Salimans et al., 2016) and Frechet Inception Distance (Heusel et al., 2017).
These metrics are notoriously ﬁckle and different repositories are known to give very different results (Grathwohl et al., 2019).
For these evaluations we generate 12,800 samples from the model and (unless otherwise stated) reﬁne the samples with 100 steps of our latent-space MALA procedure (Appendix B.7.1).
The code to generate our reported FID comes from this publicly available repository.
The code to generate our reported Inception Score can be found here.
B. S EMI - SUPERVISED LEARNING ON T ABULAR D ATA B.8. D ATA
We provide details about each of the datasets used for the experiments in Section 6.1.
HEPMASSis a dataset obtained from a particle accelerator where we must classify signal from background noise.
CROP 6 is a dataseset for classifying crop types from optical and radar sensor data.
HUMANis a dataset for human activity classiﬁcation from gyroscope data.
MNIST is an image dataset of handwritten images, treated here as tabular data.
[Table]
For HEPMASS and HUMAN data we remove features which repeat the same exact same value more than 5 times.
For CROP data we remove features which have covariation greater than 1.01.
For MNIST we linearly standardize features to the interval [ − 1 , 1] .
We take a random 10% subset of the data to use as a validation set.
B.8. T RAINING
We use the same architecture for all experiments and baselines.
It has 6 layers of hidden units with dimensions [1000 , 500 , 500 , 250 , 250 , 250] and a Leaky-ReLU nonlinearity with negative-slope .between each layer of hidden units.
The only layers which change between datasets are the input layer and the output layer which change according to the number of features and number of classses respectively.
The training process for semi-supervised learning is similar to JEM with an additional objective commonly used in semi-supervised learning:
[Equation]
where H ( p ( y | x )) is the entropy of the predictive distribution over the labels.
For all models we report the accuracy the model converged to on the held-out validation set.
We report the average taken over three training runs with different seeds.
We use equal learning rates for the energy model, generator, and the entropy estimator.
We tune the learning rate and decay schedule for supervised models on the full-set of labels and 10 labels per class.
Using+Smartphones
On VERA we tune the learning rate and decay schedule, the weighting of the entropy regularization λ and the weighting of the entropy of classiﬁcation outputs β .
For VAT we tune the perturbation size (cid:15) ∈ { . 01 , .
All other hyperparameters were ﬁxed according to tuning on VERA.
For MEG we used the hyperparameters tuned according to VERA.
For JEM we tune the number of MCMC steps in the range κ ∈ { 20 , 40 , 80 } .
We generate samples using SGLD with stepsize 1 and noise standard deviation 0 .
01 as in Grathwohl et al.
Dataset
[Table]
C A DDITIONAL R ESULTS C. T RAINING M IXTURES OF G AUSSIANS
We present additional results training mixure of Gaussian models using VERA and PCD.
Each model consits of 100 diagonal Gaussians and mixing weights.
Our experimental setup and hyperparameter search was identical to that presented in Appendiex B.2.
We see in Table 10 that VERA outperforms PCD
[Table]
C. S AMPLES FROM SSL M ODELS
We present some samples from our semi-supervised MNIST models in Figure
[Table]
C. H YBRID M ODELING
We present an extended Table 4 with Inception Score Salimans et al.
and which includes more comparisons.
[Table]
[Figure]
[Figure]
[Figure]