But what is cross-entropy? | Compression is Intelligence Part 2

3Blue1Brown33mJul 16, 2026
0:00 / 33:51
Chapters9

No clickbait detected — the title and thumbnail deliver what they promise.

AI Opinion

The episode convincingly argues that cross-entropy provides a unifying framework linking compression and language model training, particularly through the verified claim that minimizing cross-entropy directly reduces the average information per token, effectively reframing pre-training as a compression problem. However, the claim that this connection is more than a useful analogy—that training *is* compression—rests on weaker ground, as the "Partial" verdict for the cross-entropy bridge suggests the link is suggestive but not formally proven as equivalent in practice. A thoughtful viewer should double-check whether minimizing cross-entropy on a finite text corpus truly equates to optimal compression of an infinite language distribution, and whether the practical differences in how models generalize versus compress are glossed over.

Voices are AI rewrites of the same facts — style changes, not substance.

Summary

This episode explores the deep connection between compression and language model training through the lens of cross-entropy. It begins by illustrating how a 2002 paper used gzip compression to cluster languages by linguistic similarity, demonstrating that general-purpose compression can perform natural language tasks. The core insight is that cross-entropy serves as a bridge between these fields: in compression, it relates to optimal encoding where bits per symbol equal the negative log probability, while in language model training, the loss function measures the average information per token, quantifying the model's surprise. Training involves minimizing this loss via gradient descent, with the natural log used for mathematical convenience. The episode further explains KL divergence as a measure of wasted bits when using a suboptimal code, highlighting its asymmetry and its role as a distance measure between probability distributions. This framework reframes language model training as a compression problem, where minimizing cross-entropy directly improves predictive accuracy and ties model performance to information theory.

Voices are AI rewrites of the same facts — style changes, not substance.

Key Points

00:00

Language Clustering via Gzip Compression

A 2002 paper showed that by appending a snippet of one document to another and compressing the result with gzip, the difference in compressed size compared to compressing the first document alone reveals linguistic similarity. This co-compression distance metric was sufficient to reconstruct the tree of language lineage without any pre-baked linguistic knowledge, demonstrating that general-purpose compression can perform natural language tasks.

01:54

Cross-Entropy as a Bridge Between Compression and Language Model Training

Cross-entropy is central both to compression theory and to training modern language models. The video aims to first explain cross-entropy fundamentals in the context of compression, then show how it appears in pre-training and distillation of language models. The same formula appearing in two contexts hints at a deeper connection, allowing a reframing of language model training from next-token prediction to compression.

03:02

Optimal Encoding and Information Content

For an optimal code, the number of bits allocated to a symbol equals the negative log base 2 of its probability. Claude Shannon defined this as the information content of an event. In a toy example with four instructions (up 50%, down 25%, left 12.5%, right 12.5%), the optimal encoding uses 1 bit for up, 2 bits for down, and 3 bits each for left and right. The total information content of a message is the sum of individual symbol information values, and an optimal encoding approximates this sum.

15:00

Loss function as average information per token

The loss function in language model training measures the average information per token from the model's perspective. For each token in the training data, the model assigns a probability to the true next token; the negative log of that probability quantifies surprise. A well-trained model gives high probabilities to correct tokens, resulting in low surprise and low loss, while a random model is constantly surprised and incurs high loss. This approach directly ties model performance to information theory, where minimizing loss equates to improving predictive accuracy.

16:02

Training process overview: gradient descent and loss minimization

Training a language model involves defining a loss function that quantifies prediction quality, then using gradient descent and backpropagation to automatically adjust billions of parameters to minimize that loss. The loss function is evaluated over a vast training set of internet text, and the optimization process iteratively tweaks parameters to descend the loss surface. While the conceptual framework is simple, practical implementation requires handling batching, optimizers, and massive engineering scale.

19:21

Why natural log is used in practice

In machine learning, the natural log is used instead of log base 2 for the loss function because it simplifies derivative calculations, which are essential for gradient descent. The difference between natural log and log base 2 is just a constant factor that gets absorbed into the learning rate, so it does not affect the optimization outcome. This choice is purely for mathematical convenience in the backpropagation process.

31:35

KL Divergence as a Measure of Waste in Compression

KL divergence quantifies the extra bits per symbol wasted when using a suboptimal code compared to an optimal one. In the robot example, subtracting the bits per symbol in the optimized case from the unoptimized case gives the KL divergence between the two distributions. This directly measures how wasteful the encoding is, with a value of zero when distributions match.

32:24

KL Divergence in Machine Learning as an Asymmetric Distance

In machine learning, KL divergence acts as a distance measure between probability distributions, being zero when distributions are identical and increasing as they diverge. However, it is asymmetric: the KL divergence of q relative to p differs from that of p relative to q. This asymmetry is a key property distinguishing it from a true metric.

32:42

Three Ponder Points on KL Divergence

The video concludes with three conceptual exercises: first, recognizing that the compact form of KL divergence hides its nature as a difference between cross entropy and entropy; second, interpreting a diagram variant of the cross entropy diagram to represent the expression; third, considering why using KL divergence instead of cross entropy as a loss function for distilling a large model into a smaller one might be more natural, given its role as a distance measure.

Chapters

9 chapters · 9 key moments
KEYkey momentUnverified

Claims & Fact Check

The co-compression distance metric from the 2002 paper was enough to recover the tree of language lineage.

?Unverified

Cross-entropy arises in both compression and language model training, hinting at a connection that allows reframing training as compression.

?Unverified

The number of bits in an optimal encoding of a message is approximately the full information content (sum of negative log probabilities).

?Unverified

The loss function in language model training is effectively the average information per token from the model's perspective.

?Unverified

Natural log is used instead of log base 2 because it makes derivatives cleaner, and the constant factor is absorbed by the learning rate.

?Unverified

Pre-training is simply averaging the negative log probability over every token in the entire training set.

?Unverified

The challenge from company Dopple on 3b1b talent page uses the formula for KL divergence, showing the math appears in real-world applications.

?Unverified

KL divergence is asymmetric: the divergence of q relative to p is not the same as that of p relative to q.

?Unverified