Use of Information Theory in Learning Theory

1. Sources and Codes

Imagine that Alice observes one outcome and must send Bob a binary message from which he can recover it. Before discussing “information” or “uncertainty,” there is a concrete question:

How many bits should Alice assign to each possible outcome?

We will answer only that question at first. Probability, surprisal, cross-entropy, entropy, and KL divergence will then appear one at a time because the previous concept leaves a specific coding question unanswered. All logarithms are base two, so lengths are measured in bits.

Road map: Section 1 treats information as communication. Code length comes first: a distribution q specifies ideal lengths, real data occur according to p, their average gives cross-entropy, the matched case q = p gives entropy, and the mismatch gap is KL divergence. Section 2 carries these ideas into supervised learning, where the input is side information and the label is the outcome to predict. Section 3 changes viewpoint from the average behavior of a source to the shortest program that reproduces one particular object.

1. 信源与编码

想象 Alice 观察到一个结果,需要发送一段二进制消息,使 Bob 能够从消息中恢复这个结果。在讨论“信息”或“不确定性”之前,我们先问一个具体问题:

Alice 应该为每个可能结果分配多少 bit?

一开始我们只回答这个问题。之后 probability、surprisal、cross-entropy、entropy 和 KL divergence 会依次出现,因为前一个概念会留下一个尚未回答的编码问题。所有对数均以 2 为底,因此码长单位都是 bit

推导路线:第 1 节把信息看作通信。先有码长:分布 q 决定理想码长,真实数据按照 p 出现,对码长取平均得到交叉熵;匹配编码 q = p 给出熵,分布失配造成的差值就是 KL divergence。第 2 节把这些概念带入监督学习,其中输入是侧信息,标签是需要预测的结果。第 3 节再次转换视角,不再研究信源的平均行为,而是研究复现某个具体对象所需的最短程序。

1.1 From Code Length to Probability-Aware Coding

Before counting bits, we need to say where the outcomes come from. A source is a process that produces data. Its set of possible outputs is called an alphabet \(\mathcal Z\). Examples include:

  • a coin producing heads or tails;
  • a sensor producing one of several readings;
  • a text process producing the next character or token.

The source is not one particular output. It is the repeatable mechanism that may emit many outputs \(Z_1,Z_2,\ldots\). In the simplest memoryless model, each output is drawn independently from the same distribution \(p(z)\). This distribution tells us the long-run frequency with which each symbol appears.

Why encode a source? Computers store and communication channels transmit bits, while the source produces symbols such as words, labels, or sensor values. An encoder maps each emitted symbol—or a block of symbols—to bits; a decoder must recover the original data. We want this mapping to be lossless while using as few bits as possible.

Strictly speaking, we do not encode the abstract source or the distribution \(p\) itself. We encode the outputs produced by the source, using a code designed around their frequencies. “Encoding the source” is standard shorthand for this operation. For one isolated output, saving a fraction of a bit is not very meaningful; over a long sequence, small savings in average length accumulate into substantial storage or transmission savings.

Now suppose the source alphabet has eight possible outcomes and, for the moment, we use the same number of bits for all of them. Three bits are enough:

\[000,001,010,011,100,101,110,111.\]

The reason is counting: \(\ell\) bits create \(2^\ell\) distinct strings. Therefore, distinguishing \(N\) equally treated outcomes requires at least

\[\ell=\lceil\log_2N\rceil\]

bits. This statement involves no probabilities and no entropy. It is simply the capacity of a binary description.

There is another useful way to see the same count. Imagine all infinite binary sequences as a unit interval. Fixing the first bit selects half of them. Fixing two bits selects one quarter. In general, a particular prefix of length \(\ell\) occupies

\[\underbrace{\frac12\times\cdots\times\frac12}_{\ell\text{ times}}=2^{-\ell}\]

of the binary coding space. A shorter prefix reserves a larger region; a longer prefix reserves a smaller one. This geometric fact—length \(\ell\) corresponds to a share \(2^{-\ell}\)—is the bridge from code lengths to probabilities, but we have not crossed that bridge yet.

在计算 bit 之前,先要说明这些结果从哪里来。信源(source)是一个产生数据的过程,它所有可能输出组成的集合称为字母表 \(\mathcal Z\)。例如:

  • 一枚硬币产生“正面”或“反面”;
  • 一个传感器产生若干可能读数之一;
  • 一个文本过程产生下一个字符或 token。

信源不是某一个具体输出,而是可以反复产生许多输出 \(Z_1,Z_2,\ldots\) 的机制。在最简单的无记忆信源模型中,每次输出都独立地来自同一个分布 \(p(z)\)。这个分布描述各符号长期出现的频率。

为什么要对信源编码?计算机存储和通信信道传输的是 bit,而信源产生的可能是单词、标签或传感器读数。编码器把每个已产生符号——或一组符号——映射成 bit;解码器则必须从这些 bit 恢复原始数据。我们的目标是在无损恢复的前提下尽量少用 bit。

严格来说,我们不是对抽象的信源或分布 \(p\) 本身编码,而是对信源产生的输出编码,并根据它们的出现频率设计编码。“对信源编码”只是这种操作的惯用简称。对一个孤立结果,节省零点几个 bit 没有太大意义;对很长的输出序列,平均码长上的微小节省会累积成可观的存储或传输收益。

现在假设信源的字母表中有 8 个可能结果,并且暂时为每个结果使用相同长度的编码。3 bit 就足够:

\[000,001,010,011,100,101,110,111.\]

原因只是计数:\(\ell\) bit 可以产生 \(2^\ell\) 个不同字符串。因此,要区分 \(N\) 个被同等对待的结果,至少需要

\[\ell=\lceil\log_2N\rceil\]

bit。这里还没有概率,也没有熵,只是在计算二进制描述的容量。

还可以从另一个角度理解同一件事。把所有无限二进制序列想象成一个单位区间。固定第一位,会选中其中一半;固定前两位,会选中四分之一。一般地,一个指定的 \(\ell\) 位前缀占据的二进制编码空间为

\[\underbrace{\frac12\times\cdots\times\frac12}_{\ell\text{ 次}}=2^{-\ell}.\]

短前缀保留较大的区域,长前缀保留较小的区域。这个几何事实——长度 \(\ell\) 对应空间份额 \(2^{-\ell}\)——将把码长和概率连接起来,但我们暂时还没有使用概率。

Why should frequency affect code length at all? Consider four outcomes with frequencies

\[A:\frac12,\qquad B:\frac14,\qquad C:\frac18,\qquad D:\frac18.\]

A fixed-length code for four outcomes needs two bits each, for example 00, 01, 10, 11. In eight transmissions, we expect to send \(A\) four times, \(B\) twice, and \(C,D\) once each. The fixed-length code therefore uses

\[4\times2+2\times2+1\times2+1\times2=16\ \text{bits}.\]

Now try 0, 10, 110, 111. Bob can still decode the stream because no codeword is the beginning of another. The same eight outcomes use

\[4\times1+2\times2+1\times3+1\times3=14\ \text{bits}.\]

The common outcome \(A\) saves one bit on each of four appearances. The rare outcomes \(C,D\) each cost one extra bit, but they appear only once. The frequent savings outweigh the rare extra costs. That is why equal-length codes waste bits when frequencies are unequal: they spend scarce short descriptions on outcomes that hardly occur.

This example suggests the rule we want to formalize: common outcomes should receive short codewords and rare outcomes may receive longer ones.

A safe variable-length code must still be decodable. The usual requirement is prefix-free: no complete codeword may be the prefix of another. Such a code is a binary tree, and its lengths obey the Kraft inequality

\[\sum_z2^{-\ell(z)}\le1.\]

The meaning is concrete: \(2^{-\ell(z)}\) is the region reserved by the prefix for outcome \(z\), and disjoint regions cannot occupy more than the whole coding space.

Now introduce a distribution \(q(z)\). Think of \(q\) as the encoder’s belief about how frequently outcomes will occur. To allocate a fraction of coding space close to \(q(z)\), match

\[2^{-\ell_q(z)}\approx q(z).\]

Solving for length gives the ideal, possibly fractional code length

\[\boxed{\ell_q(z)=-\log_2q(z)}.\]

The same quantity is called the self-information or surprisal of outcome \(z\) under \(q\):

\[I_q(z)=-\log_2q(z).\]

The name “surprisal” is intuitive, but code length is the derivation: an outcome to which the encoder assigns small probability receives little coding space and therefore needs a long address. The logarithm also makes the lengths of two independent outcomes add:

\[-\log_2[q(z_1)q(z_2)]= -\log_2q(z_1)-\log_2q(z_2).\]

For dyadic probabilities the correspondence is exact:

Outcome \(q(z)\) Codeword \(\ell_q(z)\)
A \(1/2\) 0 1
B \(1/4\) 10 2
C \(1/8\) 110 3
D \(1/8\) 111 3

For example, the prefix 10 occupies one quarter of the coding space, matching \(q(B)=1/4\), and has length \(-\log_2(1/4)=2\) bits.

Real codewords have integer lengths, whereas \(-\log_2q(z)\) can be fractional. Huffman coding chooses integer tree depths. Arithmetic coding instead encodes a long sequence as one interval, so its length per symbol can approach the fractional ideal arbitrarily closely. From now on, “code length” means this ideal or asymptotic length unless stated otherwise.

为什么出现频率应该影响码长?考虑四个结果,其频率为

\[A:\frac12,\qquad B:\frac14,\qquad C:\frac18,\qquad D:\frac18.\]

四个结果的定长编码每个需要 2 bit,例如 00011011。在 8 次发送中,我们预计 \(A\) 出现 4 次,\(B\) 出现 2 次,\(C,D\) 各出现 1 次。于是定长编码总共使用

\[4\times2+2\times2+1\times2+1\times2=16\ \text{bits}.\]

现在改用 010110111。Bob 仍然能够解码,因为任何一个码字都不是另一个码字的开头。同样 8 个结果只需要

\[4\times1+2\times2+1\times3+1\times3=14\ \text{bits}.\]

常见结果 \(A\) 每出现一次节省 1 bit,而且它出现 4 次;罕见结果 \(C,D\) 虽然各多花 1 bit,却各只出现一次。常见结果带来的节省超过了罕见结果增加的代价。这才是频率不同时定长编码会浪费 bit 的原因:它把宝贵的短描述也分配给了几乎不出现的结果。

这个例子提示了接下来要形式化的规则:常见结果应该得到短码字,罕见结果可以使用更长的码字。

变长编码仍然必须能够被唯一解码。通常要求编码是前缀码:任何完整码字都不能是另一个码字的前缀。这样的编码构成一棵二叉树,其码长满足 Kraft inequality

\[\sum_z2^{-\ell(z)}\le1.\]

现在这个式子的含义很具体:\(2^{-\ell(z)}\) 是结果 \(z\) 的前缀所保留的区域,互不重叠的区域不可能占据超过整个编码空间。

接着引入分布 \(q(z)\)。可以把 \(q\) 理解为编码器对各结果出现频率的判断。为了给结果 \(z\) 分配接近 \(q(z)\) 的编码空间份额,我们令

\[2^{-\ell_q(z)}\approx q(z).\]

解出码长,得到理想的、可能为分数的码长:

\[\boxed{\ell_q(z)=-\log_2q(z)}.\]

同一个量也称为结果 \(z\) 在 \(q\) 下的自信息量surprisal

\[I_q(z)=-\log_2q(z).\]

“Surprisal”这个名字很直观,但码长才是这里的推导来源:编码器给某个结果的概率越小,为它保留的编码空间越少,它就需要越长的地址。对数还会让连续独立结果的码长相加:

\[-\log_2[q(z_1)q(z_2)]= -\log_2q(z_1)-\log_2q(z_2).\]

对于二进制幂概率,这个对应关系可以精确实现:

结果 \(q(z)\) 码字 \(\ell_q(z)\)
A \(1/2\) 0 1
B \(1/4\) 10 2
C \(1/8\) 110 3
D \(1/8\) 111 3

例如,前缀 10 占据四分之一编码空间,与 \(q(B)=1/4\) 匹配,长度为 \(-\log_2(1/4)=2\) bit。

实际码字的长度必须是整数,而 \(-\log_2q(z)\) 可能是分数。Huffman coding 会选择整数树深度;arithmetic coding 则把长序列编码成一个区间,使每个符号的平均长度可以任意逼近这个分数理想值。下文若无特殊说明,“码长”均指这种理想或渐近码长。

1.2 Describing Real Data with a Model Distribution: Cross-Entropy

We now give a model distribution \(q\) the job of describing data generated from the real distribution \(p\). The model first assigns every possible outcome a probability \(q(z)\). As Section 1.1 showed, this probability implies the ideal code length \(\ell_q(z)=-\log_2q(z)\) when outcome \(z\) occurs.

Cross-entropy is not the distribution \(q\) by itself. It is the score obtained when the probabilities supplied by \(q\) are repeatedly tested on outcomes supplied by \(p\). To turn the one-outcome cost into an overall model cost, we therefore need to know how often each outcome actually occurs.

Separate the two roles explicitly:

  • \(p(z)\) is the true data-generating distribution;
  • \(q(z)\) is the encoder’s model, which determines the lengths.

Suppose outcome \(z\) appears in a fraction \(p(z)\) of a long sequence. Its code length \(-\log_2q(z)\) is then paid with that same frequency. Therefore

\[\begin{aligned} \text{average length} &=\sum_z \underbrace{p(z)}_{\text{frequency}}\underbrace{[-\log_2q(z)]}_{\text{length when }z\text{ occurs}}\\ &=\mathbb E_{Z\sim p}[-\log_2q(Z)]. \end{aligned}\]

This average is called the cross-entropy:

\[\boxed{H(p,q)=-\sum_zp(z)\log_2q(z)}.\]

Nothing new was assumed: it is simply “frequency times cost, summed over outcomes.” Notice why the distributions occupy different positions. The outer weight is \(p\) because reality decides what appears; the logarithm contains \(q\) because the encoder decides the length.

What does “the same outcome space” mean? Let \(\mathcal Z\) be the list of results that may occur. Both distributions must refer to that same list:

\[p:\mathcal Z\to[0,1],\qquad q:\mathcal Z\to[0,1].\]

For example, if \(\mathcal Z=\{\text{cat},\text{dog},\text{bird}\}\), then \(p\) describes how often those three labels truly occur, while \(q\) gives the encoder’s or classifier’s probabilities for those same three labels. When “dog” occurs, its true frequency \(p(\text{dog})\) weights the length \(-\log_2q(\text{dog})\). The two entries must name the same event for this product to make sense.

A distribution over weather outcomes \(\{\text{sun},\text{rain}\}\) cannot be used as \(q\) when \(p\) is over animal labels: there is no shared outcome \(z\) whose true frequency and assigned code length can be paired. We also require \(q(z)>0\) whenever \(p(z)>0\); otherwise a possible result is assigned an infinite code length.

Therefore, cross-entropy compares two probability assignments over the same possible results. It is not a measure of association between two random variables. We also did not need entropy to derive it—only a model-based code length and a true occurrence frequency.

With samples \(z_1,\ldots,z_n\), replace the population frequencies by an empirical average:

\[\widehat H(p,q)=-\frac1n\sum_{i=1}^n\log_2q(z_i).\]

现在让模型分布 \(q\) 负责描述由真实分布 \(p\) 产生的数据。模型首先为每个可能结果分配概率 \(q(z)\);第 1.1 节已经说明,当结果 \(z\) 出现时,这个概率对应理想码长 \(\ell_q(z)=-\log_2q(z)\)。

交叉熵并不是模型分布 \(q\) 本身,而是把 \(q\) 给出的概率反复用在 \(p\) 产生的真实结果上之后得到的评分。为了把单次结果的代价变成模型的总体代价,我们还必须知道每种结果实际出现得多频繁。

把两个角色明确分开:

  • \(p(z)\) 是真实的数据生成分布;
  • \(q(z)\) 是编码器使用的模型,它决定码长。

