Grounds maximum likelihood as the standard objective behind many supervised and generative models.
Maximum Likelihood
Maximum likelihood fits parameters by making the observed data most probable; for classifiers it becomes negative log-likelihood, cross-entropy, and a KL fit to the empirical distribution.
Intuition
The idea in plain words, before the symbols.
You observed data. Among all parameter settings your model allows, which one makes that exact data look least surprising?
Maximum likelihood answers by holding the observations fixed and moving the model parameters. A parameter setting is good when it assigns high probability, or high density for continuous data, to the values that actually appeared.
For a biased coin, if you saw 14 heads in 20 flips, the most likely head probability is not found by asking which coin is "fair." It is found by asking which value of makes the sequence with 14 heads and 6 tails most plausible. The answer is .
This same idea scales into deep learning. A classifier assigns probabilities to labels. A language model assigns probabilities to next tokens. Training by maximum likelihood means increasing the probability assigned to the observed labels or tokens. The negative log of that likelihood is the loss the optimizer actually minimizes.
One limit matters: likelihood is a score of parameters after the data are fixed. It is not, by itself, a posterior probability that a parameter is true. Bayesian inference adds a prior and normalizes over parameter values; maximum likelihood just finds the parameter value with the highest data score.
Study prompts for this section: Intuition
Each button copies a prompt about this section to your clipboard, for an AI assistant you already use. Nothing is sent by this site.
Mathematics
Definitions, assumptions and the derivation.
Let be observed values treated as independent draws from a fixed parametric model family . The model family and parameter space are chosen before fitting; maximum likelihood only moves inside that family. All logarithms below are natural logarithms, so losses are measured in nats.
The likelihood is a function of the parameter:
The data values are fixed inside this expression. The variable being optimized is . Because products of many probabilities become tiny, we usually maximize log likelihood:
Equivalently, training minimizes average negative log-likelihood:
For a Bernoulli model with , parameter space , and , suppose observations are and are . For an ordered sequence,
and
If the data record only the count rather than the ordered sequence, the likelihood also has a binomial coefficient . That factor does not depend on , so it does not change the MLE.
On the open interval , the derivative is
When , setting it to zero gives
When or , there is no interior critical point. On the closed interval , the MLE is the boundary value or . On the open interval , the maximum is not attained; the likelihood only approaches its supremum at the boundary. The demo displays to avoid infinities from .
This is not a coincidence. The MLE for this Bernoulli family is the empirical frequency because the best one-parameter Bernoulli distribution matches the observed mass on and .
Now write the empirical distribution as
In this finite discrete setting, the average NLL is the cross-entropy from the empirical distribution to the model distribution:
And cross-entropy decomposes as
Here the empirical entropy is
and the forward KL mismatch is
The sums are over . Terms with contribute . If but , the NLL and KL are infinite.
Since does not depend on , maximum likelihood is equivalent here to minimizing the KL mismatch. If the model family cannot represent the empirical distribution exactly, MLE chooses the member of the family with the smallest mismatch inside that family.
The derivative of the average Bernoulli NLL with respect to is
If is produced by a logit with , then the chain rule gives
The demo reports this logit gradient. It is not the slope of the plotted curve with respect to .
For neural classifiers, is conditional on the input. The dataset objective is
For language models, is the next token at a position. The mechanism is the same: assign high probability to observed data, take logs, average, then use gradients to move parameters.
For continuous models, is a density rather than a probability mass. The likelihood scores density at the observed points; the probability of any exact point can be zero even while the likelihood density is high. Likelihood comparisons are meaningful within the same model and measurement units. The finite-sample objective is an empirical average of log density; a KL interpretation is clean when comparing expected NLL under a data-generating density to model densities with respect to the same base measure.
A three-toss example
Take the ordered sequence , so . Two candidates give and ; since , makes these data more probable, and because keeps the order of positive numbers, and the negative log-likelihood rank the two the same way. The derivative vanishes at , and on , so this is the only maximum, with . Recording only the count multiplies every value by and leaves the maximum where it is.
The likelihood is not a probability distribution over :
So is the probability of the observed sequence when , not the probability that . Change only the data, to : now , the maximum moves to and . The fitting principle is the same; the data changed.
For long sequences, compute directly rather than as the log of the product. A product of many probabilities is too small for floating point: with tosses at , rounds to in double precision, while is an ordinary number.
Study prompts for this section: Mathematics
Each button copies a prompt about this section to your clipboard, for an AI assistant you already use. Nothing is sent by this site.
Code
The same calculation as runnable code, in the notation of the derivation.
import numpy as np
# Observed Bernoulli data: 1=head/success, 0=tail/failure.
# Shape: y is (n,), theta is a scalar.
y = np.array([1, 1, 0, 1, 1, 0, 1, 0, 1, 1,
1, 0, 1, 1, 0, 1, 0, 1, 1, 1])
n = y.size
s = int(y.sum())
f = n - s
p_hat = s / n
def bernoulli_nll(theta):
theta = np.clip(theta, 1e-12, 1 - 1e-12)
return float(-(s * np.log(theta) + f * np.log(1 - theta)) / n)
def binary_entropy(p):
return float(sum(-value * np.log(value) for value in [p, 1 - p] if value > 0))
def bernoulli_kl(p, theta):
theta = np.clip(theta, 1e-12, 1 - 1e-12)
out = 0.0
if p > 0:
out += p * (np.log(p) - np.log(theta))
if p < 1:
out += (1 - p) * (np.log(1 - p) - np.log(1 - theta))
return float(out)
grid = np.linspace(0.01, 0.99, 99)
theta_grid_mle = grid[np.argmin([bernoulli_nll(t) for t in grid])]
# Closed-form MLE for Bernoulli.
theta_mle = p_hat
empirical_entropy = binary_entropy(p_hat)
kl_at_theta_04 = bernoulli_kl(p_hat, 0.4)
assert abs(bernoulli_nll(0.4) - (empirical_entropy + kl_at_theta_04)) < 1e-12
print("successes / n:", s, "/", n)
print("empirical p_hat:", round(p_hat, 3))
print("closed-form MLE:", round(theta_mle, 3))
print("grid MLE:", round(theta_grid_mle, 3))
print("NLL at theta=0.4:", round(bernoulli_nll(0.4), 3))
print("H(p_hat):", round(empirical_entropy, 3))
print("KL(p_hat || theta=0.4):", round(kl_at_theta_04, 3))
The code mirrors the math: the observations determine the empirical distribution, the likelihood is a function of , and the minimum average NLL occurs at .
The second block checks the three-toss example in exact fractions with Python's standard library, then shows the product of probabilities underflowing to while the sum of logs stays finite.
from fractions import Fraction as F
from math import comb, log, log1p
def likelihood(data, theta):
"""Probability of this exact ordered sequence of 0s and 1s."""
s = sum(data)
return theta**s * (1 - theta) ** (len(data) - s)
def log_likelihood(s, f, theta):
"""s log(theta) + f log(1 - theta), added term by term; 0 log 0 counts as 0."""
head = 0.0 if s == 0 else -float("inf") if theta == 0 else s * log(theta)
tail = 0.0 if f == 0 else -float("inf") if theta == 1 else f * log1p(-theta)
return head + tail
x = [1, 1, 0]
assert likelihood(x, F(1, 2)) == F(1, 8) and likelihood(x, F(3, 4)) == F(9, 64)
assert likelihood(x, F(2, 3)) == F(4, 27) # the maximum, at the fraction of heads
assert F(1, 3) - F(1, 4) == F(1, 12) # integral of theta^2 (1 - theta) over [0, 1]
assert comb(3, 2) * likelihood(x, F(2, 3)) == F(4, 9) # count data: scaled by 3, same maximum
assert likelihood([1, 0, 0, 0], F(1, 4)) == F(27, 256)
# A long sequence: the product underflows to 0, the sum of logs does not.
print("product of 1,100 probabilities of 1/2:", 0.5**1100)
print("log-likelihood added term by term:", log_likelihood(550, 550, 0.5))
Study prompts for this section: Code
Each button copies a prompt about this section to your clipboard, for an AI assistant you already use. Nothing is sent by this site.
Demo
Change an input, predict the result, and see which quantities respond.
Explore Maximum Likelihood
Observation guide
Optional and ungraded. Opening a guide saves nothing.
Choose what to inspect in Maximum Likelihood, then open its guide.
Choose the observed number of successes, then move the model parameter . Before the likelihood curve appears, predict whether maximum likelihood should decrease , leave it where it is, or increase it.
For i.i.d. Bernoulli observations, the order of the sequence does not affect the likelihood; the count of successes is the sufficient statistic.
The reveal shows the average negative log-likelihood curve, the MLE line, the entropy baseline, the KL mismatch, and the logit gradient. Moving away from the empirical frequency increases the KL mismatch while the empirical entropy stays fixed.
The practice after the demo works the three-toss example by hand: what is fixed, two candidates, the maximum, what a likelihood is not, and a changed sequence.
Study prompts for this section: Demo
Each button copies a prompt about this section to your clipboard, for an AI assistant you already use. Nothing is sent by this site.
Practice
One three-toss sequence by hand. Name what is fixed, compare two candidates, find the maximum, then change the data.
Concept: Maximum Likelihood
What is the smallest example of Maximum Likelihood you can work through by hand, and what does it show?
DetailsProbability
Reference id
concept:probability/maximum-likelihoodAfter the first pass
Go deeper
Optional material for a second reading. Sources are always shown; the other panels open from their headings or from these links, and closing one keeps what you wrote or revealed.What to look for in each sectionChoose a section and what you expect to see in it, then read short advice.
Section by section
Choose what to look for in each section
Maximum likelihood fits parameters by making the observed data most probable; for classifiers it becomes negative log-likelihood, cross-entropy, and a KL fit to the empirical distribution.

