Learning in undirected models
Let us now look at parameter learning in undirected graphical models. Unfortunately, as in the case of inference, the higher expressivity of undirected models also makes them significantly more difficult to deal with. Fortunately, maximum likelihood learning in these models can be reduced to repeatedly performing inference, which will allow us to apply all the approximate inference techniques that we have seen earlier.
Learning Markov random fields
Let us start with a Markov random field (MRF) of the form
is the normalizing constant. We can reparametrize as follows:
where is a vector of indicator functions and is the set of all the model parameters, as defined by the .
Note that is different for each set of parameters ; therefore, we also refer to it as the partition function. Bayesian networks are constructed such that for all ; MRFs do not make this modeling assumption, which makes them more flexible, but also more difficult to learn.
More generally, distributions of this form are members of the exponential family of distributions, about which you can learn more in CS229. Many other distributions are in the exponential family, including the Bernoulli, Multinomial, Normal, Poisson, and many other distributions.
Exponential families are widely used in machine learningWe refer the reader to the CS229 course notes for a more thorough presentation of this topic.. Suppose that you have an exponential family distribution of the formActually, exponential families have a slightly more general form, but this one will be enough for our purposes.
Here are few facts about these distributions that you should know about.
- Exponential families are log-concave in their natural parameters . The partition function is also log-convex in .
- The vector is called the vector of sufficient statistics; these fully describe the distribution ; e.g. if is Gaussian, contains (simple reparametrizations of) the mean and the variance of .
- Exponential families make the fewest unnecessary assumptions about the data distribution. More formally, the distribution maximizing the entropy under the constraint (i.e. the sufficient statistics equal some value ) is in the exponential family.
Exponential families are also very convenient to work with computationally. Their sufficient statistics can summarize arbitrary amounts of i.i.d. variables from the same distribution, and they admit so-called conjugate priors which makes them easily applicable in variational inference. In short, it definitely pays off to learn more about exponential families!
Maximum likelihood learning of MRFs
Suppose now that we are given a dataset and we want to estimate via maximum likelihood. Since we are working with an exponential family, the maximum likelihood will be concave. The log-likelihood is:
The first term is linear in and is easy to handle. The second term equals
Unlike the first term, this one does not decompose across . It is not only hard to optimize, but it is hard to even evaluate that term, as we have already seen in previous chapters.
Now consider the gradient of the log likelihood. Obtaining the gradient of the linear part is obviously very easy. However, the gradient of takes a more complicated form:
This expression can be derived using simple algebra.
Computing the expectation on the right hand side of the equation requires inference with respect to . For example, we could sample from and construct a Monte-Carlo estimate of the expectation. However, as we have seen, inference in general is intractable, and therefore so is computing the gradient.
We can similarly derive an expression for the Hessian of :
Since covariance matrices are always positive semi-definite, this proves that is convex (and therefore that the log-likelihood is concave). Recall that this was one of the properties of exponential families that we stated earlier.
In summary, even though the log-likelihood objective is convex, optimizing it is hard; usually non-convexity is what makes optimization intractable, but in this case, it is the computation of the gradient.
Approximate learning techniques
Interestingly, however, maximum-likelihood learning reduces to inference in the sense that we may repeatedly use inference to compute the gradient and determine the model weights using gradient descent.
This observation lets us apply to learning many of the approximate inference methods that we have seen in previous chapters, such as:
- Gibbs sampling from the distribution at each step of gradient descent; we then approximate the gradient using Monte-Carlo.
- Persistent contrastive divergencePersistent contrastive divergence (PCD) is one of the most popular methods for training Restricted Boltzmann Machines (RBMs), a very important deep learning model that is also an undirected graphical model. Have a look at this great practical tutorial on RBMs., a variant of Gibbs sampling which re-uses the same Markov Chain between iterations. After a step of gradient descent, our model has changed very little: hence we can essentially keep taking samples from the same Gibbs sampler, instead of starting a new one from scratch.
Another popular approach to learning is called pseudo-likelihood. The pseudo-likelihood replaces the likelihood
with the following approximation:
where is the -th variable in and is the set of neighbors of in the graph of (i.e. the Markov blanket of ).
Note that each term only involves one variable and hence its partition function is going to be tractable (we only need to sum over the values of one variable).
However, it is not equal to the likelihood. Note that the correct way to expand the likelihood would involve the chain rule, i.e. the terms would be objective, where are variables preceding in some ordering.
Intuitively, the pseudo-likelihood objective assumes that depends mainly on its neighbors in the graph, and ignores the dependencies on other, more distant variables. Observe also that if pseudo-likelihood succeeds in matching all the conditional distributions to the data, a Gibbs sampler run on the model distribution will have the same invariant distribution as a Gibbs sampler run on the true data distribution, ensuring that they are the same.
More formally, we can show that the pseudo-likelihood objective is concave. Assuming the data is drawn from an MRF with parameters , we can show that as the number of data points gets large, .
Pseudo-likelihood often works very well in practice, although there are exceptions.
We will end with an interesting observation about the maximum likelihood estimate of the MRF parameters.
Recall that the log-likelihood of an MRF is
Taking the gradient, and using our expression for the gradient of the partition function, we obtain the expression
Note that this is precisely the difference between the expectations of the natural parameters under the empirical (i.e. data) and the model distribution. Let’s now look at one component of . Recall that we have defined in the context of MRFs to be the vector of indicator functions for the variables of a clique: one entry of equals for some . The gradient over that component equals
This gives us an insight into how MRFs are trained. The log-likelihood objective forces the model marginals to match the empirical marginals.
We refer to the above property as moment matching. This property of maximum-likelihood learning is very general: whenever we choose distribution to minimize the inclusive KL-divergence across in an exponential family, the minimizer will match the moments of the sufficient statistics to the corresponding moments of . Recall that the MLE estimate is the minimizer over of , where is the empirical distribution of the data, so MLE estimation is a special case of this minimization. This property has connections to variational inference, where this minimization over in a smaller set of distributions is known as M-projection (“moment projection”).
Learning in conditional random fields
Finally, let us look how maximum-likelihood learning extends to conditional random fields (CRFs), the other important type of undirected graphical models that we have seen.
Recall that a CRF is a probability distribution of the form
is the partition function. The feature functions now depend on in addition to . The variables are fixed and the distribution is only over ; the partition function is thus a function of both and .
We can reparametrize as we did for MRFs:
where is again a vector of indicator functions and is a reparametrization of the model parameters.
The log-likelihood for this model given a dataset is
Note that this is almost the same form as we had for MRFs, except that now there is a different partition function for each data point .
The gradient is now
Similarly, the Hessian is going to be the covariance matrix
The good news is that this means that the conditional log-likelihood is still a concave function. We can optimize it using gradient ascent as before.
The bad news is that computing the gradient now requires one inference per training data point in order to compute the term
This makes learning CRFs more expensive that learning in MRFs. In practice, however, CRFs are much more widely used than MRFs because supervised learning is a more widely used type of learning, and discriminative models (like CRFs) often learn a better classifier than their generative counterparts (which model ).
To deal with the computational difficulties introduced by the partition function, we may use simpler models in which exact inference is tractable. This was the approach taken in the OCR example introduced in our first discussion of CRFs. More generally, one should try to limit the number of variables or make sure that the model’s graph is not too densely connected.
Finally, we would like to add that there exists another popular objective for training CRFs called the max-margin loss, a generalization of the objective for training SVMs. Models trained using this loss are called structured support vector machines or max-margin networks. This loss is more widely used in practice because it often leads to better generalization, and also it requires only MAP inference to compute the gradient, rather than general (e.g. marginal) inference, which is often more expensive to perform.