假设在一段很长的序列中,结果 \(z\) 出现的比例是 \(p(z)\),那么码长 \(-\log_2q(z)\) 也会以同样的频率被支付。因此

\[\begin{aligned} \text{平均码长} &=\sum_z \underbrace{p(z)}_{\text{出现频率}}\underbrace{[-\log_2q(z)]}_{z\text{ 出现时的码长}}\\ &=\mathbb E_{Z\sim p}[-\log_2q(Z)]. \end{aligned}\]

这个平均值称为交叉熵

\[\boxed{H(p,q)=-\sum_zp(z)\log_2q(z)}.\]

这里没有引入新的假设,只是“频率乘以代价,再对所有结果求和”。注意两个分布为什么出现在不同位置:外面的权重是 \(p\),因为现实决定什么会出现;对数里面是 \(q\),因为编码器决定码长。

“同一个结果空间”是什么意思?令 \(\mathcal Z\) 表示所有可能结果的列表。两个分布必须都在这份相同的列表上分配概率:

\[p:\mathcal Z\to[0,1],\qquad q:\mathcal Z\to[0,1].\]

例如,若 \(\mathcal Z=\{\text{猫},\text{狗},\text{鸟}\}\),那么 \(p\) 描述这三个标签真实出现的频率,\(q\) 则给编码器或分类器对这同三个标签分配的概率。当“狗”出现时,用它的真实频率 \(p(\text{狗})\) 乘以模型为“狗”分配的码长 \(-\log_2q(\text{狗})\)。两个位置必须指向同一个事件,这个乘积才有意义。

如果 \(p\) 定义在动物标签 \(\{\text{猫},\text{狗},\text{鸟}\}\) 上,就不能把定义在天气结果 \(\{\text{晴},\text{雨}\}\) 上的分布作为 \(q\):此时没有共同结果 \(z\),无法把真实频率与模型码长一一配对。此外,只要 \(p(z)>0\),就必须有 \(q(z)>0\);否则一个可能发生的结果会被分配无限码长。

因此,更直白地说,交叉熵比较的是对同一组可能结果作出的两套概率分配,而不是两个随机变量之间的相关性。推导它也不需要预先定义熵,只需要模型给出的码长和真实出现频率。

对于样本 \(z_1,\ldots,z_n\),用经验平均代替总体频率:

\[\widehat H(p,q)=-\frac1n\sum_{i=1}^n\log_2q(z_i).\]

1.3 The Cost That Remains with a Perfect Model: Entropy

Keep the roles fixed: outputs are generated by a source whose true distribution is \(p\), while we choose a model \(q\) and use it to assign probabilities and hence code lengths. Thus in \(H(p,q)\), the first argument describes the source distribution and the second describes the coding model. With \(p\) held fixed, the next question is: how small could this cost become if the model were perfect?

The theoretical answer assumes that \(p\) is known. In practice it is unknown, which is precisely why a model must learn an approximation \(q\) from samples.

If the encoder knows the true distribution, it should allocate coding space according to that same distribution: set \(q=p\). The code length for one outcome becomes

\[\ell_p(z)=-\log_2p(z),\]

and its average becomes

\[\boxed{H(p)=\mathbb E_{Z\sim p}[-\log_2p(Z)]=-\sum_zp(z)\log_2p(z)}.\]

The average cost that still remains at this perfect-model reference point is the Shannon entropy. Entropy is not the act of making a model fit reality, nor does its definition claim that a learned model is actually perfect. It is a property of \(p\): the irreducible expected information in source outcomes when the probability model has no mismatch. Thus it is the special value of cross-entropy obtained under the theoretical choice \(q=p\):

\[H(p)=H(p,p).\]

Does Shannon entropy assume that we know \(p\)? The definition treats \(p\) as the source’s true distribution, but it does not claim that an observer knows it. These are different statements:

  • the source has some distribution \(p\);
  • we know \(p\) well enough to calculate or use it.

Exact knowledge is possible when the mechanism is specified by construction—for example, a programmed random generator or an idealized fair die. If \(p\) is an unknown real-world distribution, however, a finite sample cannot determine it exactly in general. Events not seen in the sample may still have positive probability, and many different distributions can produce the same finite observations.

For a finite alphabet, a common estimate replaces \(p\) by empirical frequencies

\[\widehat p_n(z)=\frac1n\sum_{i=1}^n\mathbf 1\{Z_i=z\},\]

and computes

\[\widehat H_n=-\sum_z\widehat p_n(z)\log_2\widehat p_n(z).\]

Under an i.i.d. finite-alphabet assumption, this plug-in estimate converges to \(H(p)\) as \(n\to\infty\). At finite \(n\) it has sampling uncertainty, typically underestimates entropy, and can miss rare outcomes. For large or structured spaces—natural language is the main example—estimating the full entropy is much harder because most possible contexts and sequences are never repeated.

There is an important measurement asymmetry. We can estimate the cross-entropy of a fixed model \(q\) directly on held-out samples without knowing the numerical values of \(p(z)\):

\[\widehat H(p,q)=-\frac1n\sum_{i=1}^n\log_2q(z_i).\]

The samples supply occurrences from \(p\), and the model supplies their lengths. But this measures \(H(p,q)=H(p)+D_{\mathrm{KL}}(p\Vert q)\). Without more assumptions, it does not tell us how much came from the source’s entropy and how much came from model mismatch. In an LLM, held-out next-token loss estimates model cross-entropy; the true conditional entropy of language is generally not directly observable.

Compression offers another operational estimate: a strong universal compressor can approach the entropy rate for certain stationary ergodic sources. A finite compressed file is still not an exact entropy measurement—it includes model mismatch, headers, finite-length overhead, and implementation constraints.

Entropy is a property of a distribution, not of one realized outcome. A single outcome has a code length or surprisal; the distribution has an average length or entropy.

For a Bernoulli source with \(p(Z=1)=\theta\),

\[H_2(\theta)=-\theta\log_2\theta-(1-\theta)\log_2(1-\theta).\]

If \(\theta=0\) or \(1\), the outcome is known in advance and the ideal average length is zero. If \(\theta=1/2\), both outcomes are equally likely and one bit is necessary. More generally,

\[0\le H(Z)\le\log_2\lvert\mathcal Z\rvert,\]

with the maximum attained by the uniform distribution.

Does Shannon entropy measure the shortest code length? It depends on which notion of length is intended:

  1. Ideal real-valued length: yes. Assigning \(\ell(z)=-\log_2p(z)\) gives the average \(H(Z)\) exactly.
  2. One-symbol binary prefix code: not always exactly. Actual codewords contain an integer number of bits, and the optimal expected length \(L_1^*\) satisfies

    \[H(Z)\le L_1^*<H(Z)+1.\]

    Equality is possible when all nonzero probabilities are dyadic, so every \(-\log_2p(z)\) is an integer. Otherwise an integer code generally sits above entropy. For example, if two outcomes have probabilities \(0.9\) and \(0.1\), any one-symbol binary prefix code needs two distinct codewords such as 0 and 1, hence \(L_1^*=1\) bit, while \(H_2(0.1)\approx0.469\) bit.

  3. Long-block or arithmetic code: yes in the asymptotic per-symbol sense. Encoding blocks of \(n\) source symbols lets the fixed rounding overhead be shared across the block, so

    \[H(Z)\le\frac{L_n^*}{n}<H(Z)+\frac1n.\]

    The gap per symbol tends to zero as \(n\to\infty\).

Thus Shannon entropy is best described as the fundamental lower bound and asymptotically achievable rate for lossless compression of a known memoryless source—not necessarily the exact length of the shortest finite codeword or even the exact optimum for a one-symbol code. For sources with memory, the corresponding limit is the entropy rate; for lossy compression, the relevant limit is the rate–distortion function rather than entropy alone.

先固定两个角色:输出由真实分布为 \(p\) 的信源产生;我们选择模型 \(q\),用它分配概率,进而决定码长。因此在 \(H(p,q)\) 中,第一个参数描述信源分布,第二个参数描述编码模型。保持 \(p\) 不变,接下来的问题是:如果模型已经完美,这项代价最低能降到多少?

理论上的回答暂时假设 \(p\) 已知;实践中 \(p\) 未知,这正是我们需要从样本中学习近似模型 \(q\) 的原因。

如果编码器知道真实分布,就应该按照同一个分布分配编码空间,也就是令 \(q=p\)。一次结果的码长变为

\[\ell_p(z)=-\log_2p(z),\]

平均码长变为

\[\boxed{H(p)=\mathbb E_{Z\sim p}[-\log_2p(Z)]=-\sum_zp(z)\log_2p(z)}.\]

在这个完美模型基准上仍然保留的平均代价,就是 Shannon entropy。熵不是“让模型匹配现实”这个动作,它的定义也没有声称实际学到的模型真的完美。它是 \(p\) 的性质:当概率模型不存在失配时,信源结果仍然具有的不可消除期望信息量。因此,熵是理论选择 \(q=p\) 时交叉熵取得的特殊值:

\[H(p)=H(p,p).\]

Shannon entropy 是否假设我们知道 \(p\)? 定义把 \(p\) 看作信源的真实分布,但它并没有声称观察者已经知道这个分布。下面两件事不同:

  • 信源客观上具有某个分布 \(p\);
  • 我们对 \(p\) 的了解足以精确计算或使用它。

如果生成机制由设计直接给出,例如程序化随机数生成器或理想公平骰子,那么精确知道 \(p\) 是可能的。但如果 \(p\) 是未知的现实世界分布,有限样本通常不可能唯一确定它。样本中没有出现的事件仍可能具有正概率,而且许多不同分布都可能产生同一组有限观测。

对于有限字母表,常见做法是用经验频率代替 \(p\):

\[\widehat p_n(z)=\frac1n\sum_{i=1}^n\mathbf 1\{Z_i=z\},\]

然后计算

\[\widehat H_n=-\sum_z\widehat p_n(z)\log_2\widehat p_n(z).\]

在有限字母表和 i.i.d. 假设下,当 \(n\to\infty\) 时,这个 plug-in estimate 会收敛到 \(H(p)\)。但在有限样本下,它存在采样不确定性,通常会低估熵,也可能完全遗漏稀有结果。对于自然语言这样的巨大、结构化空间,完整熵的估计更困难,因为绝大多数可能 context 和 sequence 都不会重复出现。

这里存在一个重要的测量不对称:即使不知道 \(p(z)\) 的具体数值,我们仍可以在 held-out samples 上直接估计一个固定模型 \(q\) 的交叉熵:

\[\widehat H(p,q)=-\frac1n\sum_{i=1}^n\log_2q(z_i).\]

样本负责提供来自 \(p\) 的实际结果,模型负责提供这些结果的码长。但测得的是 \(H(p,q)=H(p)+D_{\mathrm{KL}}(p\Vert q)\)。如果没有额外假设,我们无法判断其中多少来自信源本身的熵,多少来自模型失配。对于 LLM,held-out next-token loss 估计的是模型交叉熵;语言真正的条件熵一般无法被直接观测。

压缩还提供了另一种操作性估计:对某些 stationary ergodic sources,优秀的 universal compressor 可以逼近其熵率。但一个有限文件的压缩后大小仍不是精确熵测量,因为它同时包含模型失配、文件头、有限长度开销和实现限制。

熵是分布的性质,而不是某一次已实现结果的性质。单个结果有码长或 surprisal;整个分布才有平均码长或 entropy。

对于满足 \(p(Z=1)=\theta\) 的 Bernoulli 信源,

\[H_2(\theta)=-\theta\log_2\theta-(1-\theta)\log_2(1-\theta).\]

当 \(\theta=0\) 或 \(1\) 时,结果可以预先确定,理想平均码长为 0;当 \(\theta=1/2\) 时,两个结果等概率,需要 1 bit。更一般地,

\[0\le H(Z)\le\log_2\lvert\mathcal Z\rvert,\]

均匀分布取得最大值。

Shannon entropy 是否衡量最短码长?答案取决于这里所说的是哪一种码长:

  1. 允许实数的理想码长:是。令 \(\ell(z)=-\log_2p(z)\),其平均值恰好就是 \(H(Z)\)。
  2. 一次只编码一个符号的二进制前缀码:不一定严格相等。真实码字只能包含整数个 bits,其最优期望码长 \(L_1^*\) 满足

    \[H(Z)\le L_1^*<H(Z)+1.\]

    如果所有非零概率都是 dyadic probabilities,使每个 \(-\log_2p(z)\) 都是整数,就可能取等;否则整数码长通常高于熵。例如,两个结果的概率分别是 \(0.9\) 和 \(0.1\) 时,任何单符号二进制前缀码都需要两个不同码字,例如 01,所以 \(L_1^*=1\) bit;但 \(H_2(0.1)\approx0.469\) bit。

  3. 长序列分组编码或 arithmetic coding:在渐近的每符号意义下是。把 \(n\) 个信源符号组成一组后,固定的取整开销可以由整组分摊,因此

    \[H(Z)\le\frac{L_n^*}{n}<H(Z)+\frac1n.\]

    当 \(n\to\infty\) 时,每个符号的差距趋于零。

因此,更准确的说法是:Shannon entropy 是已知无记忆信源进行无损压缩时的基本下界和渐近可达速率,但不一定等于某个有限码字的长度,也不一定严格等于单符号编码的最优平均长度。对存在记忆的信源,相应极限是 entropy rate;对有损压缩,相应极限是 rate–distortion function,而不只是 entropy。

1.4 The Cost of Using the Wrong Code: KL Divergence

We now have two average lengths for the same source \(p\):

  • \(H(p)\): use the matched code built from \(p\);
  • \(H(p,q)\): use the code built from another distribution \(q\).

The natural measure of mismatch is simply the extra length:

\[\begin{aligned} H(p,q)-H(p) &=\sum_zp(z)[-\log_2q(z)]-\sum_zp(z)[-\log_2p(z)]\\ &=\sum_zp(z)\log_2\frac{p(z)}{q(z)}. \end{aligned}\]

This difference is the Kullback–Leibler divergence:

\[\boxed{D_{\mathrm{KL}}(p\Vert q)=\mathbb E_{Z\sim p}\!\left[\log_2\frac{p(Z)}{q(Z)}\right]}.\]

Therefore the central identity is not a separate fact to memorize; it is the bookkeeping equation “mismatched length = matched length + extra length”:

\[\boxed{H(p,q)=H(p)+D_{\mathrm{KL}}(p\Vert q)}.\]

Why is the extra cost nonnegative? The ideal or asymptotic code matched to the true frequencies is optimal in expected length; changing its allocation cannot improve the average. Formally, Gibbs’ inequality gives

\[D_{\mathrm{KL}}(p\Vert q)\ge0,\]

with equality when the normalized distributions \(p\) and \(q\) are the same (ignoring zero-probability events). KL is therefore nonnegative, not strictly positive.

Why, then, do “KL” values sometimes look negative in everyday training? The nonnegativity statement applies to the complete expectation, not to every outcome inside it. The pointwise log-ratio

\[\log_2\frac{p(z)}{q(z)}\]

is negative whenever \(p(z)<q(z)\). For example, let \(p=(0.9,0.1)\) and \(q=(0.5,0.5)\). The two contributions to forward KL are

\[0.9\log_2\frac{0.9}{0.5}\approx0.763, \qquad 0.1\log_2\frac{0.1}{0.5}\approx-0.232.\]

The second contribution is negative, but the full sum is

\[D_{\mathrm{KL}}(p\Vert q)\approx0.763-0.232=0.531\ge0.\]

The same distinction applies to estimation. If we sample \(Z_i\sim p\) and report

\[\widehat D=\frac1n\sum_{i=1}^n\log_2\frac{p(Z_i)}{q(Z_i)},\]

then \(\widehat D\) is a finite-sample estimate of KL and can be negative by chance, even though its population expectation cannot be. In LLM and RL code, a logged “KL” is often a per-token log-ratio, a minibatch mean, or a clipped or otherwise approximate surrogate. Those quantities may be negative. A negative value is not a counterexample to Gibbs’ inequality; it means the logged quantity is not the exact full-distribution KL.