Start with the picture, metaphor, or geometric mechanism.
Choose what you expect to see in this section of Maximum Likelihood.
Questions to ask of the pictureChoose a part of the picture and what you expect, then read short advice.
Looking at the picture
Questions to ask of the picture
Maximum likelihood fits parameters by making the observed data most probable; for classifiers it becomes negative log-likelihood, cross-entropy, and a KL fit to the empirical distribution.
Which part of the picture should you look at first?
Pick the part of the picture you expect to explain Maximum Likelihood.
Sources
References for this page
A reference shows where an idea comes from; it does not vouch for every step on this page.Philosophical Transactions of the Royal Society A 222, 309–368. Names and develops the method of maximum likelihood for estimating parameters, and distinguishes likelihood from probability.
What each claim rests on1 claim, each with its sources, where it appears on this page, and its caveats.
Claims and sources
Maximum likelihood fits parameters by making the observed data most probable; for classifiers it becomes negative log-likelihood, cross-entropy, and a KL fit to the empirical distribution.
The checks were made by this site, not by an independent reviewer.
Goodfellow et al. present maximum likelihood in log space as a sum over examples and connect negative log likelihood to the supervised-learning objective used for probabilistic models.
This checks the likelihood objective, not a Bayesian posterior interpretation or a guarantee that the model family can represent the data-generating distribution.
Checked Goodfellow et al. chapters 5.5 and 5.6: section 5.5 defines theta_ML as argmax over theta of p_model(X;theta), decomposes i.i.d. data into a product over examples, then uses logs to turn the product into sum_i log p_model(x_i;theta). It also frames training as minimizing -E_data log p_model, NLL, or cross-entropy. Section 5.6 contrasts ML point estimates with Bayesian posterior distributions over theta.
Explain it without the pageWrite your own explanation before asking for feedback. Your draft and any hints stay while this page is open.
Practice · Maximum Likelihood
Try the idea in your own words
Maximum likelihood fits parameters by making the observed data most probable; for classifiers it becomes negative log-likelihood, cross-entropy, and a KL fit to the empirical distribution.
Concept · Selected for practice
Maximum Likelihood
What it rests on: Sources: Deep Learning; On the mathematical foundations of theoretical statistics
Context and links
Probability
Explain the mechanism
For Maximum Likelihood: What is the smallest example of Maximum Likelihood you can work through by hand, and what does it show? Explain your answer, including what changes, why, and which assumption matters.
A rough first thought is enough. Your draft stays when you change tasks.
Your draft stays on this page and is cleared when you leave or reload.
A little help · Explain
Open one hint at a time. These are suggestions, not your answer or a grade.
0 of 3 hints shown for this question.
Clearing your answer keeps this help record. Outside help is your own report; this page cannot check it.
Where am I stuck? (optional)
Take your draft to a feedback conversation
No AI feedback runs here. You can copy a prompt to use elsewhere; nothing is sent automatically. Review the text before sharing, and leave out private information.
Write an attempt before copying a feedback prompt.
A draft, or an AI reply to it, is not a test of what you have learned. To check that, try a different case later without help.
Ask about this pagePick one item on this page and copy a prompt about it into an AI assistant you already use. Notes you write here stay in this browser.
assert abs(bernoulli_nll(0.4) - (empirical_entropy + kl_at_theta_04)) < 1e-12Your question
Choose what your question is about
Pick the idea, equation, source, code, claim, misconception or demo state you want to ask about. The prompt you copy includes it, so the answer can stay on that item.Open the draft below to save one note and next action in this browser.
Maximum Likelihood
What is the smallest example of Maximum Likelihood you can work through by hand, and what does it show?
Fixed prompts generated from this item. They are not comments from people or independent reviews.
The 2 cited sources must support this exact item, not just the surrounding topic.
Connect the definition to one equation, piece of code or demo before widening the discussion.
Change one input, then check that the same relationship holds in the mathematics, the code and the demo.
You can state the mechanism in your own words
Local action draftNo local draft saved yetOpen when you are ready to write one next action
This draft stays in this browser and is attached to this item only.
- What the 2 cited sources say about this exact item
- The definition, its prerequisites, and a contrasting concept
- The equation or code that makes the concept concrete
- One demo state that shows what stays the same as the inputs change
- You can state the mechanism in your own words
- You can name the prerequisite that would clear up the confusion
- You can predict how the result changes when one input changes
Reference id
concept/concept-notebook/probability/maximum-likelihood
concept:probability/maximum-likelihood