12.1 Direct minimization
Let us ignore this last concern and simply naïvely attempt to minimize the relative entropy:
The result can be interpreted intuitively: Energies are arbitrary up to an additive constant, which can always be absorbed into the normalizer. Equivalently, they are completely characterized by their gradients. Accordingly, the goal of learning is to align the expected gradients under the data and model. This is highly reminiscent of exponential families, under which learning aligns the expected sufficient statistics under data and model. Indeed, the expected energy gradient (under the EBM) is equal to the derivative of its log partition function—exactly the relationship that obtains under exponential families for the expected sufficient statistics. Unlike exponential families, however, the energy is not restricted to linear dependence on the parameters, and consequently the energy gradients do no satisfy the Neyman-Fisher factorization criterion, as true sufficient statistics do. But evidently they play a very similar conceptual role.
Nevertheless, the elegance of Eq. 12.2 should not be interpreted as an easy solution to the problem of fitting EBM. In particular, the expected energy gradients (under the EBM) will not be analytically calculable for any sufficiently complicated energy function. We naturally turn to sample averages, but that brings us back to the first of the difficulties enumerated above: we don’t yet know how to sample from the model.
12.1.1 Langevin dynamics
Recall from Chapter LABEL:ch:AdvancedSamplingTechniques that, in the limit as the step size approaches zero, the discretized Langevin dynamics
(with a standard normal random variable) has as its stationary distribution
In the literature, is frequently omitted from the stationary distribution in order to reduce clutter, as we have in Eq. 12.1, and in the loss and its gradients, Eq. 12.2. Indeed, because normalized probabilities are rarely computable (or computed), is in some sense irrelevant to the reported results—it merely sets the “units” of the energy. Nevertheless, in practice when running Langevin dynamics, it is useful to be able to scale the gradient and noise terms independently: the latter must be small for stability, but the former must not be too small lest numerical precision of the gradient be lost. This is particularly true early in training, when the energy landscape produced by the neural network is very flat. Including the parameter allows for such independent scaling of the gradient and noise.††margin: Doesn’t work for discrete RVs. But there are methods….
Short-run MCMC.
Samples generated with Langevin dynamics can be used to approximate the expectation under the model. For simple EBMs, this works. However, for any sufficiently complex model, it has been observed that the burn-in of the Markov chain requires an intolerable number of Langevin steps—on the order of tens of thousands [51, 50]! Somewhat remarkably, training such EBMs under only 100 or so steps of Langevin still yields a good generator of (e.g.) images—so long as, at test time, a similar number of steps of Langevin is used. If more steps are taken, the model generates images closer to its own preferences—which turn out to be highly saturated (bad) images. Although these models are in some sense EBMs, they do not assign the EBM probability (Eq. 12.1) to data, nor are they trained according to the proper training rule.
12.1.2 Contrastive divergence
If we want to train complex EBMs, it seems we need a different procedure. Indeed, in addition to the enormous number of sampling steps required to burn in the Markov chain (and then subsequently to “thin” the samples), there is the issue of estimator variance. At any particular step of parameter updates, the energy gradient can be very different for different samples, which come from the model’s (initially unstructured) distribution. Furthermore, this variance is -dependent. Hinton [25] observes that this degrades parameter estimation in an additional, conceptually subtle, way. Parameter updates will tend to be larger (one way or another) in regions of parameter space with highly variable gradients. So after many updates, the parameters will tend to be near the low-variance regions, even if these are actually worse. Hinton likens it to “a horizontal sheet of tin that is resonating in such a way that some parts have strong vertical oscillations and other parts are motionless. Sand scattered on the tin will accumulate in the motionless areas even though the time-averaged gradient is zero everywhere.”
CD as a heuristic.
To circumvent in a single move both the long burn-in time and the high variance of the energy-gradient estimator, Hinton proposed an alternative that appears, at first glance, to be very crude [27]: initializing the Markov chain at data, and then taking only a small number of steps. This procedure has a few clear merits. Late in training, when the model distribution resembles the data distribution, data initialization could conceivably shorten the burn-in period, since the initial sample is likely already to be in the “thick” part of the model distribution from which we hope to draw samples (in contrast to an arbitrary initial vector). Early in training, data samples are unlikely to have high probability under the model. But even here data initialization offers something, so long as the same data are used in both averages in Eq. 12.2. In particular, it lowers the variance of our estimate of the loss gradient:
If only a few () steps are taken down the Markov chain, the resulting sample will be correlated with its initialization—to wit, . The gradients evaluated at these samples will likewise covary, and therefore the covariance term above will be positive, reducing the overall variance of the estimator [1]. Under standard MCMC, in contrast, the covariance term vanishes.
To emphasize that the “model” and data samples are from the same Markov chain, I have superscripted them both with the respective number of steps down that chain ( and 0). For the same reason, we should also nest the model-dependent average inside the data average in the proposed gradient estimator:
Likewise, I will also use , , and for the data, -step, and model distributions (respectively). (Recall that after infinite steps down the chain, samples will be drawn from the model distribution.)
CD as the approximate gradient of a different objective.
The heuristic arguments for Eq. 12.3 are compelling33 3 At least, in conjunction with the empirical success that CD enjoyed in its first decade, approximately 2000–2010., but it would be useful to justify it more rigorously. To that end, we work backwards: what loss function might yield this gradient? Hinton proposed [25] a “contrastive divergence,” i.e., the difference or contrast between the original relative entropy and a new one:
We note two important facts about this objective:
-
•
The contrastive divergence is non-negative: The -step distribution is “trapped” between and . That is, MCMC sampling brings a distribution closer to , which will consequently diverge less from “later” than “earlier” distributions. So the second term is always less then the first, and their difference never negative.
-
•
The contrastive divergence is zero at precisely the same points as the first term—i.e., the standard relative-entropy loss (with the gradient given by Eq. 12.2). By the previous argument, Eq. 12.4 can be zero only when the divergences are equal, i.e. when . But this implies that is not altered by the first steps of sampling; that is, it is an equilibrium distribution of the Markov chain. Hence, , at which point the standard relative entropy also vanishes.44 4 We might take this as a specific instance of a more general procedure: if the gradient of a function is difficult, replace it with a different function with the same minimum but an easier gradient.
Now we would like to show that the gradient of Eq. 12.4 is equal to the right-hand side of Eq. 12.3. We have already worked out the gradient of the first relative entropy, Eq. 12.2, but we break the computation into steps to reuse portions for the derivative of the second divergence. For brevity, we suppress the arguments:
On the third line we have substituted for the fourth term by exploiting the analogy with the second term (which we worked out in Eq. 12.2 above). In fine, the gradient of the contrastive divergence, Eq. 12.4, is equal to the desired update, plus one extra term.55 5 Note that, although I haven’t made it explicit, the sample average under is implicitly nested within the sample average under the data .
Is this close enough? Hinton concluded from extensive simulation that the third term is small in practice, and that in any case, including it rarely alters the gradient by more than 90 degrees (i.e., point in the wrong direction) [25].66 6 A recent attempt to model the third term approximately actually initializes its Markov chains at noise, rather than data [13], and is therefore inconclusive. Empirically, the method worked well in its era (c. 2000–2010). Furthermore, the relevance of this term can be decreased by increasing , since for large enough , the objective approaches the standard relative entropy—although this must be balanced against the introducton of estimator variance, discussed above.