The order matters. In \(D_{\mathrm{KL}}(p\Vert q)\), data are averaged according to \(p\) while lengths come from \(q\). Reversing them describes a different coding experiment, so KL is generally asymmetric and is not a distance metric. If \(p(z)>0\) but \(q(z)=0\), the model gives infinite length to an event that can occur, and the forward KL is infinite.

现在,对于同一个信源 \(p\),我们有两个平均码长:

  • \(H(p)\):使用按照 \(p\) 构造的匹配编码;
  • \(H(p,q)\):使用按照另一个分布 \(q\) 构造的编码。

最自然的失配度量就是二者相差的码长:

\[\begin{aligned} H(p,q)-H(p) &=\sum_zp(z)[-\log_2q(z)]-\sum_zp(z)[-\log_2p(z)]\\ &=\sum_zp(z)\log_2\frac{p(z)}{q(z)}. \end{aligned}\]

这个差值就是 Kullback–Leibler divergence

\[\boxed{D_{\mathrm{KL}}(p\Vert q)=\mathbb E_{Z\sim p}\!\left[\log_2\frac{p(Z)}{q(Z)}\right]}.\]

因此,核心恒等式不是需要单独背诵的事实,它只是“失配码长 = 匹配码长 + 额外码长”这句账目关系:

\[\boxed{H(p,q)=H(p)+D_{\mathrm{KL}}(p\Vert q)}.\]

为什么额外代价不会为负?因为匹配真实频率的理想编码或渐近编码已经使期望码长最短,改变编码空间分配不能进一步改善平均值。形式上,Gibbs inequality 给出

\[D_{\mathrm{KL}}(p\Vert q)\ge0,\]

且当归一化分布 \(p\) 与 \(q\) 相同(忽略零概率事件)时取等号。因此,KL 是非负的,而不是严格恒正的。

那么,为什么日常训练中有时会看到负的“KL”?非负性约束的是完整期望,而不是期望中的每一个结果。逐点 log-ratio

\[\log_2\frac{p(z)}{q(z)}\]

在 \(p(z)<q(z)\) 时就是负数。例如,令 \(p=(0.9,0.1)\)、\(q=(0.5,0.5)\),forward KL 中两个结果的贡献分别为

\[0.9\log_2\frac{0.9}{0.5}\approx0.763, \qquad 0.1\log_2\frac{0.1}{0.5}\approx-0.232.\]

第二项为负,但完整求和仍然是

\[D_{\mathrm{KL}}(p\Vert q)\approx0.763-0.232=0.531\ge0.\]

估计量也有同样的区别。如果从 \(p\) 中采样 \(Z_i\),并计算

\[\widehat D=\frac1n\sum_{i=1}^n\log_2\frac{p(Z_i)}{q(Z_i)},\]

那么 \(\widehat D\) 只是 KL 的有限样本估计,可能因为采样波动而为负,但它的总体期望不会为负。在 LLM 和 RL 代码中,日志里的“KL”经常是逐 token log-ratio、minibatch mean,或者经过 clipping 等处理的近似 surrogate;这些量都可能为负。负值不是 Gibbs inequality 的反例,它说明日志中的量并不是精确的全分布 KL。

顺序非常重要。在 \(D_{\mathrm{KL}}(p\Vert q)\) 中,数据按照 \(p\) 取平均,而码长由 \(q\) 决定。交换二者描述的是另一个编码实验,所以 KL 一般不对称,也不是距离度量。若 \(p(z)>0\) 而 \(q(z)=0\),模型给一个可能发生的事件分配了无限码长,forward KL 因而为无穷大。

Figure 1: Adjust the true Bernoulli source p and the coding model q. Matching q to p removes the KL excess length and makes cross-entropy equal entropy.
图 1:调节真实 Bernoulli 信源 p 与编码模型 q。当 q 与 p 匹配时,KL 额外码长消失,交叉熵等于熵。

2. Information Theory in Supervised Learning

Nothing distributional disappears when we enter supervised learning. Section 1 used one generic source variable \(Z\sim p_Z\) on an outcome space \(\mathcal Z\). A supervised-data source instead emits a pair:

\[\boxed{(X,Y)\sim p_{XY}\quad\text{on}\quad\mathcal X\times\mathcal Y}.\]

The uppercase letters name the two coordinates of a random pair; lowercase \(x,y\) denote values that were actually observed. Their joint distribution \(p_{XY}(x,y)\) determines everything that follows. For discrete variables it gives the marginals and conditionals

\[p_X(x)=\sum_y p_{XY}(x,y),\qquad p_Y(y)=\sum_x p_{XY}(x,y),\qquad p_{Y\mid X}(y\mid x)=\frac{p_{XY}(x,y)}{p_X(x)}\quad\text{for }p_X(x)>0.\]

Thus \(X\) and \(Y\) do not replace distributions. They let us refer compactly to the joint distribution, its marginals, and the family of conditional label distributions indexed by \(x\). Once an input \(x\) is known, the true distribution over labels is \(p_{Y\mid X}(\cdot\mid x)\), while the model proposes another distribution \(q_\theta(\cdot\mid x)\) on the same label space. The coding interpretation treats \(X\) as information already available to both sides and \(Y\) as the outcome to describe.

进入监督学习之后,distribution 并没有消失。第 1 节只使用一个泛指的信源变量 \(Z\sim p_Z\),其结果空间为 \(\mathcal Z\);监督数据的信源则每次产生一个成对结果

\[\boxed{(X,Y)\sim p_{XY}\quad\text{定义在}\quad\mathcal X\times\mathcal Y\text{ 上}}.\]

大写字母表示随机对中的两个坐标,小写 \(x,y\) 表示实际观测到的取值。后面的所有量都由联合分布 \(p_{XY}(x,y)\) 决定。对离散变量,它进一步给出 marginal 与 conditional distributions:

\[p_X(x)=\sum_y p_{XY}(x,y),\qquad p_Y(y)=\sum_x p_{XY}(x,y),\qquad p_{Y\mid X}(y\mid x)=\frac{p_{XY}(x,y)}{p_X(x)}\quad\text{当 }p_X(x)>0.\]

所以,\(X\) 和 \(Y\) 并没有取代 distribution;它们只是让我们可以简洁地指代联合分布、边缘分布,以及由不同 \(x\) 索引的一族条件标签分布。知道输入 \(x\) 后,标签的真实分布是 \(p_{Y\mid X}(\cdot\mid x)\),模型则在同一个标签空间上提出另一个分布 \(q_\theta(\cdot\mid x)\)。在编码解释中,\(X\) 是通信双方已经拥有的信息,\(Y\) 是需要描述的结果。

2.1 From Coding to Supervised Learning

Viewed this way, supervised learning does not introduce a different kind of cross-entropy. It takes the earlier one-outcome coding problem and adds side information: instead of using one unconditional code \(q(z)\), it selects an input-dependent code \(q_\theta(y\mid x)\) after observing \(x\).

First separate the machine-learning task from its coding interpretation. In supervised learning, the predictive model reads an input \(x\) and outputs a probability distribution \(q_\theta(\cdot\mid x)\) over possible labels. For example, after reading an image, a classifier might assign probability \(0.8\) to “cat” and \(0.2\) to “dog.” No literal message needs to be transmitted during training.

To interpret its loss as code length, imagine a separate communication experiment. An encoder sees the realized label \(y\) and turns it into bits using the code determined by \(q_\theta(\cdot\mid x)\). A decoder receives those bits and recovers the label. Both must already know \(x\); otherwise they could not agree on which input-dependent codebook to use. Here, \(x\) is side information, while \(y\) is the outcome being encoded. The ideal length of its code is therefore \(-\log_2q_\theta(y\mid x)\).

The predictor is thus the model that supplies the probabilities; the encoder and decoder are conceptual devices that reveal what those probabilities mean in bits. Both cases follow one rule:

\[\boxed{\text{cross-entropy}=\mathbb E[-\log_2 q(\text{outcome}\mid\text{available side information})]}.\]

With no side information, the condition is empty and this reduces to \(\mathbb E[-\log_2q(Z)]\). With \(X\) known, it becomes \(\mathbb E[-\log_2q_\theta(Y\mid X)]\). Equivalently, the chain rule \(q(x,y)=q(x)q(y\mid x)\) gives

\[-\log_2q(x,y)=-\log_2q(x)-\log_2q(y\mid x).\]

The first term encodes the input itself; the second encodes the label after the input is already known. A supervised loss normally charges only the second term because the task is to predict \(Y\) from the given \(X\).

Now let

  • \(X\) be the input;
  • \(Y\) be the label to predict;
  • \(p(x,y)\) be the real joint distribution of input-label pairs;
  • \(p(x)\) and \(p(y)\) be its two marginal distributions;
  • \(p(y\mid x)\) be the true label distribution after input \(x\) is known;
  • \(q_\theta(y\mid x)\) be the model’s predictive distribution.

Before inserting these objects into the loss, it helps to follow exactly what a classifier computes. For \(K\) classes, its final layer usually emits a vector

\[\mathbf z_\theta(x)=(z_1,\ldots,z_K)\in\mathbb R^K.\]

Each \(z_k\) is a logit: an unrestricted, unnormalized score for class \(k\). A logit may be negative and the logits do not have to sum to one. Softmax turns them into the normalized predictive distribution

\[\underbrace{q_\theta(k\mid x)}_{\text{probability of class }k} =\operatorname{softmax}(\mathbf z)_k =\frac{e^{\overbrace{z_k}^{\text{logit}}}} {\sum_{j=1}^K e^{z_j}}.\]

Taking the logarithm after this normalization gives

\[\underbrace{\log q_\theta(k\mid x)}_{\text{log-probability, not a logit}} =\underbrace{z_k}_{\text{class-}k\text{ logit}} -\underbrace{\log\sum_{j=1}^K e^{z_j}}_{\text{shared log-normalizer}}.\]

The subscripts have different roles here. \(k\) is a free index: fix a class \(k\) and compute its log-probability. By contrast, \(j\) is a dummy summation index: inside \(\sum_j\) it successively takes the values \(1,\ldots,K\). The formula does not claim that \(z_k=z_j\). Written without the shorthand,

\[[\log\operatorname{softmax}(\mathbf z)]_k =z_k-\underbrace{\log\!\left(e^{z_1}+e^{z_2}+\cdots+e^{z_K}\right)}_{\operatorname{logsumexp}(\mathbf z)}.\]

For example, when computing class \(k=2\), the first term is specifically \(z_2\), while the second term contains all logits, including \(z_2\). The first term is correct because the numerator of softmax is \(e^{z_k}\) and \(\log e^{z_k}=z_k\). The shared subtraction is exactly what normalizes the result:

\[\sum_{k=1}^K\exp\!\left(z_k-\operatorname{logsumexp}(\mathbf z)\right) =\frac{\sum_ke^{z_k}}{\sum_je^{z_j}}=1.\]

Therefore, for the realized class \(y\), the usual framework-level per-example cross-entropy in nats is

\[\underbrace{\ell_{\mathrm{CE}}(x,y)}_{\text{one-example loss}} =\underbrace{-\log q_\theta(y\mid x)}_{\text{negative log-probability}} =\underbrace{-z_y}_{\text{reward a large true-class logit}} +\underbrace{\log\sum_{j=1}^K e^{z_j}}_{\text{compare it with all class logits}}.\]

This is why software libraries normally ask CrossEntropyLoss to receive logits, even though the mathematical loss contains \(\log q_\theta\): the operation internally computes a numerically stable log-softmax and then selects the true class. The coding version uses base-two logarithms, so the same loss in bits is

\[\ell_{\mathrm{CE}}^{\mathrm{bits}}(x,y) =-\log_2q_\theta(y\mid x) =\frac{\ell_{\mathrm{CE}}^{\mathrm{nats}}(x,y)}{\ln 2}.\]

The objects can now be kept separate:

Symbol What it is Its role
\(z_k\) logit raw score produced by the model
\(q_\theta(k\mid x)\) probability softmax-normalized probability of class \(k\)
\(\log q_\theta(k\mid x)\) log-probability logarithm of that normalized probability
\(-\log q_\theta(y\mid x)\) negative log-probability loss/code length for one observed label \(y\)
\(L_{\mathrm{CE}}\) cross-entropy loss the preceding one-example quantity averaged under real data

Fix one input \(x\). The situation is exactly the earlier coding problem, but now the outcome space is the set of labels. If label \(y\) occurs, the model pays

\[-\log_2q_\theta(y\mid x)\]

bits. Averaging first over labels and then over inputs gives the population cross-entropy loss

\[\boxed{L_{\mathrm{CE}}=\mathbb E_{(X,Y)\sim p}[-\log_2q_\theta(Y\mid X)]}.\]

With every part labeled, the same expression is

\[\underbrace{L_{\mathrm{CE}}}_{\text{population cross-entropy}} =\underbrace{\mathbb E_{(X,Y)\sim p}}_{\text{average according to real-data frequency}} \!\left[ \underbrace{-\log_2}_{\text{probability }\to\text{ bits}} \underbrace{q_\theta(Y\mid X)}_{\text{model probability of the label that occurred}} \right].\]
What changes if we remove the logarithm? (Click to expand)

Strictly speaking, the logarithm is not an optional decoration on cross-entropy: it is part of its definition. But we can compare it with the seemingly natural probability loss

\[\ell_{\mathrm{prob}}(x,y)=1-q_\theta(y\mid x),\]

where minimizing \(1-q_y\) is equivalent to maximizing the probability assigned to the observed class. At first this appears to have the same goal as minimizing \(-\log q_y\). Their gradients with respect to the probability already reveal a difference:

\[\frac{\partial(-\log q_y)}{\partial q_y}=-\frac1{q_y}, \qquad \frac{\partial(1-q_y)}{\partial q_y}=-1.\]

The difference is clearest at the logits, which are the quantities actually changed by backpropagation. Let \(t_k=\mathbf 1\{y=k\}\) be the one-hot target. For natural-log cross-entropy,

\[\boxed{\frac{\partial\ell_{\mathrm{CE}}}{\partial z_k}=q_k-t_k}.\]

For the no-log probability loss,

\[\boxed{\frac{\partial\ell_{\mathrm{prob}}}{\partial z_k} =q_y(q_k-t_k) =q_y\frac{\partial\ell_{\mathrm{CE}}}{\partial z_k}}.\]

For one example the two gradients point in the same direction, but the no-log gradient is multiplied by the model’s probability \(q_y\) for the correct answer. This reverses the desirable emphasis. If the model is confidently wrong, say \(q_y=0.001\), the cross-entropy gradient on the true-class logit is approximately \(-0.999\), whereas the no-log gradient is approximately \(-0.000999\)—one thousand times smaller. The mistake that most needs correction supplies almost no learning signal. Cross-entropy instead becomes steep as \(q_y\to0\) and continues to push strongly against confident errors. Both gradients vanish as \(q_y\to1\), when the example is already solved.

This per-example rescaling also changes a minibatch update. Each example has a different \(q_y\), so the no-log loss suppresses hard examples before their gradients are summed and gives relatively more influence to examples the model already handles well. It can consequently learn slowly or stall after a poor initialization.

There is a deeper statistical difference when labels are genuinely uncertain. For a fixed \(x\), write \(p_k=p(Y=k\mid x)\) and let \(q\) range over all class distributions. The expected cross-entropy is

\[\mathbb E_p[-\log q_Y] =-\sum_kp_k\log q_k =H(p)+D_{\mathrm{KL}}(p\Vert q),\]

so its unique optimum is \(q=p\). It learns the entire conditional distribution. The expected no-log loss is instead

\[\mathbb E_p[1-q_Y]=1-\sum_kp_kq_k.\]

This expression is linear in \(q\), so it is minimized by placing all probability on a most likely class. For example, if \(p=(0.6,0.4)\), cross-entropy prefers \(q=(0.6,0.4)\), while the no-log loss prefers \(q=(1,0)\). The latter can recover the most likely class but not calibrated uncertainty. When the label is deterministic, both losses have the same limiting prediction \(q_y=1\), although their paths toward it still differ.

