Type at least 2 letters. Enter opens the first result, Esc closes.

    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 pp is −log⁡p-\log p: 0 for a sure outcome, 1 bit for a fair coin, 1 more bit every time pp is halved.
    • A logarithm makes surprisals of independent events add, while their probabilities multiply.
    • Entropy is the average surprisal: H(X)=−∑xp(x)log⁡p(x)=E[−log⁡p(X)]H(X) = -\sum_x p(x)\log p(x) = \mathbb{E}[-\log p(X)], with the convention 0log⁡0=00\log 0 = 0.
    • Entropy is the average number of yes/no questions of a good question strategy; the best tree needs between HH and H+1H + 1 questions.
    • log⁡2\log_2 gives bits and ln⁡\ln gives nats; 11 nat =1.443= 1.443 bits, 11 bit =0.693= 0.693 nats. NumPy and PyTorch use nats.
    • 0≤H(X)≤log⁡K0 \le H(X) \le \log K for KK outcomes: H=0H = 0 only for a constant, H=log⁡KH = \log K only for the uniform distribution.
    • Entropy depends only on the probabilities, not on the values or labels of the outcomes.
    • The binary entropy Hb(p)H_b(p) is 0 at p∈{0,1}p \in \{0, 1\}, 1 bit at p=12p = \frac12, symmetric, and Hb(0.1)=0.469H_b(0.1) = 0.469 bits.

    02 Joint and conditional entropy

    • The joint entropy H(X,Y)=E[−log⁡p(X,Y)]H(X, Y) = \mathbb{E}[-\log p(X, Y)] is the entropy of the pair seen as one variable.
    • H(Y∣X)=∑xp(x) H(Y∣X=x)H(Y \mid X) = \sum_x p(x)\, H(Y \mid X = x) is one number: the average of the row entropies, weighted by p(x)p(x). It is 0 exactly when YY is a function of XX.
    • Chain rule: H(X,Y)=H(X)+H(Y∣X)=H(Y)+H(X∣Y)H(X, Y) = H(X) + H(Y \mid X) = H(Y) + H(X \mid Y); for nn variables, H(X1,…,Xn)=∑iH(Xi∣X1,…,Xi−1)H(X_1, \dots, X_n) = \sum_i H(X_i \mid X_1, \dots, X_{i-1}).
    • Conditioning reduces entropy on average: H(Y∣X)≤H(Y)H(Y \mid X) \le H(Y), with equality exactly for independent XX and YY.
    • One value can raise the uncertainty: H(Y∣X=x)>H(Y)H(Y \mid X = x) > H(Y) is possible (weather: 1.5 > 1.299 bits).
    • max⁡(H(X),H(Y))≤H(X,Y)≤H(X)+H(Y)\max(H(X), H(Y)) \le H(X, Y) \le H(X) + H(Y), and H(g(X))≤H(X)H(g(X)) \le H(X) for any function gg.
    • Conditional entropy is not symmetric: H(Y∣X)−H(X∣Y)=H(Y)−H(X)H(Y \mid X) - H(X \mid Y) = H(Y) - H(X).
    • I(X;Y)=H(Y)−H(Y∣X)=H(X)−H(X∣Y)≥0I(X;Y) = H(Y) - H(Y \mid X) = H(X) - H(X \mid Y) \ge 0 is the shared part in the two-bar diagram H(X,Y)=H(X∣Y)+I(X;Y)+H(Y∣X)H(X, Y) = H(X \mid Y) + I(X;Y) + H(Y \mid X).

    03 Jensen and KL divergence

    • Jensen's inequality: for convex ff, f(E[X])≤E[f(X)]f(\mathbb{E}[X]) \le \mathbb{E}[f(X)]; for concave ff the inequality is reversed. For strictly convex or concave ff, equality holds only when XX is constant.
    • For the concave log, E[log⁡X]≤log⁡E[X]\mathbb{E}[\log X] \le \log \mathbb{E}[X]; the gap is about Var⁡(X)/(2 E[X]2)\operatorname{Var}(X)/(2\,\mathbb{E}[X]^2) when the spread is small.
    • The KL divergence KL(p ∥ q)=∑xp(x)log⁡p(x)q(x)\mathrm{KL}(p\,\|\,q) = \sum_x p(x) \log \frac{p(x)}{q(x)} is the average extra surprise, under the truth pp, of predicting with the model qq.
    • Gibbs' inequality: KL(p ∥ q)≥0\mathrm{KL}(p\,\|\,q) \ge 0, with equality if and only if p=qp = q. The proof is Jensen applied to log⁡q(X)p(X)\log \frac{q(X)}{p(X)}.
    • KL(p ∥ q)=∞\mathrm{KL}(p\,\|\,q) = \infty if q(x)=0q(x) = 0 for an outcome with p(x)>0p(x) > 0; outcomes with p(x)=0p(x) = 0 cost nothing.
    • KL(p ∥ u)=log⁡K−H(p)\mathrm{KL}(p\,\|\,u) = \log K - H(p) for the uniform uu on KK values, so H(p)≤log⁡KH(p) \le \log K; and H(Y)−H(Y∣X)H(Y) - H(Y \mid X) =KL(p(x,y) ∥ p(x)p(y))≥0= \mathrm{KL}(p(x,y)\,\|\,p(x)p(y)) \ge 0.
    • KL is not a metric: it is not symmetric (fair coin vs (0.8,0.2)(0.8, 0.2): 0.2230.223 vs 0.1930.193 nats) and it breaks the triangle inequality.

    04 Cross-entropy as a loss

    • Cross-entropy H(p,q)=−∑xp(x)log⁡q(x)H(p, q) = -\sum_x p(x) \log q(x) is the average surprise of the model qq on data from pp; the data distribution is the first argument.
    • H(p,q)=H(p)+KL(p ∥ q)≥H(p)H(p, q) = H(p) + \mathrm{KL}(p\,\|\,q) \ge H(p), with equality only for q=pq = p: log-loss is a strictly proper scoring rule.
    • Minimizing the average log-loss on data is maximum likelihood, and it minimizes the forward KL KL(p^ ∥ qθ)\mathrm{KL}(\hat p\,\|\,q_\theta) from the empirical distribution to the model.
    • With logits zz and q=softmax⁡(z)q = \operatorname{softmax}(z), the loss is LSE⁡(z)−zc\operatorname{LSE}(z) - z_c and its gradient is q−yq - y (prediction minus target); for soft targets tt it is q−tq - t.
    • A classifier's expected loss is H(Y∣X)H(Y \mid X) 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 H(t)+KL(t ∥ q)H(t) + \mathrm{KL}(t\,\|\,q), so the minimum loss is H(t)H(t), not 0.
    • Perplexity =eℓˉ= e^{\bar\ell} (the effective number of choices), bits per token =ℓˉ/ln⁡2= \bar\ell/\ln 2, bits per dimension =NLL/(Dln⁡2)= \text{NLL}/(D \ln 2): 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 ∑i2−li≤1\sum_i 2^{-l_i} \le 1, and any lengths that satisfy it have a prefix code.
    • Source coding theorem: H(X)≤L∗<H(X)+1H(X) \le L^* < H(X) + 1; blocks of nn symbols get within 1/n1/n bit of H(X)H(X) per symbol.
    • Huffman's algorithm (merge the two least likely nodes) gives an optimal symbol code; ties change the tree but not LL.
    • Arithmetic coding codes a whole sequence with any next-symbol model in fewer than −log⁡2q(x1:n)+2-\log_2 q(x_{1:n}) + 2 bits.
    • Coding data from pp with a model qq costs H(p,q)=H(p)+KL(p ∥ q)H(p, q) = H(p) + \mathrm{KL}(p\,\|\,q): 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 h(X)=−∫plog⁡p=E[−log⁡p(X)]h(X) = -\int p\log p = \mathbb{E}[-\log p(X)], in nats with the natural log.
    • Quantizing into bins of width Δ\Delta gives H(XΔ)≈h(X)+log⁡(1/Δ)H(X_\Delta) \approx h(X) + \log(1/\Delta): the discrete entropy goes to infinity, and hh is the finite remainder.
    • hh can be negative (a density can exceed 1) and depends on the units: h(AX+b)=h(X)+log⁡∣det⁡A∣h(AX + b) = h(X) + \log|\det A|.
    • A Gaussian has h=12log⁡((2πe)ddet⁡Σ)h = \frac12\log\big((2\pi e)^d\det\Sigma\big), a log-volume; in 1-D it is negative for σ<0.242\sigma < 0.242.
    • KL between densities is ≥0\ge 0 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 hh, and the gap h(g)−h(p)h(g) - h(p) equals KL(p ∥ g)\mathrm{KL}(p\,\|\,g).
    • KL(N(μ0,σ02) ∥ N(μ1,σ12))=log⁡σ1σ0+σ02+(μ0−μ1)22σ12−12\mathrm{KL}(\mathcal{N}(\mu_0, \sigma_0^2)\,\|\,\mathcal{N}(\mu_1, \sigma_1^2)) = \log\frac{\sigma_1}{\sigma_0} + \frac{\sigma_0^2 + (\mu_0 - \mu_1)^2}{2\sigma_1^2} - \frac12.
    • Forward KL is mode covering (for Gaussians: moment matching, maximum likelihood); reverse KL is mode seeking, needs pp only up to a constant, and gives too narrow mean-field fits (si2=1/(Σ−1)iis_i^2 = 1/(\Sigma^{-1})_{ii}).

    07 Mutual information

    • Mutual information I(X;Y)=H(X)−H(X∣Y)=H(X)+H(Y)−H(X,Y)I(X;Y) = H(X) - H(X \mid Y) = H(X) + H(Y) - H(X, Y) is the average reduction in uncertainty about one variable when you learn the other; it is symmetric.
    • I(X;Y)=KL(p(x,y) ∥ p(x)p(y))≥0I(X;Y) = \mathrm{KL}\big(p(x, y)\,\|\,p(x)p(y)\big) \ge 0, with equality exactly for independent variables; it is the average pointwise mutual information log⁡p(x,y)p(x)p(y)\log\frac{p(x, y)}{p(x)p(y)}.
    • For a fair bit through a binary symmetric channel, I=1−Hb(ε)I = 1 - H_b(\varepsilon): 0.2780.278 bits at ε=0.2\varepsilon = 0.2, and 0 at ε=0.5\varepsilon = 0.5.
    • For jointly Gaussian variables, I=−12log⁡(1−ρ2)I = -\frac12\log(1 - \rho^2), and in general 12log⁡det⁡ΣXXdet⁡ΣYYdet⁡Σ\frac12\log\frac{\det\Sigma_{XX}\det\Sigma_{YY}}{\det\Sigma}.
    • Mutual information is unchanged by invertible maps of each variable and sees nonlinear dependence that correlation misses.
    • Data processing inequality: if X→Y→ZX \to Y \to Z is a Markov chain, then I(X;Z)≤I(X;Y)I(X;Z) \le I(X;Y), with equality when ZZ is sufficient (I(X;Y∣Z)=0I(X;Y \mid Z) = 0).
    • The plug-in estimate of mutual information is biased upward for independent variables, by about (KX−1)(KY−1)/(2N)(K_X - 1)(K_Y - 1)/(2N) nats; compare it with a permutation baseline.

    08 InfoNCE and contrastive learning

    • The best classifier between samples of PP (label 1) and QQ (label 0), with equal class sizes, has the logit log⁡p(x)/q(x)\log p(x)/q(x): the density-ratio trick.
    • An f-divergence is Df(P ∥ Q)=EQ[f(p/q)]D_f(P\,\|\,Q) = \mathbb{E}_Q[f(p/q)] with convex ff and f(1)=0f(1) = 0; Jensen gives Df≥0D_f \ge 0. KL, reverse KL, TV, χ2\chi^2, squared Hellinger and JS are f-divergences.
    • The convex conjugate f∗(t)=sup⁡u[tu−f(u)]f^*(t) = \sup_u [tu - f(u)] gives the tangent lines of ff, and the Fenchel–Young inequality f(u)≥tu−f∗(t)f(u) \ge tu - f^*(t).
    • Variational bound: for every critic TT, Df(P ∥ Q)≥EP[T]−EQ[f∗(T)]D_f(P\,\|\,Q) \ge \mathbb{E}_P[T] - \mathbb{E}_Q[f^*(T)], with equality at T∗=f′(p/q)T^* = f'(p/q). Only samples of PP and QQ are needed.
    • For KL: NWJ EP[T]−EQ[eT−1]\mathbb{E}_P[T] - \mathbb{E}_Q[e^{T-1}] (optimal 1+log⁡r1 + \log r) and DV EP[T]−log⁡EQ[eT]\mathbb{E}_P[T] - \log\mathbb{E}_Q[e^T] (optimal log⁡r+c\log r + c). With P=p(x,y)P = p(x,y) and Q=p(x)p(y)Q = p(x)p(y) they bound I(X;Y)I(X;Y), but their variance grows like eIe^{I}.
    • InfoNCE: I(X;Y)≥log⁡N−LInfoNCEI(X;Y) \ge \log N - \mathcal{L}_{\text{InfoNCE}}, where the loss is the softmax cross-entropy of picking the true partner among NN candidates. The bound never exceeds log⁡N\log N, and its optimal critic is pmi⁡(x,y)+a(x)\operatorname{pmi}(x,y) + a(x).
    • Contrastive learning (CPC, SimCLR, CLIP) minimizes InfoNCE with the critic cos⁡(g(x),h(y))/τ\cos(g(x), h(y))/\tau; large batches raise the log⁡N\log N ceiling.
    • A GAN discriminator is a density-ratio classifier: D∗=p/(p+q)D^* = p/(p+q), and the GAN value at D∗D^* is 2 JS(P ∥ Q)−log⁡42\,\mathrm{JS}(P\,\|\,Q) - \log 4.

    09 The ELBO and VAEs

    • The ELBO is ELBO(q)=Eq[log⁡p(x,z)−log⁡q(z)]\mathrm{ELBO}(q) = \mathbb{E}_q[\log p(x, z) - \log q(z)], and log⁡p(x)=ELBO(q)+KL(q(z) ∥ p(z∣x))\log p(x) = \mathrm{ELBO}(q) + \mathrm{KL}(q(z)\,\|\,p(z \mid x)); so the ELBO is a lower bound on log⁡p(x)\log p(x), tight exactly at the posterior.
    • Jensen's inequality also gives the bound: log⁡Eq[w]≥Eq[log⁡w]\log \mathbb{E}_q[w] \ge \mathbb{E}_q[\log w] with weights w=p(x,z)/q(z)w = p(x, z)/q(z); the ELBO is the log of the geometric mean of the weights, log⁡p(x)\log p(x) the log of their arithmetic mean.
    • Two standard forms: ELBO=Eq[log⁡p(x,z)]+H(q)\mathrm{ELBO} = \mathbb{E}_q[\log p(x, z)] + H(q) (energy + entropy) and ELBO=Eq[log⁡p(x∣z)]−KL(q ∥ p(z))\mathrm{ELBO} = \mathbb{E}_q[\log p(x \mid z)] - \mathrm{KL}(q\,\|\,p(z)) (reconstruction − KL to the prior).
    • Maximizing the ELBO over qq minimizes the reverse KL KL(q ∥ p(z∣x))\mathrm{KL}(q\,\|\,p(z \mid x)): variational inference is mode seeking, and a mean-field Gaussian gets the too-small variances 1/(Σ−1)ii1/(\Sigma^{-1})_{ii}.
    • Maximizing the ELBO over the model parameters is approximate maximum likelihood; EM is the case where qq is set to the exact posterior before each step.
    • The VAE loss is −ELBO-\mathrm{ELBO} with a Gaussian encoder, the reparameterization z=μ+σ⊙εz = \mu + \sigma \odot \varepsilon, the KL 12∑i(μi2+σi2−1−log⁡σi2)\frac12\sum_i(\mu_i^2 + \sigma_i^2 - 1 - \log\sigma_i^2), and a reconstruction term that is minus a cross-entropy (Bernoulli) or a scaled squared error (Gaussian).
    • The IWAE bound LK=E[log⁡1K∑kwk]\mathcal{L}_K = \mathbb{E}[\log \frac1K\sum_k w_k] satisfies ELBO=L1≤LK≤LK+1≤log⁡p(x)\mathrm{ELBO} = \mathcal{L}_1 \le \mathcal{L}_K \le \mathcal{L}_{K+1} \le \log p(x), and its gap is about Var⁡q(w)/(2K p(x)2)\operatorname{Var}_q(w)/(2K\,p(x)^2) for large KK.
    • With an encoder, the gap is the approximation gap (family too simple) plus the amortization gap (one shared network); posterior collapse means qϕ(z∣x)=p(z)q_\phi(z \mid x) = p(z) for every xx.

    10 Rate–distortion and β-VAE

    • The rate–distortion function R(D)=min⁡I(X;X^)R(D) = \min I(X; \hat X) over test channels with E[d(X,X^)]≤D\mathbb{E}[d(X, \hat X)] \le D is the fewest bits per symbol for an average distortion DD; long block codes reach it.
    • R(D)R(D) is non-increasing and convex, equals H(X)H(X) at D=0D = 0 for discrete sources with Hamming distortion, and is 0 for D≥Dmax⁡D \ge D_{\max}.
    • Bernoulli(pp), Hamming: R(D)=Hb(p)−Hb(D)R(D) = H_b(p) - H_b(D) for D≤min⁡(p,1−p)D \le \min(p, 1-p); a fair coin with 11% errors needs 0.5 bits per flip.
    • Gaussian, squared error: R(D)=12log⁡2(σ2/D)R(D) = \frac12\log_2(\sigma^2/D) for D≤σ2D \le \sigma^2; each extra bit divides the MSE by 4 (6.02 dB).
    • Reverse water-filling: independent Gaussian components get Di=min⁡(θ,λi)D_i = \min(\theta, \lambda_i); components below the water level get no bits.
    • Blahut–Arimoto alternates $r = $ output marginal and q∝r e−βdq \propto r\,e^{-\beta d}; it converges to the point of slope −β-\beta (nats).
    • Information bottleneck: min⁡I(X;T)−βI(T;Y)\min I(X;T) - \beta I(T;Y), a rate–distortion problem with distortion KL(p(y∣x) ∥ p(y∣t))\mathrm{KL}(p(y\mid x)\,\|\,p(y\mid t)).
    • β-VAE: loss = distortion + $\beta\cdot$rate, and the rate ExKL(q(z∣x) ∥ p(z))=Iq(X;Z)+KL(q(z) ∥ p(z))≥Iq(X;Z)\mathbb{E}_x \mathrm{KL}(q(z\mid x)\,\|\,p(z)) = I_q(X;Z) + \mathrm{KL}(q(z)\,\|\,p(z)) \ge I_q(X;Z).