Maximum Likelihood: Fitting Frequencies
Minimize the negative log-likelihood by hand and watch a model learn the frequencies of its data.
How does a generative model learn? At its core, it adjusts its parameters to make the observed data as likely as possible. This tool works through the smallest possible example: a generator with only two outputs, A and B, and a single parameter a = p(A). Ten observations contain eight A and two B. Which value of a fits them best?
Follow the five-step guide. The average negative log-likelihood J(a) = −0.8·log a − 0.2·log(1 − a) is drawn as a curve; its derivative J′(a) is the slope of the red tangent line and tells you which way to move a. Take gradient-descent steps a ← a − η·J′(a) and watch the point roll to the minimum at a = 0.8, where the loss is 0.5004 nats against 0.6931 for equal probabilities. Setting a = 1 (always predicting the most common outcome) gives infinite loss: likelihood rewards fitting frequencies, not picking the majority.
Finally, compare training and held-out loss. With only ten observations the fitted frequency need not match the population frequency: draw new training sets from a population, change the number of observations, and see why models are evaluated on held-out data.