The logarithm is not the only possible way to learn calibrated probabilities. The Brier score, \(\sum_k(q_k-t_k)^2\), is another proper scoring rule and is also minimized in expectation at \(q=p\). What fails above is specifically the linear objective \(1-q_y\), not every loss without a logarithm.

There is a second possible meaning of “not taking the log.” Suppose we retain the likelihood of the entire dataset,

\[\mathcal L(\theta)=\prod_{i=1}^nq_\theta(y_i\mid x_i),\]

and maximize this product directly instead of maximizing its logarithm. These two objectives do have the same optimizer, and where \(\mathcal L>0\) their gradients satisfy

\[\nabla_\theta\mathcal L =\mathcal L\,\nabla_\theta\log\mathcal L.\]

Thus the full-batch gradient direction is the same but its scale is multiplied by the entire dataset likelihood. Because a product of many probabilities is exponentially small, this gradient rapidly vanishes and may underflow to exactly zero; it also changes dramatically with batch size. Taking the log converts the product into the stable additive objective \(\sum_i\log q_\theta(y_i\mid x_i)\). This is a numerical and optimization reason for the log, in addition to its coding and probability-estimation meanings.

Writing out both averages makes the roles explicit:

\[L_{\mathrm{CE}}=-\sum_xp(x)\sum_yp(y\mid x)\log_2q_\theta(y\mid x).\]

For each fixed \(x\), cross-entropy compares the two distributions \(p(\cdot\mid x)\) and \(q_\theta(\cdot\mid x)\) on the same label space. It is therefore imprecise to say that cross-entropy is “between the random variables \(X\) and \(Y\).” It is between true and predicted conditional distributions, averaged over \(X\).

For one observed pair \((x,y)\), the stochastic loss is just the code length of the observed label:

\[L_{\mathrm{CE}}(x,y)=-\log_2q_\theta(y\mid x).\]

If the model assigns probability \(0.8\) to the true class, the loss is \(-\log_2 0.8\approx0.322\) bits. Raising the probability of the observed answer shortens its code and lowers the loss.

This is also why cross-entropy and negative log-likelihood are the same training objective. With natural logarithms, the value is measured in nats rather than bits, but the minimizer is unchanged. For a language model, \(X\) is the token prefix, \(Y\) is the next token, and \(q_\theta(\cdot\mid X)\) is the next-token distribution.

从这个角度看,监督学习并没有引入另一种交叉熵,而是在前面的单结果编码问题上加入了侧信息:不再始终使用一个 unconditional code \(q(z)\),而是在观察 \(x\) 后选择随输入变化的编码 \(q_\theta(y\mid x)\)。

这里需要先把机器学习任务和它的编码解释分开。在监督学习中,预测模型读取输入 \(x\),输出所有可能标签上的概率分布 \(q_\theta(\cdot\mid x)\)。例如,分类模型读入一张图片后,可能给“猫”分配 \(0.8\) 的概率,给“狗”分配 \(0.2\) 的概率。训练过程中不一定真的有人在传输一串二进制消息。

为了用码长解释损失,我们另外设想一个通信实验。编码器看见实际标签 \(y\),按照 \(q_\theta(\cdot\mid x)\) 所确定的编码规则把它变成 bits;解码器收到这些 bits,再还原出标签。双方必须事先都知道 \(x\),否则就无法确定应该使用哪一本随输入变化的“码表”。此时,\(x\) 是侧信息,\(y\) 才是待编码结果,因此它的理想码长是 \(-\log_2q_\theta(y\mid x)\)。

所以,预测模型负责给出概率;编码器和解码器则是假想的解释工具,帮助我们把这个概率理解成 bit 代价。两种交叉熵仍服从同一条规则:

\[\boxed{\text{交叉熵}=\mathbb E[-\log_2 q(\text{待编码结果}\mid\text{编码时已知的信息})]}.\]

没有侧信息时,条件为空,公式就是 \(\mathbb E[-\log_2q(Z)]\);已知 \(X\) 时,它变成 \(\mathbb E[-\log_2q_\theta(Y\mid X)]\)。也可以从概率的 chain rule 看出:

\[q(x,y)=q(x)q(y\mid x),\]

因此

\[-\log_2q(x,y)=-\log_2q(x)-\log_2q(y\mid x).\]

第一项是编码输入本身的代价,第二项是在输入已经知道后编码标签的代价。监督学习的任务是根据给定的 \(X\) 预测 \(Y\),因此损失通常只计算第二项。

现在令

  • \(X\) 为输入;
  • \(Y\) 为要预测的标签;
  • \(p(x,y)\) 为输入与标签对的真实联合分布;
  • \(p(x)\) 和 \(p(y)\) 为它的两个边缘分布;
  • \(p(y\mid x)\) 为知道输入 \(x\) 后的真实标签分布;
  • \(q_\theta(y\mid x)\) 为模型的预测分布。

在把这些量放进损失之前,可以先逐步看清分类模型究竟计算了什么。对 \(K\) 个类别,最后一层通常输出向量

\[\mathbf z_\theta(x)=(z_1,\ldots,z_K)\in\mathbb R^K.\]

其中每个 \(z_k\) 都是类别 \(k\) 的 logit:它只是模型给出的、尚未归一化的原始分数。Logit 可以为负,也不需要加起来等于 1。Softmax 才把这些分数变成归一化的预测分布:

\[\underbrace{q_\theta(k\mid x)}_{\text{类别 }k\text{ 的概率}} =\operatorname{softmax}(\mathbf z)_k =\frac{e^{\overbrace{z_k}^{\text{logit}}}} {\sum_{j=1}^K e^{z_j}}.\]

在归一化之后再取对数,才得到

\[\underbrace{\log q_\theta(k\mid x)}_{\text{log-probability,不是 logit}} =\underbrace{z_k}_{\text{类别 }k\text{ 的 logit}} -\underbrace{\log\sum_{j=1}^K e^{z_j}}_{\text{所有类别共享的 log-normalizer}}.\]

这里两个下标扮演不同角色。\(k\) 是 free index:先固定一个类别 \(k\),再计算这个类别的 log-probability;\(j\) 则是 dummy summation index:在 \(\sum_j\) 内部依次遍历 \(1,\ldots,K\)。这个公式并没有假设 \(z_k=z_j\)。不使用求和简写时,它是

\[[\log\operatorname{softmax}(\mathbf z)]_k =z_k-\underbrace{\log\!\left(e^{z_1}+e^{z_2}+\cdots+e^{z_K}\right)}_{\operatorname{logsumexp}(\mathbf z)}.\]

例如计算类别 \(k=2\) 时,前一项特指 \(z_2\);后一项却包含所有 logits,其中也包括 \(z_2\)。前一项之所以正确,是因为 softmax 的分子为 \(e^{z_k}\),取对数后 \(\log e^{z_k}=z_k\)。所有类别共同减去后一项,恰好保证归一化:

\[\sum_{k=1}^K\exp\!\left(z_k-\operatorname{logsumexp}(\mathbf z)\right) =\frac{\sum_ke^{z_k}}{\sum_je^{z_j}}=1.\]

因此,对实际出现的真实类别 \(y\),机器学习框架通常计算的单样本交叉熵(单位为 nat)是

\[\underbrace{\ell_{\mathrm{CE}}(x,y)}_{\text{单样本损失}} =\underbrace{-\log q_\theta(y\mid x)}_{\text{negative log-probability}} =\underbrace{-z_y}_{\text{鼓励提高真实类别的 logit}} +\underbrace{\log\sum_{j=1}^K e^{z_j}}_{\text{同时与所有类别的 logits 比较}}.\]

这解释了一个容易困惑的接口设计:数学公式中虽然写着 \(\log q_\theta\),软件库的 CrossEntropyLoss 通常却要求传入 logits。因为它会在内部以数值稳定的方式计算 log-softmax,再取出真实类别对应的那一项。本文的编码解释使用以 2 为底的对数,因此同一个损失换成 bit 后是

\[\ell_{\mathrm{CE}}^{\mathrm{bits}}(x,y) =-\log_2q_\theta(y\mid x) =\frac{\ell_{\mathrm{CE}}^{\mathrm{nats}}(x,y)}{\ln 2}.\]

现在可以明确区分每一个量:

符号 它是什么 在计算中的作用
\(z_k\) logit 模型直接输出的原始分数
\(q_\theta(k\mid x)\) probability softmax 归一化后的类别 \(k\) 概率
\(\log q_\theta(k\mid x)\) log-probability 归一化概率的对数
\(-\log q_\theta(y\mid x)\) negative log-probability 一个已观测标签 \(y\) 的损失或码长
\(L_{\mathrm{CE}}\) cross-entropy loss 按真实数据频率对上述单样本量取平均

先固定一个输入 \(x\)。这与前面的编码问题完全相同,只是结果空间变成了标签集合。若标签 \(y\) 出现,模型支付

\[-\log_2q_\theta(y\mid x)\]

bit。先对标签取平均,再对输入取平均,就得到总体交叉熵损失:

\[\boxed{L_{\mathrm{CE}}=\mathbb E_{(X,Y)\sim p}[-\log_2q_\theta(Y\mid X)]}.\]

把每一部分直接标在公式上,同一个式子就是

\[\underbrace{L_{\mathrm{CE}}}_{\text{总体交叉熵}} =\underbrace{\mathbb E_{(X,Y)\sim p}}_{\text{按照真实数据的出现频率取平均}} \!\left[ \underbrace{-\log_2}_{\text{把概率换算成 bit}} \underbrace{q_\theta(Y\mid X)}_{\text{模型赋给实际标签的概率}} \right].\]
去掉 logarithm 会发生什么?(点击展开)

严格来说,logarithm 并不是后来装饰在 cross-entropy 上的可选操作,而是 cross-entropy 定义的一部分。不过,我们可以把它和一个看起来很自然的 probability loss 比较:

\[\ell_{\mathrm{prob}}(x,y)=1-q_\theta(y\mid x).\]

最小化 \(1-q_y\) 等价于提高模型赋给已观测真实类别的概率。乍看之下,它似乎与最小化 \(-\log q_y\) 目标相同,但二者对概率的梯度已经表现出区别:

\[\frac{\partial(-\log q_y)}{\partial q_y}=-\frac1{q_y}, \qquad \frac{\partial(1-q_y)}{\partial q_y}=-1.\]

对实际训练而言,更关键的是关于 logits 的梯度,因为 backpropagation 真正修改的是产生 logits 的参数。令 \(t_k=\mathbf 1\{y=k\}\) 为 one-hot target。使用自然对数的交叉熵满足

\[\boxed{\frac{\partial\ell_{\mathrm{CE}}}{\partial z_k}=q_k-t_k}.\]

而 no-log probability loss 满足

\[\boxed{\frac{\partial\ell_{\mathrm{prob}}}{\partial z_k} =q_y(q_k-t_k) =q_y\frac{\partial\ell_{\mathrm{CE}}}{\partial z_k}}.\]

对单个样本,两个梯度指向同一方向,但 no-log 梯度还乘上了模型给正确答案的概率 \(q_y\)。这个权重恰好会削弱最需要修正的样本:若模型非常自信地答错,例如 \(q_y=0.001\),交叉熵关于真实类别 logit 的梯度约为 \(-0.999\),no-log 梯度却只有约 \(-0.000999\),小了一千倍。最严重的错误几乎不再提供学习信号。交叉熵则会在 \(q_y\to0\) 时保持强烈惩罚,持续推动模型纠正自信的错误。当 \(q_y\to1\)、样本已经学会时,两种梯度才都会趋近于零。

这种逐样本缩放还会改变一个 minibatch 的更新方向。每个样本的 \(q_y\) 不同,no-log loss 会在求和之前压低困难样本的梯度,让模型已经处理得较好的样本获得相对更大的影响。因此,它可能学习得很慢,甚至在较差的初始化附近停滞。

当标签本身具有不确定性时,二者还有更深的统计差别。固定 \(x\),记 \(p_k=p(Y=k\mid x)\),并让 \(q\) 遍历所有类别分布。期望交叉熵为

\[\mathbb E_p[-\log q_Y] =-\sum_kp_k\log q_k =H(p)+D_{\mathrm{KL}}(p\Vert q),\]

所以它的唯一最优解是 \(q=p\),能够学习完整的条件分布。No-log loss 的期望却是

\[\mathbb E_p[1-q_Y]=1-\sum_kp_kq_k.\]

这个表达式关于 \(q\) 是线性的,因此最优解会把全部概率放到某个最可能的类别上。例如,若 \(p=(0.6,0.4)\),交叉熵偏好 \(q=(0.6,0.4)\),no-log loss 却偏好 \(q=(1,0)\)。后者可以找出最可能的类别,却不能还原校准良好的不确定性。若标签完全由输入确定,两种损失的极限预测都是 \(q_y=1\),但抵达这个终点的训练 dynamics 仍然不同。

Logarithm 也不是学习校准概率的唯一选择。例如 Brier score,\(\sum_k(q_k-t_k)^2\),是另一种 proper scoring rule,它的期望同样在 \(q=p\) 时最小。上面的问题特指线性目标 \(1-q_y\),而不是说所有不含 logarithm 的损失都不可用。

“不取 log”还可能有第二种含义:仍然保留整个数据集的 likelihood

\[\mathcal L(\theta)=\prod_{i=1}^nq_\theta(y_i\mid x_i),\]

但直接最大化这个乘积,而不最大化它的 logarithm。这两个目标确实具有同一个 optimizer;在 \(\mathcal L>0\) 时,它们的梯度满足

\[\nabla_\theta\mathcal L =\mathcal L\,\nabla_\theta\log\mathcal L.\]

因此,full-batch 梯度方向相同,但其尺度还要乘以整个数据集的 likelihood。许多小于 1 的概率相乘后会指数级缩小,梯度很快消失,数值上甚至会 underflow 到精确的 0;梯度大小也会剧烈依赖 batch size。取 log 后,乘积变成稳定、可加的目标 \(\sum_i\log q_\theta(y_i\mid x_i)\)。所以除了编码解释和概率估计意义,logarithm 还有直接的数值与优化意义。

把两个平均都展开,可以清楚看到各自的作用:

\[L_{\mathrm{CE}}=-\sum_xp(x)\sum_yp(y\mid x)\log_2q_\theta(y\mid x).\]

对每个固定的 \(x\),交叉熵比较的是同一个标签空间上的两个分布 \(p(\cdot\mid x)\) 和 \(q_\theta(\cdot\mid x)\)。因此,说交叉熵“在随机变量 \(X\) 和 \(Y\) 之间”并不准确;它是在比较真实与预测的条件分布,然后对 \(X\) 取平均。

对一个已观测样本 \((x,y)\),随机损失就是已观测标签的码长:

\[L_{\mathrm{CE}}(x,y)=-\log_2q_\theta(y\mid x).\]

若模型给真实类别的概率为 \(0.8\),损失为 \(-\log_2 0.8\approx0.322\) bit。提高已观测答案的概率,会缩短它的编码并降低损失。

这也解释了为什么 cross-entropy 与 negative log-likelihood 是同一个训练目标。使用自然对数时,单位从 bit 变成 nat,但最优解不变。对于语言模型,\(X\) 是已有 token prefix,\(Y\) 是下一个 token,\(q_\theta(\cdot\mid X)\) 是 next-token distribution。

2.2 How Good Can Prediction Be?

The notation now contains two random variables, but the object being measured is still a distribution. For every possible input value \(x\), the joint distribution supplies one label distribution \(p_{Y\mid X=x}\). The collection

\[\left\{p_{Y\mid X=x}:x\in\mathcal X\right\}\]

is simply a family of distributions indexed by the observed input, and \(p_X(x)\) says how frequently each member of that family is used.

For a fixed input \(x\), suppose the model were perfect: \(q_\theta(\cdot\mid x)=p(\cdot\mid x)\). The average label-code length would then be the entropy of the true conditional distribution. Averaging this matched length over inputs defines conditional entropy:

