William DeGroot
← All posts

Singular learning theory · 02

A brief detour into singular integrals.

On empirical KL divergence, Bayesian inference, and model evidence.

Before defining the RLCT, we will take a brief detour into Bayesian statistics and Watanabe's theory of singular integrals. This will conveniently give us the opportunity to shore up necessary background in information theory and Bayesian statistics – and establish some prerequisites for exploring the fundamental theorems of singular learning theory in the future. We will seek to answer the following questions.

  1. In Bayesian inference, we output a distribution on the weights. How can we quantify how well the model and the prior predicted the observed dataset?
  2. How do KL divergence and Watanabe's singular integral show up when computing the model evidence?

Going forward, it will be essential to have some information theory basics. For that, I will default to 3b1b's excellent two-part series (Part 1: Reinventing Entropy and Part 2: But what is cross-entropy?). A central object of study in The Gray Book is the singular integral of general form:

Z(n)=∫exp(−nKn(w))ϕ(w)dwZ(n) = \int\textrm{exp}(-nK_n(w))\phi(w)dw

where Kn(w)K_n(w) is a function on Rd\RR^d and ϕ(w)\phi(w) is a probability density function. First, we will show that, when we set Kn(w)K_n(w) to the empirical KL divergence, Z(n)Z(n) is exactly computing the normalized model evidence.

Empirical Cross Entropy

For the remainder of this post, let X\mathcal{X} be the input space, and let Y\mathcal{Y} denote the space of possible outputs. Perhaps think about every x∈Xx \in \cX as a token sequence of fixed context length and every y∈Yy \in \cY as a possible next token with ∣Y∣=∣vocabulary∣.|\cY| = |\textrm{vocabulary}|. Then let q(y∣x)q(y \mid x) denote the underlying true conditional distribution (that we are trying to model), and define a joint probability distribution on X×Y\cX \times \cY:

q(x,y)=q(x)q(y∣x).q(x,y) = q(x)q(y \mid x).

Similarly, let p(y∣x,w)p(y \mid x, w) denote the conditional distribution predicted by our model with parameters w,w, and extend this to a distribution to X×Y\cX \times \cY by letting

pw(x,y)=q(x)p(y∣x,w).p_w(x,y) = q(x)p(y \mid x, w).

Recall that, for two probability distributions qq and pp on a discrete sample space Y\mathcal Y, the population KL divergence is defined by

DKL(q∥p)=∑y∈Yq(y)log⁡q(y)p(y). D_{\mathrm{KL}}(q\|p)=\sum_{y\in\mathcal Y}q(y)\log\frac{q(y)}{p(y)}.

Specializing to X×Y,\cX \times \cY, we compute that

K(w):=DKL(q∣∣pw)=∑(x,y)∈X×Yq(x,y)log⁡q(x)q(y∣x)q(x)p(y∣x,w)=E(x,y)∼q[log⁡q(y∣x)p(y∣x,w)]. \begin{aligned} K(w) := D_{\mathrm{KL}}(q || p_w) &= \sum_{(x,y) \in \cX \times \cY}q(x,y)\log\frac{q(x)q(y\mid x)}{q(x)p(y\mid x,w)}\\ &= \EE_{(x,y) \sim q}[\log\frac{q(y \mid x)}{p(y \mid x,w)}]. \end{aligned}

In the case where ∣X∣|\cX| is finite and q(x)q(x) is a uniform distribution on X\cX, this is the average of the conditional KL divergences over the inputs. The general issue with the population KL divergence, however, is that q(x,y)q(x,y) may be unknown or difficult to compute in practice. (For modeling natural language, it is arguably unknown). Therefore, we need a good empirical substitute which will converge to the population KL divergence as the number of samples goes to infinity.

Let Dn={(x1,y1),…,(xn,yn)}⊆X×YD_n = \{(x_1,y_1),\ldots,(x_n,y_n)\} \subseteq \cX \times \cY be a dataset with nn examples, sampled independently according to

(x,y)∼qi.i.d.X×Y. (x,y) \sim_q^{\textrm{i.i.d.}} \cX \times \cY.

For future use, let D\mathcal{D} be the space of all datasets with any finite number of examples. Then

q(Dn)=∏i=1nq(xi)q(yi∣xi)q(D_n) = \prod_{i = 1}^nq(x_i)q(y_i \mid x_i)

and

p(Dn∣w)=∏i=1nq(xi)p(yi∣xi,w).p(D_n \mid w) = \prod_{i = 1}^nq(x_i)p(y_i \mid x_i,w).

We define the empirical KL divergence to be

Kn(w)=1n∑i=1nlog⁡q(yi∣xi)p(yi∣xi,w).K_n(w) = \frac{1}{n}\sum_{i = 1}^n \log \frac{q(y_i \mid x_i)}{p(y_i \mid x_i,w)}.

It is also a common convention to flip numerator and denominator, writing:

Kn(w)=−1n∑i=1nlog⁡p(yi∣xi,w)q(yi∣xi)K_n(w) = -\frac{1}{n}\sum_{i = 1}^n \log \frac{p(y_i \mid x_i,w)}{q(y_i \mid x_i)}

By the law of large numbers, for each fixed w,w, it follows that

Kn(w)→K(w)asn→∞.K_n(w) \to K(w) \hspace{5mm}\textrm{as}\hspace{5mm}n \to \infty.

In the expression that we saw earlier for Z(n),Z(n), this will precisely be our choice of function Kn.K_n.

