Entropy in deep learning
Thesis: prediction = compression = intelligence
In other words, you could think of LLM pre-training instead of predicting the next token, it’s creating the most efficient text compressor.
Motivating example: sending instructions using a bitstream
Section titled “Motivating example: sending instructions using a bitstream”The constraint: No code word can be a prefix of another one. This is called the prefix condition. Codes that satisfy the prefix condition are called prefix(-free) codes.
The trade-off: You could encode the most common instruction with fewer bits, but then all possible code words that start with that code word are not available for encoding other instructions. This is the trade-off between the length of the code word and the number of code words available.
The insight: The optimal code is the one that minimizes the expected code word
length, which is
What is the lower bound on the expected code word length?
Section titled “What is the lower bound on the expected code word length?”Random noise should be incompressible. Therefore, a perfect compressor should produce a bitstream that is indistinguishable from random noise.
Let X be a random variable representing a message chosen uniformly at random
from the set of all possible
Because each of the
Information of an event
Section titled “Information of an event”Same as the self-information of an event, which is defined as
Entropy of a distribution
Section titled “Entropy of a distribution”The entropy of a distribution is the expected value of the self-information of
the events in the distribution. It is defined as
Cross-entropy
Section titled “Cross-entropy”Cross-entropy is how many bits on average you need to encode data from a
distribution
Relationship to negative log-likelihood
Section titled “Relationship to negative log-likelihood”They are the same in the context of a classification problem. Suppose:
is the one-hot encoded vector of the label with the correct label at position is our predicted probabilities vector
In this setup, cross-entropy simplifies to:
However, similar to the overflow problem of naive softmax on real hardware, log
softmax risks taking
KL divergence
Section titled “KL divergence”KL divergence is the difference between the cross-entropy and the entropy of a
distribution. It is defined as
KL divergence is not a distance by definition, since it is asymmetric and does not satisfy the triangle inequality.
The reason it is non-negative is that entropy
is the minimum achievable expected code length for a source distributed according to . Since no coding strategy can outperform the optimal code for the true distribution , we necessarily have Therefore
In other words, the probability distribution
(our model) cannot yield a lower expected encoding cost than the true distribution , because already represents the theoretical lower bound on the expected code length for data generated from .