\[\boxed{H(Y\mid X)=\mathbb E_{(X,Y)\sim p}[-\log_2p(Y\mid X)]}.\]

Written explicitly as an average of distributional entropies,

\[\boxed{H(Y\mid X)=\sum_xp_X(x)\,H\!\left(p_{Y\mid X=x}\right)}.\]

So conditional entropy does not measure a mysterious relation “between two letters.” It averages the entropy of the true label distribution at each input.

This looks almost identical to the earlier cross-entropy loss, but one symbol changes its meaning. Both use the same outer average because, by iterated expectation,

\[\mathbb E_{(X,Y)\sim p}[g(X,Y)] =\mathbb E_{X\sim p(x)}\mathbb E_{Y\sim p(y\mid X)}[g(X,Y)].\]

What is averaged differs:

\[H(Y\mid X)=\mathbb E_p[-\log_2\underbrace{p(Y\mid X)}_{\text{true conditional distribution}}],\]

whereas

\[L_{\mathrm{CE}}(q_\theta)=\mathbb E_p[-\log_2\underbrace{q_\theta(Y\mid X)}_{\text{model conditional distribution}}].\]

They are equal only under the perfect-model assumption \(q_\theta(\cdot\mid x)=p(\cdot\mid x)\) for \(p(x)\)-almost every input. The paragraph began with that assumption; without it, cross-entropy is larger by the expected KL term derived below.

It measures the label uncertainty that remains after the input is known. The word “remains” matters. Before seeing \(X\), the best context-free code for \(Y\) costs \(H(Y)\) bits on average. After seeing \(X\), the best input-dependent code costs only \(H(Y\mid X)\).

We can now decompose the supervised loss using the same matched-versus-mismatched argument as before. For every \(x\),

\[H\!\left(p(\cdot\mid x),q_\theta(\cdot\mid x)\right) =H\!\left(p(\cdot\mid x)\right) +D_{\mathrm{KL}}\!\left(p(\cdot\mid x)\Vert q_\theta(\cdot\mid x)\right).\]

Averaging over \(X\) gives

\[\boxed{L_{\mathrm{CE}}=H(Y\mid X)+\mathbb E_X\!\left[D_{\mathrm{KL}}\!\left(p(\cdot\mid X)\Vert q_\theta(\cdot\mid X)\right)\right]}.\]

The two terms answer different questions:

  • \(H(Y\mid X)\) is ambiguity inherent in the prediction problem given the available input;
  • the expected KL is extra loss caused by the model not matching the true conditional distribution.

If labels are deterministic given inputs, then \(H(Y\mid X)=0\). If labels are noisy or genuinely ambiguous, even a perfect model cannot drive the population loss below \(H(Y\mid X)\).

2.2.1 The Same Pattern in Mean Squared Error (Click to expand)

Regression has an exact parallel. Let

\[m(x)=\mathbb E[Y\mid X=x]\]

be the true conditional mean, and let \(\mu_\theta(x)\) be the model’s prediction. Add and subtract \(m(X)\) inside the error:

\[Y-\mu_\theta(X)=\underbrace{Y-m(X)}_{\text{unpredictable residual}}+\underbrace{m(X)-\mu_\theta(X)}_{\text{model mismatch}}.\]

After squaring and averaging, the cross term vanishes because \(\mathbb E[Y-m(X)\mid X]=0\). Thus

\[\boxed{ \mathbb E[(Y-\mu_\theta(X))^2] =\underbrace{\mathbb E[\operatorname{Var}(Y\mid X)]}_{\text{irreducible conditional variation}} +\underbrace{\mathbb E[(m(X)-\mu_\theta(X))^2]}_{\text{model error}}. }\]

This has the same logic as

\[L_{\mathrm{CE}} =\underbrace{H(Y\mid X)}_{\text{irreducible conditional uncertainty}} +\underbrace{\mathbb E_X[D_{\mathrm{KL}}(p(\cdot\mid X)\Vert q_\theta(\cdot\mid X))]}_{\text{model error}}.\]

MSE asks the model to match the conditional mean; cross-entropy asks it to match the entire conditional distribution. The best MSE predictor is \(m(x)\), and its minimum population MSE is \(\mathbb E[\operatorname{Var}(Y\mid X)]\). “Irreducible” always means relative to the available input \(X\): adding informative features can reduce both \(\operatorname{Var}(Y\mid X)\) and \(H(Y\mid X)\).

If the fitted predictor \(\widehat\mu_D\) also varies with the random training set \(D\), its model-error term can be split once more. Writing \(\bar\mu(x)=\mathbb E_D[\widehat\mu_D(x)]\) gives the familiar bias–variance decomposition:

\[\mathbb E_D\mathbb E_{X,Y}[(Y-\widehat\mu_D(X))^2] =\underbrace{\mathbb E_X[\operatorname{Var}(Y\mid X)]}_{\text{data noise}} +\underbrace{\mathbb E_X[(m(X)-\bar\mu(X))^2]}_{\text{squared bias}} +\underbrace{\mathbb E_X[\operatorname{Var}_D(\widehat\mu_D(X))]}_{\text{estimator variance}}.\]

The first term remains even with the optimal learning procedure; the latter two arise from how the model class and finite training data produce a fitted predictor. This is a further decomposition of the MSE model term, not a different source of label noise.

There is also a direct likelihood connection. If the model assumes

\[q_\theta(y\mid x)=\mathcal N(\mu_\theta(x),\sigma^2)\]

with a fixed variance, then—remembering that this article uses base-two logarithms—

\[-\log_2 q_\theta(y\mid x) =\frac12\log_2(2\pi\sigma^2) +\frac{(y-\mu_\theta(x))^2}{2\sigma^2\ln 2}.\]

Minimizing Gaussian cross-entropy, or negative log-likelihood, is therefore exactly equivalent to minimizing MSE. If the variance is also learned, the loss additionally charges a \(\log\sigma^2\) term, so predicting uncertainty matters as well as predicting the mean.

Finally, suppose we ask not how good a model is, but how useful the input itself is. Without \(X\), the optimal label code costs \(H(Y)\). With \(X\), it costs \(H(Y\mid X)\). The expected saving is the mutual information:

\[\boxed{I(X;Y)=H(Y)-H(Y\mid X)}.\]

To see where the distributions in this expression come from, return to the joint distribution \(p_{XY}\). For discrete \(X\) and \(Y\), it is a two-dimensional table: one axis lists values of \(X\), the other lists values of \(Y\), and each cell contains \(p_{XY}(x,y)\). The figure below turns each cell into a column whose height is its probability mass.

Figure 2: A joint distribution is a two-dimensional table of probabilities. Sum columns in the \(X\) direction to obtain \(p_Y\); select one \(X=x\) slice and normalize it to obtain \(p_{Y\mid X=x}\).

Every distribution used by mutual information is extracted from this same joint table:

  1. Ignore the input: for a fixed label \(y\), add the columns over every possible input, \(p_Y(y)=\sum_x p_{XY}(x,y).\) This marginal distribution describes labels before we are told which \(x\) occurred.
  2. Reveal one input: fix \(X=x\) and retain only that slice of the table. Its total mass is \(p_X(x)\), not one, so divide every column in the slice by \(p_X(x)\): \(p_{Y\mid X}(y\mid x)=\frac{p_{XY}(x,y)}{p_X(x)}.\) This normalized slice describes labels after we know that particular input.

Mutual information therefore remains entirely distributional. For each input value, it compares the normalized slice \(p_{Y\mid X=x}\) with the common marginal \(p_Y\). It then averages that comparison using the frequency \(p_X(x)\) with which each slice occurs:

\[\boxed{I(X;Y) =\mathbb E_{X\sim p_X}\!\left[ D_{\mathrm{KL}}\!\left(p_{Y\mid X}(\cdot\mid X)\Vert p_Y\right) \right]}.\]

Thus mutual information uses forward KL to measure how much, on average, observing \(X\) changes the label distribution from its prior marginal \(p_Y\)—equivalently, how many bits about \(Y\) the input supplies. Expanding this average and substituting \(p(y\mid x)=p(x,y)/p(x)\) gives

\[\begin{aligned} I(X;Y) &=\mathbb E_{p(x,y)}\!\left[\log_2\frac{p(y\mid x)}{p(y)}\right]\\ &=\mathbb E_{p(x,y)}\!\left[\log_2\frac{p(x,y)}{p(x)p(y)}\right]\\ &=D_{\mathrm{KL}}\!\left(p(X,Y)\Vert p(X)p(Y)\right). \end{aligned}\]

If \(X\) and \(Y\) are independent, then \(p(x,y)=p(x)p(y)\) and this KL is zero.

This separates three questions that are easy to conflate: cross-entropy evaluates a predictive distribution, conditional entropy measures irreducible uncertainty after seeing the input, and mutual information measures how much uncertainty the input removes.

Quantity Definition Coding interpretation
Self-information \(-\log_2p(z)\) ideal bits for one outcome \(z\)
Entropy \(\mathbb E_p[-\log_2p(Z)]\) asymptotically optimal bits per symbol under the true source
Cross-entropy \(\mathbb E_p[-\log_2q(Z)]\) expected bits using the model’s code
KL divergence \(\mathbb E_p[\log_2 p(Z)/q(Z)]\) excess expected bits due to mismatch
Conditional entropy \(\mathbb E_p[-\log_2p(Y\mid X)]\) uncertainty in \(Y\) remaining after observing \(X\)
Mutual information \(H(Y)-H(Y\mid X)\) uncertainty about \(Y\) removed by observing \(X\)

To close the discussion, consider a numerical check that puts entropy, cross-entropy, and KL on the same scale. Let the true binary source be \(p=(0.75,0.25)\), while the model assumes \(q=(0.5,0.5)\). The model considers both outcomes equally likely, so it assigns each one the ideal length

\[-\log_2 0.5=1\ \text{bit}.\]

No matter which outcome occurs, one bit is paid. Its average is therefore

\[H(p,q)=0.75(1)+0.25(1)=1.\]

The matched code instead uses the true probabilities. Its ideal lengths are

\[-\log_2 0.75\approx0.415,qquad -\log_2 0.25=2,\]

so the shorter length is paid 75% of the time and the longer one only 25% of the time:

\[H(p)=0.75(0.415)+0.25(2)\approx0.811\ \text{bits}.\]

The difference is precisely

\[D_{\mathrm{KL}}(p\Vert q)=H(p,q)-H(p)=1-0.811\approx0.189\ \text{bits}.\]

The uniform model is not “wrong” because its code is undecodable; its one-bit code is perfectly valid. It is inefficient because it ignores the three-to-one frequency imbalance and pays about \(0.189\) unnecessary bits per outcome in the long-run limit.

2.3 Three Machine-Learning Consequences

With the coding meanings in place, three machine-learning consequences are now direct.

1. Maximum likelihood and minimum cross-entropy are the same optimization. Suppose the supervised dataset is

\[D=\{(x_i,y_i)\}_{i=1}^n,\]

and, conditional on the inputs, the labels are modeled independently. The conditional likelihood is the probability that the model assigns to all observed labels:

\[\mathcal L(\theta;D)=\prod_{i=1}^n q_\theta(y_i\mid x_i).\]

Products are awkward to optimize and can underflow numerically, so take a logarithm. Because the logarithm is strictly increasing, it does not change which \(\theta\) is best:

\[\arg\max_\theta\mathcal L(\theta;D) =\arg\max_\theta\sum_{i=1}^n\log q_\theta(y_i\mid x_i).\]

Negating converts maximization to minimization, and dividing by the constant \(n\) does not change the optimizer:

\[\arg\max_\theta\mathcal L(\theta;D) =\arg\min_\theta\left[-\frac1n\sum_{i=1}^n\log q_\theta(y_i\mid x_i)\right].\]

The expression in brackets is empirical cross-entropy, also called negative log-likelihood. In one-hot classification, this follows explicitly because

\[-\sum_{k=1}^K\mathbf 1\{y_i=k\}\log q_\theta(k\mid x_i) =-\log q_\theta(y_i\mid x_i);\]

only the observed class survives the sum. The coding interpretation says the same thing another way:

\[-\log_2\prod_iq_\theta(y_i\mid x_i) =\sum_i-\log_2q_\theta(y_i\mid x_i).\]

Thus the maximum-likelihood model assigns the greatest probability to the observed label sequence; equivalently, it gives that sequence the shortest total ideal code. “The same optimization” does not mean the raw likelihood and cross-entropy have the same numerical value—they differ by a logarithm, a minus sign, and often the factor \(1/n\)—only that they select the same \(\theta\).

2. Minimizing population cross-entropy minimizes forward KL. The conditional decomposition derived above is

\[L_{\mathrm{CE}}(\theta) =H(Y\mid X) +\mathbb E_X\!\left[D_{\mathrm{KL}}\!\left(p(\cdot\mid X)\Vert q_\theta(\cdot\mid X)\right)\right].\]

Once the data-generating distribution \(p\) and the available input \(X\) are fixed, \(H(Y\mid X)\) is a constant: changing \(\theta\) cannot remove ambiguity inherent in the task. Therefore

\[\arg\min_\theta L_{\mathrm{CE}}(\theta) =\arg\min_\theta\mathbb E_X\!\left[D_{\mathrm{KL}}\!\left(p(\cdot\mid X)\Vert q_\theta(\cdot\mid X)\right)\right].\]

If the model family contains the true conditional distribution and optimization succeeds, the KL term can reach zero and \(q_\theta(\cdot\mid x)=p(\cdot\mid x)\) almost everywhere. If the family is restricted, training instead finds its best approximation to \(p\) and a positive mismatch remains. It is forward KL because outcomes are averaged according to the data distribution \(p\). Consequently, an outcome with \(p(y\mid x)>0\) but very small \(q_\theta(y\mid x)\) incurs a large penalty: the model has assigned a very long code to something that really occurs.

In practice, training minimizes empirical cross-entropy on a finite sample, not the inaccessible population expectation. A sufficiently flexible model can lower training loss by memorization, so held-out cross-entropy is needed to estimate whether the expected KL on new data has actually fallen. From the coding viewpoint, training can remove mismatch bits; it cannot reduce the intrinsic \(H(Y\mid X)\) without changing what information is supplied in \(X\).

3. Perplexity is exponentiated cross-entropy. For observed conditional probabilities \(q_i=q_\theta(y_i\mid x_i)\), the average base-two cross-entropy is

\[\widehat H=-\frac1n\sum_{i=1}^n\log_2q_i.\]

Exponentiating gives

\[\boxed{\operatorname{PPL}=2^{\widehat H} =\left(\prod_{i=1}^nq_i\right)^{-1/n}}.\]

Thus perplexity is the inverse geometric mean probability assigned to the observed outcomes. Its “effective branching factor” interpretation comes from a uniform example: if every step had \(K\) equally likely choices, then each observed outcome would have probability \(1/K\), the cross-entropy would be \(\log_2K\) bits, and perplexity would be exactly \(K\). A model with average loss \(3\) bits per token therefore has the same average code length as an idealized uniform choice among \(2^3=8\) alternatives. This does not mean that exactly eight tokens are plausible at every position; it is an equivalent average scale.

Lower perplexity means shorter average token codes on the same evaluation distribution. Comparisons require the same dataset, tokenization, and conditioning setup: changing the tokenizer changes what counts as one symbol, so perplexities from different vocabularies are not automatically comparable. With natural-log loss, the equivalent formula is \(\operatorname{PPL}=\exp(\text{average NLL})\).

Is training by cross-entropy the same as finding the largest compression ratio? Almost, if the comparison uses a fixed uncompressed representation. Minimizing cross-entropy adjusts \(q_\theta\) so that outcomes common under \(p\) receive shorter codes; because the original number of bits is fixed, a shorter expected encoded length means a larger compression ratio. The population optimum is \(q_\theta=p\), where the expected length reaches \(H(p)\) and the KL mismatch cost vanishes. In supervised learning, the corresponding statement is narrower: minimizing conditional cross-entropy seeks the shortest label code given \(X\), whose irreducible limit is \(H(Y\mid X)\)—it does not compress the input \(X\) itself.

