Bring the mental model from Distributions; this page will reuse it instead of restarting from zero.
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.
01
Intuition
Build the mental picture first so the rest of the page has something to attach to.
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 θ^=14/20.
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.
The analogy has one important limit: 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.
Copy-only prompts — each action copies a page-grounded prompt to your clipboard. Nothing is sent by this site.
02
Math
Translate the story into symbols, assumptions, and a derivation you can inspect.
Let X1,…,Xn be observed values treated as independent draws from a fixed parametric model family pθ(x). 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 xi∈{0,1}, parameter space θ∈[0,1], and Pθ(X=1)=θ, suppose s observations are 1 and f=n−s are 0. For an ordered sequence,
and
If the data record only the count s rather than the ordered sequence, the likelihood also has a binomial coefficient (sn). That factor does not depend on θ, so it does not change the MLE.
On the open interval 0<θ<1, the derivative is
When 0<s<n, setting it to zero gives
When s=0 or s=n, there is no interior critical point. On the closed interval [0,1], the MLE is the boundary value θ^MLE=0 or θ^MLE=1. On the open interval (0,1), the maximum is not attained; the likelihood only approaches its supremum at the boundary. The demo displays θ∈[0.01,0.99] to avoid infinities from log0.
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 1 and 0.
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 x∈{0,1}. Terms with p^(x)=0 contribute 0. If p^(x)>0 but pθ(x)=0, the NLL and KL are infinite.
Since H(p^) 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 a with θ=σ(a), 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, pθ(y∣x) is conditional on the input. The dataset objective is
For language models, yi 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, pθ(x) 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.
Copy-only prompts — each action copies a page-grounded prompt to your clipboard. Nothing is sent by this site.
03
Code
Keep the implementation aligned with the notation so the algorithm is legible.
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 θ=p^.
Copy-only prompts — each action copies a page-grounded prompt to your clipboard. Nothing is sent by this site.
04
Interactive Demo
Use direct manipulation to connect the explanation to a moving system.
Live Concept Demo
Explore Maximum Likelihood
The stage is code-native and interactive. Use it to test the explanation against the mechanism.
Manipulate one control and predict the visible change.
Choose what to inspect in Maximum Likelihood. This shared fallback is an observation guide, not evidence of learning.
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.
Copy-only prompts — each action copies a page-grounded prompt to your clipboard. Nothing is sent by this site.
Concept: Maximum Likelihood
What is the smallest example that makes Maximum Likelihood click without losing the math?
Object contextProbability
concept:probability/maximum-likelihoodMaximum Likelihood
What is the smallest example that makes Maximum Likelihood click without losing the math?
Start with the prediction checkpoint, then compare the reveal to the mental model.
Take this moveStudy modes
Keep the object fixed; change the lens.Route back through the notebook
Carry the same object through intuition, math, code, and demo.
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 next edge should feel earned: use the demo prediction here before following Cross-Entropy.
After The First Pass
Turn the concept into an inspected object.
The lower panels are one second act: keep the object fixed, inspect it visually, check source boundaries, practice transfer, then attach the research question.Mechanism Storyboard
See the idea move before the page explains it
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.
Before reading further, choose the kind of change Maximum Likelihood should make visible.
Visual Inquiry
Make the image answer a mathematical question
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 visible object should carry the first intuition?
Pick the cue that should make Maximum Likelihood easier to reason about before the page gives the answer.
Source Grounding
Canonical references for the mechanism on this page.
What is the smallest example that makes Maximum Likelihood click without losing the math?
concept:probability/maximum-likelihoodsources: goodfellow-2016-deep-learning
Open the closest source note before trusting the local explanation.
1 selected-object source shown first; 1 reference total.
Audit the claim boundary, then ask from the same selected object.
Grounds maximum likelihood as the standard objective behind many supervised and generative models.
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.
Claim Review
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.
What is the smallest example that makes Maximum Likelihood click without losing the math?
concept:probability/maximum-likelihoodsources: goodfellow-2016-deep-learning
Treat every claim as provisional until source support and a local witness agree.
1 structured claim check on this concept.
Run the prediction or practice transfer before asking for a grounded review.
Publisher-side editorial review is not independent replication. Claims without it still need exact source-support review. 1 reference and 3 local witnesses are available for inspection.
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.
Reviewer: codex+oracle; reviewed 2026-05-06Practice notebook
Use the idea, then test it somewhere new
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.
What is the smallest example that makes Maximum Likelihood click without losing the math?
concept:probability/maximum-likelihoodsources: goodfellow-2016-deep-learning
Use one state from Maximum Likelihood to explain what changes, why it changes, and which assumption the explanation needs.
No learner move yet; no learning state is inferred.
Write first, use only the help you need, then try a new case without it.
Use one state from Maximum Likelihood to explain what changes, why it changes, and which assumption the explanation needs.
Reveal when your model needs a nudge.
Reveal when your model needs a nudge.
Reveal when your model needs a nudge.
Write an attempt before asking the companion.
0 of 3 progressive hints opened.
This draft and any AI response do not establish mastery; a later unassisted case can.
- ObjectConceptMaximum Likelihood
- PredictBefore revealMaximum Likelihood prediction
- WitnessCompare codeMaximum Likelihood code witness 1
- RoomAsk groundedChecking local snapshot
Research Room
Attach the question to an exact object
Pick the concept, equation, source, code witness, claim, misconception, or demo state before asking for help. The handoff stays grounded to that object.Open the draft below to save one note and next action in this browser.
Maximum Likelihood
What is the smallest example that makes Maximum Likelihood click without losing the math?
These are fixed, deterministic perspectives derived from the selected object. They do not represent people, community contributions, or independent review.
Source ids goodfellow-2016-deep-learning must support the exact object, not just the surrounding topic.
Treat this as a mechanism object: connect the definition to one equation, code witness, or demo before broadening the discussion.
Ask the learner to perturb one representation, then check whether the same invariant survives in math, code, and demo.
The learner can state the mechanism in their own words
Local action draftNo local draft saved yetExpand only when ready to capture one local next action
This draft stays locally in this browser for concept:probability/maximum-likelihood.
- Source ids to inspect: goodfellow-2016-deep-learning
- Definition, prerequisite, and contrast concept links
- The equation or code witness that makes the concept operational
- One demo state that shows the invariant instead of a slogan
- The learner can state the mechanism in their own words
- The learner can name the prerequisite that would repair confusion
- The learner can predict how the mechanism changes under one perturbation
I am working in Continuous Function's research reading room. Object: concept - Maximum Likelihood Object key: concept:probability/maximum-likelihood Context: Probability Anchor id: concept/concept-notebook/probability/maximum-likelihood Open question: What is the smallest example that makes Maximum Likelihood click without losing the math? Evidence to inspect: - Source ids to inspect: goodfellow-2016-deep-learning - Definition, prerequisite, and contrast concept links - The equation or code witness that makes the concept operational - One demo state that shows the invariant instead of a slogan Deterministic role lenses for this object: - Boundary: fixed perspectives, not people, community contributions, or independent review - Source-checking summary: Treat this as a mechanism object: connect the definition to one equation, code witness, or demo before broadening the discussion. - Proposed experiment: Ask the learner to perturb one representation, then check whether the same invariant survives in math, code, and demo. - Teach/transfer move: Turn the mechanism into one sentence that predicts a neighboring concept. - Assumptions: - Source ids goodfellow-2016-deep-learning must support the exact object, not just the surrounding topic. - The stable content-object key lets local drafts, prompts, and route memory attach without changing the source page. - The concept explanation is local atlas prose until checked against its math, code, and source support. - Prerequisite gaps should become a repair route, not a reason to leave the object vague. - Role-lens requests: - Learner: ask for "Ask what would make "Maximum Likelihood" feel predictable rather than familiar." | assumption: Source ids goodfellow-2016-deep-learning must support the exact object, not just the surrounding topic. | next action: The learner can state the mechanism in their own words - Researcher: ask for "Source ids to inspect: goodfellow-2016-deep-learning" | assumption: The stable content-object key lets local drafts, prompts, and route memory attach without changing the source page. | next action: The learner can name the prerequisite that would repair confusion - Experimenter: ask for "Choose one variable or condition to perturb before asking for an explanation." | assumption: The concept explanation is local atlas prose until checked against its math, code, and source support. | next action: The learner can predict how the mechanism changes under one perturbation - Professor: ask for "Find the smallest transferable rule a learner could reuse without the AI." | assumption: Prerequisite gaps should become a repair route, not a reason to leave the object vague. | next action: Teach or transfer: Turn the mechanism into one sentence that predicts a neighboring concept. What would resolve this: - The learner can state the mechanism in their own words - The learner can name the prerequisite that would repair confusion - The learner can predict how the mechanism changes under one perturbation Answer as a careful research tutor: stay source-grounded, separate verified evidence from assumptions, name the relevant math objects, and end with one next action. Current deterministic role lens for this object: - Role lens: Learner - Evidence request: Ask what would make "Maximum Likelihood" feel predictable rather than familiar. - Assumption to keep visible: Source ids goodfellow-2016-deep-learning must support the exact object, not just the surrounding topic. - Proposed experiment: Ask the learner to perturb one representation, then check whether the same invariant survives in math, code, and demo. - Next action: The learner can state the mechanism in their own words
concept/concept-notebook/probability/maximum-likelihood
concept:probability/maximum-likelihood