Quick recap
The key takeaways of every lesson on one page. Read it in ten minutes to refresh the whole track; open a lesson when a point feels unclear.
01 Surprise, bits and entropy
- The surprisal of an outcome with probability is : 0 for a sure outcome, 1 bit for a fair coin, 1 more bit every time is halved.
- A logarithm makes surprisals of independent events add, while their probabilities multiply.
- Entropy is the average surprisal: , with the convention .
- Entropy is the average number of yes/no questions of a good question strategy; the best tree needs between and questions.
- gives bits and gives nats; nat bits, bit nats. NumPy and PyTorch use nats.
- for outcomes: only for a constant, only for the uniform distribution.
- Entropy depends only on the probabilities, not on the values or labels of the outcomes.
- The binary entropy is 0 at , 1 bit at , symmetric, and bits.
02 Joint and conditional entropy
- The joint entropy is the entropy of the pair seen as one variable.
- is one number: the average of the row entropies, weighted by . It is 0 exactly when is a function of .
- Chain rule: ; for variables, .
- Conditioning reduces entropy on average: , with equality exactly for independent and .
- One value can raise the uncertainty: is possible (weather: 1.5 > 1.299 bits).
- , and for any function .
- Conditional entropy is not symmetric: .
- is the shared part in the two-bar diagram .
03 Jensen and KL divergence
- Jensen's inequality: for convex , ; for concave the inequality is reversed. For strictly convex or concave , equality holds only when is constant.
- For the concave log, ; the gap is about when the spread is small.
- The KL divergence is the average extra surprise, under the truth , of predicting with the model .
- Gibbs' inequality: , with equality if and only if . The proof is Jensen applied to .
- if for an outcome with ; outcomes with cost nothing.
- for the uniform on values, so ; and .
- KL is not a metric: it is not symmetric (fair coin vs : vs nats) and it breaks the triangle inequality.
04 Cross-entropy as a loss
- Cross-entropy is the average surprise of the model on data from ; the data distribution is the first argument.
- , with equality only for : log-loss is a strictly proper scoring rule.
- Minimizing the average log-loss on data is maximum likelihood, and it minimizes the forward KL from the empirical distribution to the model.
- With logits and , the loss is and its gradient is (prediction minus target); for soft targets it is .
- A classifier's expected loss is plus an average KL; only the KL part can be trained away, so noisy labels set a floor above 0.
- With soft targets (label smoothing, distillation) the loss is , so the minimum loss is , not 0.
- Perplexity (the effective number of choices), bits per token , bits per dimension : one quantity in different units.
05 Compression is prediction
- A prefix-free code decodes instantly; its codewords are the leaves of a binary tree.
- Kraft inequality: binary prefix codes (and all uniquely decodable codes) satisfy , and any lengths that satisfy it have a prefix code.
- Source coding theorem: ; blocks of symbols get within bit of per symbol.
- Huffman's algorithm (merge the two least likely nodes) gives an optimal symbol code; ties change the tree but not .
- Arithmetic coding codes a whole sequence with any next-symbol model in fewer than bits.
- Coding data from with a model costs : the wrong model costs exactly the KL divergence.
- Compression = prediction: a language model's loss in bits is the size of the text after arithmetic coding with that model.
06 Differential entropy and KL fits
- The differential entropy of a density is , in nats with the natural log.
- Quantizing into bins of width gives : the discrete entropy goes to infinity, and is the finite remainder.
- can be negative (a density can exceed 1) and depends on the units: .
- A Gaussian has , a log-volume; in 1-D it is negative for .
- KL between densities is and does not change under invertible maps of the variable; the same holds for mutual information.
- Among densities with a given covariance the Gaussian has the largest , and the gap equals .
- .
- Forward KL is mode covering (for Gaussians: moment matching, maximum likelihood); reverse KL is mode seeking, needs only up to a constant, and gives too narrow mean-field fits ().
07 Mutual information
- Mutual information is the average reduction in uncertainty about one variable when you learn the other; it is symmetric.
- , with equality exactly for independent variables; it is the average pointwise mutual information .
- For a fair bit through a binary symmetric channel, : bits at , and 0 at .
- For jointly Gaussian variables, , and in general .
- Mutual information is unchanged by invertible maps of each variable and sees nonlinear dependence that correlation misses.
- Data processing inequality: if is a Markov chain, then , with equality when is sufficient ().
- The plug-in estimate of mutual information is biased upward for independent variables, by about nats; compare it with a permutation baseline.
08 InfoNCE and contrastive learning
- The best classifier between samples of (label 1) and (label 0), with equal class sizes, has the logit : the density-ratio trick.
- An f-divergence is with convex and ; Jensen gives . KL, reverse KL, TV, , squared Hellinger and JS are f-divergences.
- The convex conjugate gives the tangent lines of , and the Fenchel–Young inequality .
- Variational bound: for every critic , , with equality at . Only samples of and are needed.
- For KL: NWJ (optimal ) and DV (optimal ). With and they bound , but their variance grows like .
- InfoNCE: , where the loss is the softmax cross-entropy of picking the true partner among candidates. The bound never exceeds , and its optimal critic is .
- Contrastive learning (CPC, SimCLR, CLIP) minimizes InfoNCE with the critic ; large batches raise the ceiling.
- A GAN discriminator is a density-ratio classifier: , and the GAN value at is .
09 The ELBO and VAEs
- The ELBO is , and ; so the ELBO is a lower bound on , tight exactly at the posterior.
- Jensen's inequality also gives the bound: with weights ; the ELBO is the log of the geometric mean of the weights, the log of their arithmetic mean.
- Two standard forms: (energy + entropy) and (reconstruction − KL to the prior).
- Maximizing the ELBO over minimizes the reverse KL : variational inference is mode seeking, and a mean-field Gaussian gets the too-small variances .
- Maximizing the ELBO over the model parameters is approximate maximum likelihood; EM is the case where is set to the exact posterior before each step.
- The VAE loss is with a Gaussian encoder, the reparameterization , the KL , and a reconstruction term that is minus a cross-entropy (Bernoulli) or a scaled squared error (Gaussian).
- The IWAE bound satisfies , and its gap is about for large .
- With an encoder, the gap is the approximation gap (family too simple) plus the amortization gap (one shared network); posterior collapse means for every .
10 Rate–distortion and β-VAE
- The rate–distortion function over test channels with is the fewest bits per symbol for an average distortion ; long block codes reach it.
- is non-increasing and convex, equals at for discrete sources with Hamming distortion, and is 0 for .
- Bernoulli(), Hamming: for ; a fair coin with 11% errors needs 0.5 bits per flip.
- Gaussian, squared error: for ; each extra bit divides the MSE by 4 (6.02 dB).
- Reverse water-filling: independent Gaussian components get ; components below the water level get no bits.
- Blahut–Arimoto alternates $r = $ output marginal and ; it converges to the point of slope (nats).
- Information bottleneck: , a rate–distortion problem with distortion .
- β-VAE: loss = distortion + $\beta\cdot$rate, and the rate .