Continuous variables need care. Differential entropy can be negative and changes under a change of coordinates. KL divergence remains invariant under smooth reparameterization, but it is no longer literally a raw finite-bit code length without specifying quantization or a reference measure.

现在记号中出现了两个随机变量,但被测量的对象仍然是 distribution。对每个可能的输入取值 \(x\),联合分布都会给出一个标签分布 \(p_{Y\mid X=x}\)。整个集合

\[\left\{p_{Y\mid X=x}:x\in\mathcal X\right\}\]

只是一族由已观测输入索引的 distributions,而 \(p_X(x)\) 决定其中每个分布以多大频率被使用。

对一个固定输入 \(x\),假设模型已经完美,即 \(q_\theta(\cdot\mid x)=p(\cdot\mid x)\)。此时标签的平均码长就是该真实条件分布的熵。再对输入取平均,就得到条件熵

\[\boxed{H(Y\mid X)=\mathbb E_{(X,Y)\sim p}[-\log_2p(Y\mid X)]}.\]

把它直接写成 distributional entropies 的平均,就是

\[\boxed{H(Y\mid X)=\sum_xp_X(x)\,H\!\left(p_{Y\mid X=x}\right)}.\]

所以 conditional entropy 并不是在测量“两个字母之间”的某种神秘关系;它是在对每个输入下真实标签分布的 entropy 取平均。

这个公式看起来几乎与前面的交叉熵损失相同,但有一个符号改变了含义。二者采用同一个外层平均,是因为 iterated expectation 给出

\[\mathbb E_{(X,Y)\sim p}[g(X,Y)] =\mathbb E_{X\sim p(x)}\mathbb E_{Y\sim p(y\mid X)}[g(X,Y)].\]

真正被平均的量却不同:

\[H(Y\mid X)=\mathbb E_p[-\log_2\underbrace{p(Y\mid X)}_{\text{真实条件分布}}],\]

\[L_{\mathrm{CE}}(q_\theta)=\mathbb E_p[-\log_2\underbrace{q_\theta(Y\mid X)}_{\text{模型条件分布}}].\]

只有当 \(q_\theta(\cdot\mid x)=p(\cdot\mid x)\) 对几乎所有可能输入都成立,也就是模型完美时,二者才相等。本段开头正是先作出了这个假设;若没有它,交叉熵会比条件熵多出下面推导的期望 KL 项。

它衡量知道输入之后仍然保留的标签不确定性。“仍然保留”非常重要:在看到 \(X\) 之前,对 \(Y\) 最好的无上下文编码平均需要 \(H(Y)\) bit;看到 \(X\) 之后,最好的输入相关编码只需要 \(H(Y\mid X)\) bit。

现在可以复用前面的“匹配编码与失配编码”关系来分解监督学习损失。对每个 \(x\),

\[H\!\left(p(\cdot\mid x),q_\theta(\cdot\mid x)\right) =H\!\left(p(\cdot\mid x)\right) +D_{\mathrm{KL}}\!\left(p(\cdot\mid x)\Vert q_\theta(\cdot\mid x)\right).\]

对 \(X\) 取平均得到

\[\boxed{L_{\mathrm{CE}}=H(Y\mid X)+\mathbb E_X\!\left[D_{\mathrm{KL}}\!\left(p(\cdot\mid X)\Vert q_\theta(\cdot\mid X)\right)\right]}.\]

两项回答不同的问题:

  • \(H(Y\mid X)\) 是在已有输入条件下,预测任务本身固有的歧义;
  • 期望 KL 是模型没有匹配真实条件分布所造成的额外损失。

若标签由输入确定,则 \(H(Y\mid X)=0\)。若标签含噪声或本身存在真实歧义,即使完美模型也不能让总体损失低于 \(H(Y\mid X)\)。

2.2.1 Mean Squared Error 中相同的分解(点击展开)

回归问题存在完全平行的关系。令

\[m(x)=\mathbb E[Y\mid X=x]\]

为真实条件均值,令 \(\mu_\theta(x)\) 为模型预测。在误差中加上再减去 \(m(X)\):

\[Y-\mu_\theta(X)=\underbrace{Y-m(X)}_{\text{不可预测的残差}}+\underbrace{m(X)-\mu_\theta(X)}_{\text{模型失配}}.\]

平方并取平均后,交叉项会因为 \(\mathbb E[Y-m(X)\mid X]=0\) 而消失,因此

\[\boxed{ \mathbb E[(Y-\mu_\theta(X))^2] =\underbrace{\mathbb E[\operatorname{Var}(Y\mid X)]}_{\text{不可约的条件变化}} +\underbrace{\mathbb E[(m(X)-\mu_\theta(X))^2]}_{\text{模型误差}}. }\]

它和下面的交叉熵分解具有相同逻辑:

\[L_{\mathrm{CE}} =\underbrace{H(Y\mid X)}_{\text{不可约的条件不确定性}} +\underbrace{\mathbb E_X[D_{\mathrm{KL}}(p(\cdot\mid X)\Vert q_\theta(\cdot\mid X))]}_{\text{模型误差}}.\]

MSE 要求模型匹配条件均值,cross-entropy 则要求模型匹配完整条件分布。最优 MSE predictor 是 \(m(x)\),其最小总体 MSE 为 \(\mathbb E[\operatorname{Var}(Y\mid X)]\)。“不可约”始终是相对于当前可用输入 \(X\) 而言:加入更多有效特征,可能同时降低 \(\operatorname{Var}(Y\mid X)\) 和 \(H(Y\mid X)\)。

如果拟合得到的 predictor \(\widehat\mu_D\) 还会随随机训练集 \(D\) 改变,那么模型误差项可以继续拆分。令 \(\bar\mu(x)=\mathbb E_D[\widehat\mu_D(x)]\),就得到经典的 bias–variance decomposition:

\[\mathbb E_D\mathbb E_{X,Y}[(Y-\widehat\mu_D(X))^2] =\underbrace{\mathbb E_X[\operatorname{Var}(Y\mid X)]}_{\text{数据噪声}} +\underbrace{\mathbb E_X[(m(X)-\bar\mu(X))^2]}_{\text{bias 的平方}} +\underbrace{\mathbb E_X[\operatorname{Var}_D(\widehat\mu_D(X))]}_{\text{estimator variance}}.\]

第一项即使学习过程达到最优仍然存在;后两项来自模型类别以及有限训练数据怎样产生最终 predictor。这是在进一步拆分 MSE 的模型项,而不是又定义了一种标签噪声。

二者还有直接的 likelihood 联系。若模型假设

\[q_\theta(y\mid x)=\mathcal N(\mu_\theta(x),\sigma^2)\]

且方差固定,那么——注意本文统一使用以 2 为底的对数——

\[-\log_2 q_\theta(y\mid x) =\frac12\log_2(2\pi\sigma^2) +\frac{(y-\mu_\theta(x))^2}{2\sigma^2\ln 2}.\]

因此,最小化 Gaussian cross-entropy,也就是 negative log-likelihood,与最小化 MSE 完全等价。若方差也由模型学习,损失中还会出现 \(\log\sigma^2\) 项;此时模型不仅要预测均值,也要预测不确定性。

最后,如果我们不再问模型有多好,而是问输入本身有多有用:没有 \(X\) 时,最优标签编码平均需要 \(H(Y)\) bit;知道 \(X\) 后,只需要 \(H(Y\mid X)\) bit。节省下来的平均码长就是互信息

\[\boxed{I(X;Y)=H(Y)-H(Y\mid X)}.\]

为了看清这个式子里的两个分布从哪里来,先回到联合分布 \(p_{XY}\)。当 \(X,Y\) 都是离散变量时,\(p_{XY}\) 可以写成一张二维表:一条轴列出 \(X\) 的可能取值,另一条轴列出 \(Y\) 的可能取值,每个格子填入 \(p_{XY}(x,y)\)。下面的图把每个格子竖成一根柱子,柱高就是该格子的概率质量。

图 2:联合分布是一张二维概率表。沿 \(X\) 方向把柱高相加得到 \(p_Y\);选中一个 \(X=x\) 切片并重新归一化,就得到 \(p_{Y\mid X=x}\)。

互信息使用的每一个分布都来自同一张联合分布表:

  1. 忽略输入:固定标签 \(y\),沿所有可能的输入取值把柱高相加, \(p_Y(y)=\sum_x p_{XY}(x,y).\) 这个边缘分布描述尚未得知具体输入时,标签总体上怎样出现。
  2. 揭示一个输入:固定 \(X=x\),只保留联合分布中的这个切片。该切片的总质量是 \(p_X(x)\),而不是 1,所以还要把其中每根柱子的高度除以 \(p_X(x)\): \(p_{Y\mid X}(y\mid x)=\frac{p_{XY}(x,y)}{p_X(x)}.\) 归一化后的切片描述已经知道这个输入时,标签怎样分布。

因此,mutual information 仍然完全是 distributional quantity。对于每个输入取值,它比较归一化后的切片 \(p_{Y\mid X=x}\) 与共同的边缘分布 \(p_Y\);最后再按照各切片出现的频率 \(p_X(x)\),对这些比较结果取平均:

\[\boxed{I(X;Y) =\mathbb E_{X\sim p_X}\!\left[ D_{\mathrm{KL}}\!\left(p_{Y\mid X}(\cdot\mid X)\Vert p_Y\right) \right]}.\]

因此,互信息使用 forward KL 衡量观察 \(X\) 后标签分布相对于原先 marginal \(p_Y\) 平均改变了多少;等价地,它表示输入为 \(Y\) 提供了多少 bit。展开这个平均并代入 \(p(y\mid x)=p(x,y)/p(x)\),可以逐步得到

\[\begin{aligned} I(X;Y) &=\mathbb E_{p(x,y)}\!\left[\log_2\frac{p(y\mid x)}{p(y)}\right]\\ &=\mathbb E_{p(x,y)}\!\left[\log_2\frac{p(x,y)}{p(x)p(y)}\right]\\ &=D_{\mathrm{KL}}\!\left(p(X,Y)\Vert p(X)p(Y)\right). \end{aligned}\]

若 \(X\) 与 \(Y\) 独立,则 \(p(x,y)=p(x)p(y)\),这个 KL 就等于 0。

这区分了三个容易混淆的问题:cross-entropy 评价一个预测分布;conditional entropy 衡量看到输入后仍不可消除的不确定性;mutual information 衡量输入消除了多少不确定性。

定义 编码解释
自信息量 \(-\log_2p(z)\) 单个结果 \(z\) 的理想 bit 数
\(\mathbb E_p[-\log_2p(Z)]\) 真实信源下渐近最优的每符号 bit 数
交叉熵 \(\mathbb E_p[-\log_2q(Z)]\) 使用模型编码时的期望 bit 数
KL divergence \(\mathbb E_p[\log_2 p(Z)/q(Z)]\) 分布失配造成的额外期望 bit 数
条件熵 \(\mathbb E_p[-\log_2p(Y\mid X)]\) 观察 \(X\) 后 \(Y\) 仍保留的不确定性
互信息 \(H(Y)-H(Y\mid X)\) 观察 \(X\) 所消除的关于 \(Y\) 的不确定性

最后用一个数值例子,把 entropy、cross-entropy 与 KL 放在同一个尺度上检查。设真实二元信源为 \(p=(0.75,0.25)\),而模型假设 \(q=(0.5,0.5)\)。模型认为两个结果等概率,所以为二者分配相同的理想码长:

\[-\log_2 0.5=1\ \text{bit}.\]

无论哪个结果出现,都支付 1 bit,因此平均值也是

\[H(p,q)=0.75(1)+0.25(1)=1.\]

匹配编码改用真实概率,其两个理想码长为

\[-\log_2 0.75\approx0.415,qquad -\log_2 0.25=2.\]

较短码长有 75% 的时间被支付,较长码长只有 25% 的时间被支付,因此

\[H(p)=0.75(0.415)+0.25(2)\approx0.811\ \text{bits}.\]

二者之差恰好是

\[D_{\mathrm{KL}}(p\Vert q)=H(p,q)-H(p)=1-0.811\approx0.189\ \text{bits}.\]

所以均匀模型并不是因为“无法解码”而错误;它的一 bit 编码完全有效。它低效,是因为忽略了三比一的出现频率差异,在长序列极限下,每个结果平均多支付约 \(0.189\) bit。

有了这些编码解释,三个机器学习中的结论就可以直接读出。

1. Maximum likelihood 与最小化交叉熵是同一个优化。 假设监督学习数据集为

\[D=\{(x_i,y_i)\}_{i=1}^n,\]

并假设给定各个输入后,标签由模型独立生成。Conditional likelihood 是模型赋给全部已观测标签的联合概率:

\[\mathcal L(\theta;D)=\prod_{i=1}^n q_\theta(y_i\mid x_i).\]

乘积不方便优化,数值上也容易 underflow,因此先取对数。由于 logarithm 严格单调递增,它不会改变最优的 \(\theta\):

\[\arg\max_\theta\mathcal L(\theta;D) =\arg\max_\theta\sum_{i=1}^n\log q_\theta(y_i\mid x_i).\]

加上负号会把最大化变成最小化;再除以常数 \(n\) 仍不会改变 optimizer:

\[\arg\max_\theta\mathcal L(\theta;D) =\arg\min_\theta\left[-\frac1n\sum_{i=1}^n\log q_\theta(y_i\mid x_i)\right].\]

方括号中的量就是 empirical cross-entropy,也称为 negative log-likelihood。对 one-hot classification,这一点可以直接展开:

\[-\sum_{k=1}^K\mathbf 1\{y_i=k\}\log q_\theta(k\mid x_i) =-\log q_\theta(y_i\mid x_i);\]

求和中只有已观测真实类别对应的一项保留下来。编码解释给出同一个结论:

\[-\log_2\prod_iq_\theta(y_i\mid x_i) =\sum_i-\log_2q_\theta(y_i\mid x_i).\]

因此,maximum-likelihood model 给已观测标签序列分配最大的概率;等价地,它为这段序列给出最短的理想总码长。“同一个优化”不表示 likelihood 与 cross-entropy 的数值相同——二者还相差 logarithm、负号以及通常存在的 \(1/n\)——而是说它们选择同一个 \(\theta\)。

2. 最小化总体交叉熵等价于最小化 forward KL。 前面已经得到条件分解

\[L_{\mathrm{CE}}(\theta) =H(Y\mid X) +\mathbb E_X\!\left[D_{\mathrm{KL}}\!\left(p(\cdot\mid X)\Vert q_\theta(\cdot\mid X)\right)\right].\]

一旦数据生成分布 \(p\) 和可用输入 \(X\) 固定,\(H(Y\mid X)\) 就是常数:改变 \(\theta\) 无法消除任务本身固有的歧义。因此

\[\arg\min_\theta L_{\mathrm{CE}}(\theta) =\arg\min_\theta\mathbb E_X\!\left[D_{\mathrm{KL}}\!\left(p(\cdot\mid X)\Vert q_\theta(\cdot\mid X)\right)\right].\]

如果模型族包含真实条件分布,而且优化成功,KL 项可以达到零,此时几乎处处有 \(q_\theta(\cdot\mid x)=p(\cdot\mid x)\)。若模型族受到限制,训练只能找到该模型族中对 \(p\) 的最佳近似,仍会留下正的失配代价。这里是 forward KL,因为所有结果都按照数据分布 \(p\) 取平均。因此,若某个结果满足 \(p(y\mid x)>0\),模型却给出很小的 \(q_\theta(y\mid x)\),损失会很大:模型为一个真实会出现的结果分配了很长的编码。

