Bring the mental model from Logistic Regression; this page will reuse it instead of restarting from zero.
Machine Learning
Multinomial Logistic Regression
Softmax regression turns one score per class into a normalized probability distribution and learns by moving probability mass toward the observed class.
Concept Structure
Multinomial Logistic Regression
Start with the picture, metaphor, or geometric mechanism.
Make the objects explicit and connect them with notation.
Mirror the equations with runnable implementation details.
Manipulate the mechanism and watch the idea respond.
Learning map
Multinomial Logistic RegressionConceptual Bridge
What should feel connected as you move through this page.
Softmax regression turns one score per class into a normalized probability distribution and learns by moving probability mass toward the observed class.
The next edge should feel earned: use the demo prediction here before following Scaled Dot-Product Attention & Transformer Layers.
01
Intuition
Build the mental picture first so the rest of the page has something to attach to.
You are here because a language model, image classifier, and attention mechanism all need the same basic move: turn a list of scores into a distribution. Binary logistic regression has one logit. Softmax regression has one logit per class.
Before this, know logistic regression and cross-entropy. By the end, you should be able to explain why softmax probabilities sum to one, why adding the same constant to every logit changes nothing, and why the logit gradient is .
Imagine three labels: cat, dog, and bird. The model gives each label a score. A score by itself is not a probability because scores can be negative, large, or unnormalized. Softmax exponentiates the scores and normalizes them:
The highest score gets the largest probability, but every class competes through the denominator. Raising one logit steals probability mass from the others.
Softmax also has a useful invariance. If you add the same number to every logit, every exponential is multiplied by , and that factor cancels:
That is why stable implementations subtract the maximum logit before exponentiating. It changes the numbers used internally, not the distribution.
02
Math
Translate the story into symbols, assumptions, and a derivation you can inspect.
For one input and classes, collect class weights in and biases in . The logit vector is
The predicted class distribution is
If the observed class is , the likelihood is . The negative log-likelihood is
Substituting the softmax gives the log-sum-exp form:
Now differentiate with respect to one logit :
That is the multi-class version of the logistic-regression signal . The correct class has a negative gradient unless it already has probability near , so gradient descent raises its logit. Incorrect classes have positive gradients, so gradient descent lowers their logits.
For a batch with design matrix , one-hot labels , probabilities , and weights , one common convention writes logits as
The average-loss gradients are
and
The notation differs by whether examples are rows or columns, but the invariant is stable: softmax plus cross-entropy creates a probability-error vector over classes.
03
Code
Keep the implementation aligned with the notation so the algorithm is legible.
import numpy as np
# Three-class softmax regression on tiny 2D points.
# Shapes: X is (n, 3) with bias column, W is (3, K).
X_raw = np.array([[-2, 0], [-1, 1], [0, -1], [1, 1], [2, 0], [1, -2]], float)
y = np.array([0, 0, 1, 1, 2, 2])
K = 3
X = np.column_stack([np.ones(len(X_raw)), X_raw])
Y = np.eye(K)[y]
W = np.zeros((X.shape[1], K))
def softmax(z):
z = z - z.max(axis=1, keepdims=True)
exp_z = np.exp(z)
return exp_z / exp_z.sum(axis=1, keepdims=True)
for step in range(120):
logits = X @ W
Q = softmax(logits)
grad = X.T @ (Q - Y) / len(X)
W -= 0.7 * grad
Q = softmax(X @ W)
loss = -np.mean(np.log(Q[np.arange(len(y)), y] + 1e-12))
print("class probabilities:")
print(np.round(Q, 3))
print("loss:", round(loss, 4))
print("first example logit gradient:", np.round(Q[0] - Y[0], 3))
print("row sums:", np.round(Q.sum(axis=1), 6))
The code mirrors the math: softmax normalizes logits row by row, Q - Y is the probability-error matrix, and X.T @ (Q - Y) / n is the weight gradient.
04
Interactive Demo
Use direct manipulation to connect the explanation to a moving system.
Set three logits and choose the true class. Before revealing the gradient, predict the shape of the update: does one wrong class nearly match the true-class upward push, is the wrong probability mass split across wrong classes, or are all updates already small?
The reveal shows the invariant that is easy to miss: for one example, the true-class upward update has magnitude , while all wrong-class downward updates sum to the same amount. A single wrong class can nearly tie the true-class push, but it cannot be larger unless the demo has changed the object being measured. The shared-shift slider adds the same value to every logit. Watch the raw scores move while the probabilities and gradients stay fixed. That small invariant is the bridge from classical softmax regression to stable neural-network implementations.
Live Concept Demo
Explore Multinomial Logistic Regression
The stage is code-native and interactive. Use it to test the explanation against the mechanism.
Manipulate one control and predict the visible change.
Commit to what Multinomial Logistic Regression should make visible before reading the result.
After The First Pass
Turn the concept into an inspected object.
Once the invariant is visible in the intuition, math, code, and demo, use these panels to inspect the mechanism visually, check source support, practice the idea, and attach a grounded research question.
Mechanism Storyboard
See the idea move before the page explains it
Softmax regression turns one score per class into a normalized probability distribution and learns by moving probability mass toward the observed class.
Start with the picture, metaphor, or geometric mechanism.
Before reading further, choose the kind of change Multinomial Logistic Regression should make visible.
Visual Inquiry
Make the image answer a mathematical question
Softmax regression turns one score per class into a normalized probability distribution and learns by moving probability mass toward the observed class.
Which visible object should carry the first intuition?
Pick the cue that should make Multinomial Logistic Regression easier to reason about before the page gives the answer.
Source Grounding
Canonical references for the mechanism on this page.
Curriculum source for softmax regression and multi-class likelihood.
Open sourceCurriculum source for logits, softmax probabilities, and implementation-oriented multi-class classification.
Open sourceClaim Review
Softmax regression turns one score per class into a normalized probability distribution and learns by moving probability mass toward the observed class.
Claims without a substantive review badge still need exact source-support review.
cs229-softmax-regression, d2l-softmax-regression
Use equation, code, and demo objects to check whether the source support is operational.
CS229 gives softmax logits, NLL/cross-entropy, and derivative phi_i - 1{y=i}; D2L independently derives softmax-cross-entropy derivative softmax(o)_j - y_j and the rowwise vectorized model.
Sources: CS229 Lecture Notes: Softmax Regression, Dive into Deep Learning: Softmax RegressionThis supports single-label softmax classification mechanics, not calibrated probabilities, multi-label classification, attention semantics, or any claim that one wrong class can exceed the total true-class push.A bounded review summary is present; still check caveats and exact source scope.Checked CS229 section 2.3 and D2L section 4.1: both support softmax probabilities, one-hot labels, cross-entropy/NLL, and the logit derivative as predicted probability minus the label indicator. Prior GPT Pro blocker about the wrong-class update was resolved by teaching true-class push equals total wrong-class pull.
Reviewer: codex+gpt-pro-prior; reviewed 2026-06-28Source support candidates
course-notes 2023CS229 Lecture Notes: Softmax RegressionCurriculum source for softmax regression and multi-class likelihood.
bookDive into Deep Learning: Softmax RegressionCurriculum source for logits, softmax probabilities, and implementation-oriented multi-class classification.
Practice Loop
Try the idea before it explains itself
Softmax regression turns one score per class into a normalized probability distribution and learns by moving probability mass toward the observed class.
Before touching the demo, predict one visible change that should happen in Multinomial Logistic Regression.
Reveal when your model needs a nudge.
Reveal when your model needs a nudge.
Reveal when your model needs a nudge.
A concrete answer is on the canvas.
The answer names why the claim should hold.
It touches the page context or a neighboring idea.
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.
Multinomial Logistic Regression
What is the smallest example that makes Multinomial Logistic Regression click without losing the math?
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:machine-learning/multinomial-logistic-regression.
- Source ids to inspect: cs229-softmax-regression, d2l-softmax-regression
- 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 - Multinomial Logistic Regression Object key: concept:machine-learning/multinomial-logistic-regression Context: Machine Learning Anchor id: concept/concept-notebook/machine-learning/multinomial-logistic-regression Open question: What is the smallest example that makes Multinomial Logistic Regression click without losing the math? Evidence to inspect: - Source ids to inspect: cs229-softmax-regression, d2l-softmax-regression - 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 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.
concept/concept-notebook/machine-learning/multinomial-logistic-regression
concept:machine-learning/multinomial-logistic-regression