Now I should note that this actually does not fix the issue of being unable to compute Kn(w)K_n(w) due to q(x,y)q(x,y) being unknown. However, we can at least minimize the empirical KL divergence by remarking that minimizing Kn(w)K_n(w) is equivalent to minimizing the empirical cross entropy, which is given by:

Ln(w)=−1n∑i=1nlog⁡p(yi∣xi,w).L_n(w) = -\frac{1}{n} \sum_{i = 1}^n\log p(y_i \mid x_i,w).

The fact that this quantity does not depend on qq makes Ln(w)L_n(w) highly useful for training machine learning algorithms. Unfortunately though, explicitly computing Kn(w)K_n(w) is still generally not possible. However, it will be useful to consider it abstractly as an input to a singular integral.

Bayesian Posterior

Given a dataset DD and a set of model parameters W\mathcal{W}, we define the posterior distribution with respect to some w∈Ww \in \mathcal{W} to be:

p(w∣D)=p(D∣w)p(w)p(D)p(w \mid D) = \frac{p(D \mid w)p(w)}{p(D)}

for some prior distribution p(W).p(\mathcal{W}). There are a few ways to think about the posterior distribution. First off, it is immediately apparent that

p(w∣D)∝p(D∣w)p(w).p(w \mid D) \propto p(D \mid w)p(w).

Thus, p(w∣D)p(w \mid D) is similar to the likelihood – except it is weighted by some prior, p(w).p(w). Then we normalize by p(D)p(D) to ensure that p(W∣D)p(\mathcal{W} \mid D) is a probability distribution. It is also important to remember that – under the hood – we are assuming the existence of the sample space W×D\mathcal{W} \times \mathcal{D}, where the probability measure is a joint distribution constructed in two stages. First we sample from the parameters:

w∼p(W)Ww\sim_{p(\mathcal{W})} \mathcal{W}

and then we sample from D\mathcal{D}:

D∼p,wD.D\sim_{p,w}\mathcal{D}.

From this generative point of view, p(w∣D)p(w\mid D) becomes more concrete. In the discrete case, it is the probability that the hidden parameter setting sampled in the first stage was ww, conditional on observing the dataset DD in the second stage. Remember unlike the likelihood, a large posterior (say .99) does not automatically mean that ww is highly predictive – only that its likelihood, weighted by the prior, is much larger than the rest of W.\mathcal{W}. 1 The process of Bayesian inference (repeatedly updating your new prior to be the posterior, computed with new observations) will output a distribution of parameters. The likelihood tells us how predictive a single parameter setting is. But what if we wanted to average the likelihood over the prior to get a feel for the entire distribution?

In general, this is hard. But SLT to the rescue! Let's see how the singular integral Z(n)Z(n) that Watanabe and others have developed techniques to analyze asymptotically is actually doing something very similar in disguise.

Model evidence

Letting Kn(w)K_n(w) be the empirical KL divergence, we can simplify:

Kn(w)=−1n∑i=1nlog⁡p(yi∣xi,w)q(yi∣xi)  ⟹  e−nKn(w)=exp⁡(log⁡∏i=1np(yi∣xi,w)q(yi∣xi))=∏i=1nq(xi)p(yi∣xi,w)q(xi)q(yi∣xi)=p(Dn∣w)q(Dn). \begin{aligned} K_n(w) &= -\frac{1}{n}\sum_{i = 1}^n\log \frac{p(y_i \mid x_i,w)}{q(y_i \mid x_i)}\\ \implies e^{-n K_n(w)} &= \exp(\log\prod_{i = 1}^n\frac{p(y_i \mid x_i,w)}{q(y_i \mid x_i)})\\ &= \prod_{i = 1}^n \frac{q(x_i)p(y_i \mid x_i,w)}{q(x_i)q(y_i \mid x_i)}\\ &= \frac{p(D_n \mid w)}{q(D_n)} \end{aligned}.

Plugging this into Z(n)Z(n) and taking ϕ(w)=p(w)\phi(w) = p(w), we obtain:

Z(n)=∫Wp(Dn∣w)q(Dn)p(w)dw.Z(n) = \int_{\mathcal{W}}\frac{p(D_n \mid w)}{q(D_n)}p(w)dw.

It is extremely tempting to claim that this integrand is just p(w∣Dn)p(w \mid D_n), but this is incorrect precisely because p(Dn)≠q(Dn)p(D_n) \neq q(D_n) (in general). Instead, we note that

Z(n)=p(Dn)q(Dn).Z(n) = \frac{p(D_n)}{q(D_n)}.

We often call p(Dn)p(D_n) the model evidence, and this ratio tells us roughly how well the distribution p(W)p(\mathcal{W}) predicted DnD_n, normalized by the true dataset probability. One might also remark that the evidence p(Dn)p(D_n) is exactly the likelihood p(Dn∣w)p(D_n \mid w) averaged over p(W)p(\mathcal{W}), so this is a very natural thing to want to compute.

This explains Watanabe's interest in singular integrals to some extent. But this isn't all. Remember that the end goal is to produce a more precise measure of “effective dimension”. Next time, we will finally define the RLCT and relate it to p(Dn)q(Dn)\frac{p(D_n)}{q(D_n)} via the free energy equation. Eventually we will also develop techniques for estimating Z(n)Z(n) using a Laplace approximation to the posterior distribution.

Notes

  1. Bayesian inference/statistics is its own subject that I will not begin to tackle in full detail. Check out Stanford's Bayesian analysis lecture notes for a nice lecture-based introduction.
    ↩
✦← What is Singular Learning Theory?Back to all writing

Note