实践中,训练最小化的是有限样本上的 empirical cross-entropy,而不是不可直接获得的总体期望。容量足够大的模型可能通过记忆降低训练损失,因此还要用 held-out cross-entropy 判断新数据上的期望 KL 是否真的下降。从编码角度看,训练能够消除分布失配造成的额外 bits;除非改变提供给模型的输入信息 \(X\),否则它不能降低固有的 \(H(Y\mid X)\)。

3. Perplexity 是交叉熵的指数。 对已观测结果,令模型给出的条件概率为 \(q_i=q_\theta(y_i\mid x_i)\)。平均 base-two cross-entropy 是

\[\widehat H=-\frac1n\sum_{i=1}^n\log_2q_i.\]

取指数得到

\[\boxed{\operatorname{PPL}=2^{\widehat H} =\left(\prod_{i=1}^nq_i\right)^{-1/n}}.\]

所以 perplexity 是模型赋给真实结果之概率的几何平均数的倒数。“有效分支数”解释来自均匀分布:若每一步都有 \(K\) 个等概率选项,那么实际结果的概率为 \(1/K\),交叉熵为 \(\log_2K\) bit,perplexity 恰好是 \(K\)。因此,平均损失为 \(3\) bits/token 的模型,与“每一步都从 \(2^3=8\) 个等概率选项中选择”的理想情形具有相同平均码长。这并不表示每个位置都恰好有八个合理 token,而只是一个等价的平均尺度。

在相同评估分布上,更低的 perplexity 表示更短的平均 token 编码。比较时必须保持数据集、tokenizer 和 conditioning setup 一致:tokenizer 改变后,“一个符号”的定义也会改变,不同 vocabulary 下的 perplexity 不能直接比较。若 loss 使用自然对数,则相应公式是 \(\operatorname{PPL}=\exp(\text{average NLL})\)。

用交叉熵训练,是否等于寻找最大的压缩比?在未压缩表示的长度固定时,可以近似这样理解。最小化交叉熵是在调整 \(q_\theta\),让 \(p\) 下经常出现的结果得到更短的编码;原始长度不变时,平均编码越短,压缩比就越大。总体分布上的最优点是 \(q_\theta=p\),此时期望码长达到 \(H(p)\),KL 失配代价消失。在监督学习中,这个说法要更窄一些:最小化条件交叉熵是在寻找“已知 \(X\) 后标签 \(Y\) 的最短编码”,其不可消除的下限是 \(H(Y\mid X)\);它没有在压缩输入 \(X\) 本身。

连续变量需要谨慎。Differential entropy 可以为负,并会随坐标变换而改变。KL divergence 在光滑重参数化下保持不变,但若不指定量化方式或参考测度,就不能再把它直接理解为原始的有限 bit 码长。

3. Information Theory in Unsupervised Learning

This section has one destination:

\[\boxed{K(X,Y)=K(X)+K(Y\mid X)+O(\log n)}.\]

We want to understand every symbol in this formula and then use it to answer a learning question: if \(X\) is an unlabeled dataset and \(Y\) is a downstream task, in what precise sense can structure in \(X\) help describe \(Y\)?

The route is different from Sections 1 and 2. There, uppercase letters denoted random variables and quantities such as entropy were averages over a distribution. Here, \(X\) and \(Y\) will denote two particular finite objects that have already been observed—for example, two finite datasets stored as bit strings. We therefore need a notion of information for an individual object rather than an average over possible outcomes.

3.1 How Much Information Is in One Fixed Object?

Consider two files of the same length:

  • \(s_1\) contains one billion zeros;
  • \(s_2\) is a billion-bit string with no exploitable pattern.

If we place the uniform distribution over all billion-bit strings, both have probability \(2^{-10^9}\) and surprisal \(10^9\) bits. Shannon information is answering a question asked before the draw: under the chosen distribution, how surprising is the outcome? It does not by itself express that, after seeing the files, the first admits the short instruction “print zero one billion times,” while the second may require listing nearly every bit.

For a fixed object, we instead ask:

What is the shortest exact, reproducible description that generates this object?

To make “description” and “length” unambiguous, we agree on a binary computer \(U\). A description is a finite binary program \(r\). The machine reads \(r\), produces an output, and must then halt: after finitely many steps, it enters a stop state. Requiring the program to output exactly \(s\) and halt tells us when the finite output is complete; a computation that prints \(s\) and then continues printing has not reproduced exactly \(s\).

There is a second boundary to settle: how does the machine know where one program ends? We use a prefix-free program language, in which no complete valid program is the prefix of another. For example,

\[\{0,10,110,111\}\]

is prefix-free, whereas \(\{0,01,10\}\) is not. Prefix-free programs are also called self-delimiting: their ends can be recognized from the incoming bits without sending a separate fixed-width length field. This becomes essential when we later place a description of \(X\) next to a description of \(Y\). As in Section 1, their lengths satisfy Kraft’s inequality,

\[\sum_{r:\,U(r)\ \mathrm{halts}}2^{-\lvert r\rvert}\le 1.\]

Finally, we choose \(U\) to be universal: it can simulate any other programmable machine after receiving a fixed interpreter for that machine. We must fix \(U\) before measuring length, just as ordinary coding requires a shared decoder.

The prefix Kolmogorov complexity of a finite string \(s\) is then

\[\boxed{K_U(s)=\min_{r:\,U(r)\downarrow=s}\lvert r\rvert}.\]

The notation \(U(r)\downarrow=s\) says that \(U\) runs program \(r\), outputs exactly \(s\), and halts; \(\lvert r\rvert\) is the program length in bits. Once the reference machine is understood, we write \(K(s)\).

Several properties are useful for interpreting this definition.

A literal description is always available. A program can contain a self-delimiting description of the length of \(s\) followed by the bits of \(s\) themselves, so

\[K(s)\le \lvert s\rvert+O(\log\lvert s\rvert).\]

Thus complexity is never much larger than an explicitly delimited copy. A patterned string can be far shorter: the loop and the integer needed to generate a billion zeros occupy vastly fewer than a billion bits.

Most long strings are not substantially compressible. There are \(2^m\) strings of length \(m\) but fewer than \(2^{m-c}\) programs shorter than \(m-c\) bits. Because one deterministic halting program produces only one final output, fewer than a fraction \(2^{-c}\) of the length-\(m\) strings can be compressed by more than \(c\) bits. Short descriptions reveal special structure; they are not available for every string.

The choice of universal machine contributes only a fixed constant. If \(U_1\) and \(U_2\) are universal, either can simulate the other using a fixed interpreter. Therefore

\[\lvert K_{U_1}(s)-K_{U_2}(s)\rvert\le c,\]

where \(c\) depends on the two machines but not on \(s\). Exact values for small objects depend on the language, but the discrepancy does not grow with the dataset.

Exact Kolmogorov complexity is not computable in general. We can run candidate programs and eventually observe the ones that halt, but a program still running today may halt tomorrow or may run forever. No algorithm can decide this for all programs—the halting problem. Consequently a real compressor can demonstrate an upper bound by producing a description, but it cannot generally certify that the description is the shortest possible. This limitation will matter when we interpret the word “guarantee.”

3.2 What Changes When Another Object Is Already Known?

Suppose Alice and Bob already possess the same fixed object \(X\). Alice now needs to describe another fixed object \(Y\). A program may use \(X\) as an auxiliary input, and the bits of \(X\) are not charged again. This gives conditional Kolmogorov complexity:

\[\boxed{K_U(Y\mid X)=\min_{r:\,U(r,X)\downarrow=Y}\lvert r\rvert}.\]

The vertical bar means “with this particular \(X\) already available,” not conditioning on a random event. The quantity asks how many additional program bits are needed to reconstruct this particular \(Y\).

Three cases establish the intuition.

  • The program can ignore \(X\), so \(K(Y\mid X)\le K(Y)+O(1)\). Side information cannot make the best description substantially worse.
  • If one fixed short procedure \(f\) computes \(Y=f(X)\), then a program only needs to say “run \(f\),” and \(K(Y\mid X)\le K(f)+O(1)\). When \(f\) is fixed independently of the data size, this is written \(K(Y\mid X)=O(1)\).
  • Merely possessing a large \(X\) does not guarantee a saving. If none of its structure helps generate \(Y\), then \(K(Y\mid X)\approx K(Y)\).

We also need a way to treat both objects as one output. Let \(K(X,Y)\) be the shortest program length for producing an unambiguously encoded ordered pair \((X,Y)\). It is not the complexity of a raw concatenation with an unknown boundary: the pair representation lets the decoder recover where \(X\) ends and \(Y\) begins. Let

\[n=\lvert X\rvert+\lvert Y\rvert\]

denote the total raw size. We now have the three terms in the target formula:

Term Question
\(K(X)\) How many bits describe \(X\) alone?
\(K(Y\mid X)\) After \(X\) is known, how many additional bits describe \(Y\)?
\(K(X,Y)\) How many bits describe the pair jointly?

3.3 Why Does the Joint Description Split?

There is a useful precedent in Shannon information. For random variables with joint distribution \(p(x,y)\), define joint entropy by

\[H(X,Y)=\mathbb E_{(X,Y)\sim p}[-\log_2p(X,Y)].\]

The probability factorization \(p(x,y)=p(x)p(y\mid x)\) implies

\[-\log_2p(x,y)=-\log_2p(x)-\log_2p(y\mid x).\]

Averaging gives the exact Shannon chain rule

\[H(X,Y)=H(X)+H(Y\mid X).\]

Its coding meaning is “describe the random outcome of \(X\), then describe the random outcome of \(Y\) using \(X\).” The Kolmogorov formula asks the analogous question for two fixed objects, but its justification must use programs rather than probabilities.

Start with the easy direction. Take a shortest self-delimiting program for \(X\). After it halts and reconstructs \(X\), run a shortest conditional program for \(Y\) with that reconstructed \(X\) as input. A fixed wrapper combines the two programs and outputs the ordered pair. This constructs a joint description whose length is essentially

\[K(X)+K(Y\mid X).\]

Therefore the best joint program cannot be longer than this two-stage construction, apart from bounded bookkeeping.

The reverse direction is subtler. A shortest joint program may mix the shared structure of \(X\) and \(Y\) rather than visibly containing an “\(X\) part” followed by a “\(Y\) part.” The symmetry-of-information theorem says that this mixing cannot create an arbitrarily large hidden saving: the joint description can be reorganized into a description of \(X\) plus what is still needed for \(Y\) once \(X\) is known, with only logarithmic overhead.

The sharp prefix-complexity statement is

\[K(X,Y)=K(X)+K(Y\mid X,K(X))+O(1).\]

Why is \(K(X)\) supplied to the second program here? Knowing the exact length of the optimal first description removes ambiguity about how the two optimal descriptions are coordinated. In the simpler formula we do not provide that integer. Since \(K(X)\) is at most on the order of \(n\), a self-delimiting description of its value costs at most \(O(\log n)\) bits. Removing it from the condition therefore yields

\[\boxed{K(X,Y)=K(X)+K(Y\mid X)+O(\log n)}.\]

The \(O(\log n)\) term is controlled boundary and complexity bookkeeping. It is not uncertainty in the data and does not grow proportionally with dataset size.

The formula now has a direct two-slip interpretation:

  1. the first slip reconstructs \(X\) and costs \(K(X)\) bits;
  2. with \(X\) available, the second slip supplies only what is missing to reconstruct \(Y\) and costs \(K(Y\mid X)\) bits;
  3. a logarithmic number of bits coordinates the two descriptions.

Two limiting cases are worth retaining.

  • If \(Y\) is computable from \(X\) by a fixed short rule, then \(K(Y\mid X)=O(1)\) and describing the pair costs little more than describing \(X\).
  • If \(X\) provides no useful structure for describing \(Y\), then \(K(Y\mid X)\approx K(Y)\) and the pair costs approximately the sum of the separate descriptions.

This suggests a useful individual-object analogue of mutual information:

\[\boxed{I_K(X:Y)=K(Y)-K(Y\mid X)}.\]

It counts the description bits saved on \(Y\) by already knowing \(X\). Using the chain rule,

\[I_K(X:Y)=K(X)+K(Y)-K(X,Y)+O(\log n),\]

so the saving is symmetric between \(X\) and \(Y\) up to logarithmic bookkeeping.

3.4 What Does This Guarantee for Unsupervised Learning?

Now assign the fixed objects concrete learning roles:

  • \(X\) is the entire unlabeled training corpus or dataset, not one random input example;
  • \(Y\) is the finite data needed to specify performance on a downstream task—for example, its labels or task-specific continuation data.

First imagine describing \(Y\) without using \(X\). The ideal cost is \(K(Y)\). If \(X\) has already been described, the additional ideal cost of appending \(Y\) to the joint description is

\[K(X,Y)-K(X).\]

The chain rule identifies this incremental cost:

\[\boxed{K(X,Y)-K(X)=K(Y\mid X)+O(\log n)}.\]

This is the central step. It says that an optimal joint description pays for \(X\) once and then pays only for the information in \(Y\) that cannot already be reconstructed from \(X\). The saving relative to describing \(Y\) alone is

\[\begin{aligned} K(Y)-[K(X,Y)-K(X)] &=K(Y)-K(Y\mid X)+O(\log n)\\ &=I_K(X:Y)+O(\log n). \end{aligned}\]

So “useful unlabeled data” has a precise ideal meaning: \(X\) is useful for the task exactly to the extent that it shortens the best description of \(Y\).

The stronger guarantee comes from comparing this ideal description with any concrete computable learner. Suppose a learning-and-coding procedure \(A\) receives \(X\) and emits a self-delimiting residual code for \(Y\) of length \(L_A(Y\mid X)\). A universal machine can reproduce \(Y\) from \(X\) by receiving:

  1. a description of the procedure \(A\), costing \(K(A)\) bits;
  2. the residual bits produced by \(A\), costing \(L_A(Y\mid X)\) bits;
  3. a fixed interpreter, absorbed into \(O(1)\).

Therefore

\[K(Y\mid X)\le K(A)+L_A(Y\mid X)+O(1).\]

Combining this with the chain rule gives the regret-style guarantee

\[\boxed{K(X,Y)-K(X) \le K(A)+L_A(Y\mid X)+O(\log n)}.\]

Read it carefully: if any computable procedure can exploit patterns in the unlabeled data to describe the downstream data compactly, the universal joint description can simulate that procedure and do at least as well, apart from the one-time description of the procedure and logarithmic bookkeeping. If \(A\) is fixed while datasets grow, \(K(A)\) is a fixed cost rather than a cost per example.

This argument is the compression view discussed in Ilya Sutskever: An Observation on Generalization. It gives two honest limiting cases:

  • If \(K(Y\mid X)\ll K(Y)\), then this particular unlabeled dataset contains substantial reusable algorithmic structure for this task.
  • If \(K(Y\mid X)\approx K(Y)\), then the dataset supplies almost no such structure; the theorem cannot manufacture a learning benefit.

Probabilistic modeling is the computable analogy. Any joint model factors as

\[q_\theta(X,Y)=q_\theta(X)q_\theta(Y\mid X),\]

and therefore its ideal code length splits as

\[-\log_2q_\theta(X,Y) =-\log_2q_\theta(X)-\log_2q_\theta(Y\mid X).\]

A shared model can reuse patterns learned while describing \(X\) to shorten its description of \(Y\). This motivates unsupervised learning through compression. But the probability identity alone does not prove that minimizing \(-\log q_\theta(X)\) in a restricted neural model will reduce \(-\log q_\theta(Y\mid X)\): the architecture, objective, optimization, finite sample, and way the representation is accessed all matter.

The word guarantee therefore refers to an ideal benchmark, not to every practical training run. Kolmogorov complexity is uncomputable; the theorem says that the ideal universal description can match every computable competitor up to description overhead. A neural network and its optimizer search only a small, computable part of program space. They may approximate the compression principle, but the chain rule does not promise that they reach its optimum or that useful information exists in \(X\).

这一节只有一个目的:理解下面的公式,

\[\boxed{K(X,Y)=K(X)+K(Y\mid X)+O(\log n)},\]

