3Blue1Brown
July 16, 2026
TL;DR
Cross-entropy is a fundamental concept connecting compression and machine learning, naturally arising in both file compression and language model training as a measure of how well predictions match actual data patterns.
“Whenever you see the same formula pop up in two separate contexts, it's math's way of kind of winking at you and hinting at a connection.”
— Presenter
“If you want a loss function with the property that it's minimized only when the model matches the statistics of the data, your hand is forced. You actually have to use the negative log.”
— Presenter
“In the same way that whenever you see pi show up in math, even when it seems unrelated to circles, there's always going to be some connection to circles hiding there, I think whenever you see cross-entropy pop up, there will be a way to connect it to compression.”
— Presenter
1. From Compression to Cross-Entropy
Introduction to the 2002 'Language Trees and Zipping' paper demonstrating how gzip compression alone can cluster languages and recover linguistic lineage. The paper exemplifies how compression and information theory connect to machine learning tasks, motivating the exploration of cross-entropy.
2. Entropy and Information Content Basics
Foundational concepts of encoding messages as bit sequences, where optimal codes allocate bits inversely proportional to symbol probability. Claude Shannon's information content formula is introduced, showing why the negative log of probability determines bits per symbol.
3. Cross-Entropy Definition and Visualization
Cross-entropy formally defined as the average bits used per symbol when an encoding optimized for distribution Q is applied to distribution P. Visual representation uses bar diagrams where bar widths represent P and heights represent information content of Q.
4. Properties of Cross-Entropy
Key insight that cross-entropy minimizes exactly when P equals Q, with that minimum value being the entropy of P. Demonstrated through two-outcome probability distributions, showing how cross-entropy bounds entropy from below.
5. Language Model Training Fundamentals
Overview of modern language models as probability distributors over tokens. Introduction of loss functions as optimization targets, with gradient descent and backpropagation as the training mechanism for adjusting billions of model parameters.
6. Why Logarithms Are Forced Upon Us
Mathematical argument using constrained optimization that if you want a loss function minimized exactly when model outputs match data statistics, logarithms are the only valid choice. Lagrange multiplier method proves why negative log is necessary.
7. Cross-Entropy in Pre-Training
Cross-entropy loss in language models emerges naturally when averaging negative log probabilities across all training tokens. This connects to the constrained optimization proof, explaining why the formula appears despite seeming unrelated to compression initially.
8. Model Distillation
Training a small model to approximate a larger one by comparing their full probability distributions at each token using cross-entropy loss. This provides richer learning signals than binary ground-truth labels, like learning chess by studying move probabilities rather than game outcomes.
9. The Compression-Intelligence Connection
Synthesis of how cross-entropy appears in both compression and deep learning contexts. Explanation of how language models can be converted to text compressors, making clear that cross-entropy training is equivalent to training optimal compressors.
10. KL Divergence
Introduction to Kullback-Leibler divergence as the difference between cross-entropy and entropy, quantifying bits wasted by suboptimal codes. Asymmetric nature of KL divergence and its role as a distance measure between distributions in machine learning.