再用它回答一个 learning question:如果 \(X\) 是无标签数据集,\(Y\) 是下游任务,那么 \(X\) 中的结构究竟在什么严格意义上能够帮助描述 \(Y\)?

这条路线与第 1、2 节不同。此前的大写字母表示随机变量,entropy 等量是对 distribution 取平均。这里的 \(X,Y\) 将表示两个已经观测到的、具体的有限对象,例如存储成 bit strings 的两个有限数据集。因此,我们需要衡量一个具体对象的信息,而不再只衡量所有可能结果上的平均。

3.1 一个固定对象中有多少信息?

考虑两个长度相同的文件:

  • \(s_1\) 由十亿个零组成;
  • \(s_2\) 是一段找不到可利用规律的十亿 bit 字符串。

如果在全部十亿 bit 字符串上指定 uniform distribution,二者的概率都是 \(2^{-10^9}\),surprisal 也都是 \(10^9\) bits。Shannon information 回答的是抽样之前的问题:在选定的 distribution 下,这个结果有多意外?它本身不会表达另一件事:文件已经出现之后,第一个文件可以用“打印十亿次零”这条短指令描述,而第二个文件可能不得不逐 bit 列出。

因此,对一个固定对象,我们改问:

能够精确、可重复地生成这个对象的描述,最短可以有多短?

为了让“描述”和“长度”没有歧义,我们约定一台二进制计算机 \(U\)。一份描述是一段有限二进制程序 \(r\)。机器读取 \(r\)、产生输出,并且必须 halt(停机):运行有限步后进入停止状态。“程序精确输出 \(s\) 并停机”让我们知道有限输出何时完整;如果程序先打印 \(s\),然后继续打印别的内容,它就没有精确复现 \(s\)。

还需要解决第二个边界:机器怎样知道一段程序在哪里结束?我们使用 prefix-free(前缀无歧义)的程序语言,即任何完整合法程序都不能是另一段合法程序的 prefix。例如,

\[\{0,10,110,111\}\]

是 prefix-free 的,而 \(\{0,01,10\}\) 不是。Prefix-free programs 也叫 self-delimiting programs(自限定程序):机器可以根据已经收到的 bits 识别程序终点,不必另收一个固定宽度的长度字段。稍后把描述 \(X\) 的程序和描述 \(Y\) 的程序放在一起时,这一点会直接用到。与第 1 节相同,它们的长度满足 Kraft inequality:

\[\sum_{r:\,U(r)\ \text{停机}}2^{-\lvert r\rvert}\le 1.\]

最后,\(U\) 应当是 universal(通用)的:给出一段固定 interpreter 后,它可以模拟其他任意可编程机器。测量长度前必须固定 \(U\),正如普通编码必须让双方共享 decoder。

有限字符串 \(s\) 的 prefix Kolmogorov complexity 定义为

\[\boxed{K_U(s)=\min_{r:\,U(r)\downarrow=s}\lvert r\rvert}.\]

记号 \(U(r)\downarrow=s\) 表示 \(U\) 运行程序 \(r\),精确输出 \(s\) 后停机;\(\lvert r\rvert\) 是程序的 bit 数。Reference machine 已经明确时,简写为 \(K(s)\)。

下面几个性质会帮助我们正确理解这个定义。

总有 literal description。 程序可以先写入 \(s\) 长度的 self-delimiting description,再逐 bit 写入 \(s\),因此

\[K(s)\le \lvert s\rvert+O(\log\lvert s\rvert).\]

所以 complexity 不会比一份边界明确的原样复制长很多。有规律的字符串则可能短得多:生成十亿个零的循环与整数,远少于十亿 bits。

绝大多数长字符串无法大幅压缩。 长度为 \(m\) 的字符串共有 \(2^m\) 个,长度小于 \(m-c\) 的程序却不到 \(2^{m-c}\) 个。一段 deterministic halting program 只能产生一个最终输出,所以能够节省超过 \(c\) bits 的 \(m\) bit 字符串,所占比例小于 \(2^{-c}\)。短描述意味着特殊结构,并不是每个对象都能拥有。

更换通用机器只改变固定常数。 若 \(U_1,U_2\) 都是 universal machines,任意一方都能通过固定 interpreter 模拟另一方,因此

\[\lvert K_{U_1}(s)-K_{U_2}(s)\rvert\le c,\]

其中 \(c\) 取决于两台机器,却不随 \(s\) 增长。短对象的精确数值会依赖语言,但这种差异不会随数据集一起增长。

精确的 Kolmogorov complexity 一般不可计算。 我们可以运行候选程序,并最终看到其中会停机的程序;但一段今天仍在运行的程序,可能明天停机,也可能永远运行。没有算法能对所有程序作出这一判断,这就是 halting problem。因此,实际 compressor 可以通过给出一份描述来证明 upper bound,却一般不能证明自己已经找到了最短描述。理解后文中的“理论保证”时,这个限制非常重要。

3.2 已经知道另一个对象后,会发生什么?

假设 Alice 与 Bob 已经拥有同一个固定对象 \(X\),Alice 现在需要描述另一个固定对象 \(Y\)。程序可以把 \(X\) 当作辅助输入使用,而且不再重复计算 \(X\) 的 bits。这就得到 conditional Kolmogorov complexity

\[\boxed{K_U(Y\mid X)=\min_{r:\,U(r,X)\downarrow=Y}\lvert r\rvert}.\]

竖线表示“这个具体的 \(X\) 已经可用”,不是对随机事件做 conditioning。这个量问的是:为了重建这个具体的 \(Y\),还需要多少额外程序 bits

三个情形可以建立直觉。

  • 程序总可以忽略 \(X\),所以 \(K(Y\mid X)\le K(Y)+O(1)\)。Side information 不会让最优描述明显变差。
  • 如果一个固定的短过程 \(f\) 能计算 \(Y=f(X)\),程序只需表达“运行 \(f\)”,于是 \(K(Y\mid X)\le K(f)+O(1)\)。当 \(f\) 固定且不随数据规模增长时,写作 \(K(Y\mid X)=O(1)\)。
  • 仅仅拥有很大的 \(X\) 并不保证节省。如果 \(X\) 中没有任何结构能帮助生成 \(Y\),就仍有 \(K(Y\mid X)\approx K(Y)\)。

还需要把两个对象视为一个输出。令 \(K(X,Y)\) 表示产生边界明确的有序对 \((X,Y)\) 的最短程序长度。它不是边界未知的 raw concatenation:pair representation 必须让 decoder 分别恢复 \(X\) 与 \(Y\)。记

\[n=\lvert X\rvert+\lvert Y\rvert\]

为两者的总原始长度。目标公式中的三个量现在都有了明确含义:

所回答的问题
\(K(X)\) 单独描述 \(X\) 需要多少 bits?
\(K(Y\mid X)\) \(X\) 已知后,描述 \(Y\) 还需多少 bits?
\(K(X,Y)\) 联合描述这对对象需要多少 bits?

3.3 联合描述为什么可以拆开?

Shannon information 中已经有一个可以借鉴的结构。对于服从联合分布 \(p(x,y)\) 的随机变量,joint entropy 定义为

\[H(X,Y)=\mathbb E_{(X,Y)\sim p}[-\log_2p(X,Y)].\]

概率分解 \(p(x,y)=p(x)p(y\mid x)\) 给出

\[-\log_2p(x,y)=-\log_2p(x)-\log_2p(y\mid x).\]

对两边取平均,就得到精确的 Shannon chain rule:

\[H(X,Y)=H(X)+H(Y\mid X).\]

它的编码含义是:“先描述随机结果 \(X\),再利用 \(X\) 描述随机结果 \(Y\)。”Kolmogorov 公式对两个固定对象提出了类似问题,但其依据必须来自程序,而不是概率。

先看容易的方向。取一段重建 \(X\) 的最短 self-delimiting program。它停机并得到 \(X\) 后,再运行一段以这个 \(X\) 为输入、重建 \(Y\) 的最短 conditional program。一个固定 wrapper 把两段程序组合起来并输出 ordered pair。这样就构造出一份长度大致为

\[K(X)+K(Y\mid X)\]

的联合描述。因此,最优 joint program 不会比这个两阶段构造更长,除去有限的 bookkeeping overhead。

反方向更微妙。最短 joint program 可能把 \(X,Y\) 的共有结构混合在一起,而不是清楚地包含一个“\(X\) 部分”和一个“\(Y\) 部分”。Symmetry-of-information theorem 表明,这种混合无法产生任意大的隐藏优势:联合描述仍可重组为“描述 \(X\)”加上“\(X\) 已知后描述 \(Y\) 还缺少的部分”,代价只是 logarithmic overhead。

Prefix complexity 更精确的形式是

\[K(X,Y)=K(X)+K(Y\mid X,K(X))+O(1).\]

这里为什么把 \(K(X)\) 也提供给第二段程序?知道第一段最优描述的精确长度,可以消除两段最优描述在协调方式上的歧义。较简洁的公式并不提供这个整数。由于 \(K(X)\) 至多与 \(n\) 同阶,对它的数值作 self-delimiting description 最多需要 \(O(\log n)\) bits。因此,从条件中去掉它,就得到

\[\boxed{K(X,Y)=K(X)+K(Y\mid X)+O(\log n)}.\]

\(O(\log n)\) 是受控的边界与 complexity bookkeeping;它不是数据中的不确定性,也不会与数据集大小成比例增长。

现在可以把公式理解为“两张字条”:

  1. 第一张字条重建 \(X\),长度为 \(K(X)\);
  2. \(X\) 已经可用后,第二张只补充重建 \(Y\) 所缺的信息,长度为 \(K(Y\mid X)\);
  3. 另用 logarithmic 数量的 bits 协调两份描述。

两个极端情况值得保留。

  • 若固定短规则可以从 \(X\) 计算 \(Y\),则 \(K(Y\mid X)=O(1)\),描述 pair 几乎只比描述 \(X\) 多一点。
  • 若 \(X\) 对描述 \(Y\) 没有帮助,则 \(K(Y\mid X)\approx K(Y)\),描述 pair 的代价接近分别描述二者的代价之和。

由此还能得到 mutual information 针对单个对象的对应量:

\[\boxed{I_K(X:Y)=K(Y)-K(Y\mid X)}.\]

它计算知道 \(X\) 后,在 \(Y\) 的描述上节省了多少 bits。代入 chain rule 得到

\[I_K(X:Y)=K(X)+K(Y)-K(X,Y)+O(\log n),\]

所以除去 logarithmic bookkeeping,这种节省对 \(X,Y\) 是对称的。

3.4 这对无监督学习保证了什么?

现在为两个固定对象赋予具体的 learning 含义:

  • \(X\) 是完整的无标签训练语料或数据集,不是一个随机输入样本;
  • \(Y\) 是确定下游任务表现所需的有限数据,例如它的标签或 task-specific continuation data。

先假设不用 \(X\) 描述 \(Y\),理想代价是 \(K(Y)\)。如果 \(X\) 已经被描述,那么在 joint description 后追加 \(Y\) 的理想增量代价是

\[K(X,Y)-K(X).\]

Chain rule 确定了这笔增量:

\[\boxed{K(X,Y)-K(X)=K(Y\mid X)+O(\log n)}.\]

这是最关键的一步。它表示最优 joint description 只为 \(X\) 付费一次,随后只需支付 \(Y\) 中无法从 \(X\) 重建的那部分信息。与单独描述 \(Y\) 相比,节省量为

\[\begin{aligned} K(Y)-[K(X,Y)-K(X)] &=K(Y)-K(Y\mid X)+O(\log n)\\ &=I_K(X:Y)+O(\log n). \end{aligned}\]

因此,“无标签数据有用”获得了一个精确的理想含义:\(X\) 能让 \(Y\) 的最佳描述缩短多少,它就对任务有多少用处。

更强的 guarantee 来自与任意具体的可计算 learner 作比较。假设 learning-and-coding procedure \(A\) 接收 \(X\),并为 \(Y\) 产生长度为 \(L_A(Y\mid X)\) 的 self-delimiting residual code。Universal machine 可以在收到下面三项后,从 \(X\) 重建 \(Y\):

  1. 过程 \(A\) 的描述,花费 \(K(A)\) bits;
  2. \(A\) 产生的 residual bits,花费 \(L_A(Y\mid X)\) bits;
  3. 一段固定 interpreter,其代价并入 \(O(1)\)。

因此

\[K(Y\mid X)\le K(A)+L_A(Y\mid X)+O(1).\]

再与 chain rule 合并,就得到 regret-style guarantee:

\[\boxed{K(X,Y)-K(X) \le K(A)+L_A(Y\mid X)+O(\log n)}.\]

需要逐字理解它:只要任何可计算过程能够利用无标签数据中的模式,把下游数据描述得更短,universal joint description 就能模拟该过程;除了一次性描述该过程与 logarithmic bookkeeping,它至少能做得同样好。当 \(A\) 固定而数据规模增长时,\(K(A)\) 是固定代价,而不是每个样本都要支付的代价。

这就是 Ilya Sutskever: An Observation on Generalization 中讨论的 compression view。它给出两个诚实的极端情况:

  • 若 \(K(Y\mid X)\ll K(Y)\),这个具体无标签数据集确实包含许多可供该任务复用的 algorithmic structure。
  • 若 \(K(Y\mid X)\approx K(Y)\),该数据集几乎没有提供这种结构;定理无法凭空制造 learning benefit。

Probabilistic modeling 是它的可计算类比。任何 joint model 都可以分解为

\[q_\theta(X,Y)=q_\theta(X)q_\theta(Y\mid X),\]

所以理想码长分解为

\[-\log_2q_\theta(X,Y) =-\log_2q_\theta(X)-\log_2q_\theta(Y\mid X).\]

共享模型可以复用描述 \(X\) 时学到的模式,从而缩短对 \(Y\) 的描述;这为通过 compression 理解 unsupervised learning 提供了动机。但仅凭这个概率恒等式,并不能证明在受限 neural model 中减小 \(-\log q_\theta(X)\) 一定会减小 \(-\log q_\theta(Y\mid X)\):architecture、objective、optimization、finite sample,以及 representation 的读取方式都会产生影响。

所以,guarantee 指的是理想基准,而不是每一次现实训练。Kolmogorov complexity 不可计算;定理表明 ideal universal description 能在 description overhead 范围内匹配每一个 computable competitor。Neural network 与 optimizer 只搜索整个程序空间中很小且可计算的一部分。它们可以近似 compression principle,但 chain rule 并不承诺它们抵达最优点,也不承诺 \(X\) 中一定存在有用信息。

References

  • Cover, T. M. & Thomas, J. A. (2006). Elements of Information Theory (2nd ed.). Wiley. Chapters 2, 5, and 14.
  • MacKay, D. J. C. (2003). Information Theory, Inference, and Learning Algorithms. Cambridge University Press. Chapters 2, 4, and 5.
  • Shannon, C. E. (1948). A Mathematical Theory of Communication. Bell System Technical Journal, 27, 379–423 and 623–656.
  • Li, M. & Vitányi, P. (2019). An Introduction to Kolmogorov Complexity and Its Applications (4th ed.). Springer. Chapters 1–2 for foundations, Chapter 4 for the connection with Shannon information, and Chapter 8 for applications.
  • Online introductions: Scholarpedia — Algorithmic Complexity and Gregory Chaitin’s publications.
  • Cover, T. M. & Thomas, J. A. (2006). Elements of Information Theory(第二版). Wiley,第 2、5、14 章。
  • MacKay, D. J. C. (2003). Information Theory, Inference, and Learning Algorithms. Cambridge University Press,第 2、4、5 章。
  • Shannon, C. E. (1948). A Mathematical Theory of Communication. Bell System Technical Journal, 27, 379–423 与 623–656。
  • Li, M. & Vitányi, P. (2019). An Introduction to Kolmogorov Complexity and Its Applications(第四版). Springer。第 1–2 章介绍基础,第 4 章讨论与 Shannon information 的联系,第 8 章介绍应用。
  • 在线导读:Scholarpedia — Algorithmic ComplexityGregory Chaitin 的论文页面