Tutorials › Generalized Linear Models › Deriving Category Probabilities With The Softmax Map

Multinomial Logit Models · Tutorial 488 of 981

Deriving Category Probabilities With The Softmax Map

Learn how baseline-category predictors determine a valid probability for every response category through the softmax map.

Intermediate 9 min read

What You'll Learn

  • Define the baseline-category predictors and the softmax map for \(K\) response categories
  • Derive the probability formulas from the baseline logit equations and normalization
  • Verify that finite predictors give positive probabilities summing to one when \(K \ge 2\)
  • Show how strictly positive category probabilities determine unique baseline predictors
  • Calculate category probabilities from exact predictor values and recover predictors from probabilities
  • Recognize why zero probabilities cannot be represented by finite baseline predictors

From Baseline Logits to Category Probabilities

A baseline-category logit model describes a response that can fall into one of \(K\) categories. For a fixed covariate profile, the model uses a predictor for each nonbaseline category relative to a designated baseline. Those predictors are log ratios, not probabilities: they can be negative, positive, or any finite real number. The softmax map converts them into a full set of category probabilities.

The conversion has to satisfy two requirements. Each probability must be positive, and the probabilities across all categories must add to one. The baseline category is included in the normalization even though it has no separately estimated predictor: its relative weight is one. This tutorial derives that normalization, checks its properties, and works through calculations in both directions.

Definition: Let \(Y\) take one of \(K\) categories, labelled \(1,\ldots,K\), where \(K\ge 2\). Choose category \(K\) as the baseline. At a fixed covariate profile, write \(p_j=P(Y=j)\). The baseline-category predictors are \(\eta_j=\log(p_j/p_K)\) for \(j=1,\ldots,K-1\), whenever all category probabilities are positive. The softmax map assigns a probability to each category from the predictors \(\eta_1,\ldots,\eta_{K-1}\).

In a regression model, each nonbaseline predictor may depend on covariates, for example through a linear expression \(\eta_j(x)\). The probability calculation below is carried out at one fixed profile \(x\), so we write \(\eta_j\) rather than repeatedly including \(x\). The baseline convention is equivalent to setting \(\eta_K=0\); this is a convenient way to include the baseline in the same normalization as the other categories.

Deriving the Softmax Formula

Start from the defining log-ratio equations for the nonbaseline categories. Exponentiating each equation gives \(p_j/p_K=\exp(\eta_j)\), or \(p_j=p_K\exp(\eta_j)\). Thus every nonbaseline probability is its baseline probability multiplied by a relative weight. The requirement that all category probabilities sum to one determines the common scale \(p_K\).

1
Exponentiate the baseline logits.
For each \(j<K\), \(p_j=p_K\exp(\eta_j)\).
2
Apply the probability sum.
Substitute those expressions into \(p_K+\sum_{j=1}^{K-1}p_j=1\), giving \(p_K\left(1+\sum_{r=1}^{K-1}\exp(\eta_r)\right)=1\).
3
Solve for the baseline probability.
Since the expression in parentheses is positive, \(p_K=1/\left(1+\sum_{r=1}^{K-1}\exp(\eta_r)\right)\).
4
Recover each other probability.
Insert this value of \(p_K\) into \(p_j=p_K\exp(\eta_j)\).
$$ p_j=\frac{\exp(\eta_j)}{1+\sum_{r=1}^{K-1}\exp(\eta_r)} \quad (j=1,\ldots,K-1), \qquad p_K=\frac{1}{1+\sum_{r=1}^{K-1}\exp(\eta_r)}. $$

Equivalently, define \(\eta_K=0\) and include all \(K\) categories in the denominator:

$$ p_j=\frac{\exp(\eta_j)}{\sum_{r=1}^{K}\exp(\eta_r)} \quad (j=1,\ldots,K), \qquad \eta_K=0. $$

The two forms are identical because \(\exp(\eta_K)=\exp(0)=1\). The baseline has a numerator too; it is simply one. The denominator is the sum of all category weights, not just the weights for categories with estimated predictors.

Worked Example: Two Predictors With Exact Exponentials

There are three categories, with category 3 as the baseline. Suppose \(\eta_1=\log 2\) and \(\eta_2=\log 3\). Find all three probabilities.

First compute the weights: \(\exp(\eta_1)=2\), \(\exp(\eta_2)=3\), and the baseline weight is \(1\). The denominator is therefore \(1+2+3=6\). The probabilities are

$$ p_1=\frac{2}{6}=\frac13,\qquad p_2=\frac{3}{6}=\frac12,\qquad p_3=\frac{1}{6}=\frac16. $$

They sum to \(1/3+1/2+1/6=2/6+3/6+1/6=1\), and each is positive. As a check against the original predictors, \(p_1/p_3=(1/3)/(1/6)=2\) and \(p_2/p_3=(1/2)/(1/6)=3\). Taking logarithms gives \(\log 2\) and \(\log 3\), as specified.

Why the Formula Gives Valid Probabilities

The softmax formula is defined for finite real predictors. Its denominator contains positive terms, including the baseline term \(1\), so it cannot be zero. The next result checks both the range of each probability and the sum constraint. The condition \(K\ge2\) matters: with one category there are no nonbaseline predictors, and its sole probability is one.

Theorem: Suppose \(K\ge2\) and \(\eta_1,\ldots,\eta_{K-1}\) are finite real numbers. Define \(p_1,\ldots,p_K\) by the softmax formulas above. Then \(0<p_j<1\) for every \(j=1,\ldots,K\), and \(\sum_{j=1}^{K}p_j=1\).

Proof. Set \(D=1+\sum_{r=1}^{K-1}\exp(\eta_r)\). Each exponential is finite and strictly positive, and \(D\) includes the positive term \(1\), so \(0<D<\infty\). For \(j<K\), \(p_j=\exp(\eta_j)/D>0\); also \(p_K=1/D>0\). For a nonbaseline category, \(D\) contains its numerator \(\exp(\eta_j)\) and the additional positive baseline term \(1\), so \(D>\exp(\eta_j)\) and \(p_j<1\). For the baseline, \(K\ge2\) ensures that the sum defining \(D\) includes at least one positive exponential term, so \(D>1\) and \(p_K<1\). Finally,

$$ \sum_{j=1}^{K}p_j = \frac{\sum_{j=1}^{K-1}\exp(\eta_j)+1} {1+\sum_{r=1}^{K-1}\exp(\eta_r)} =1. $$

Thus the softmax outputs are strictly positive probabilities summing to one. \(\square\)

A useful way to interpret the calculation is that the unnormalized weights are \(\exp(\eta_1),\ldots,\exp(\eta_{K-1}),1\). Dividing every weight by their total produces probabilities without changing the relative weight of any pair of categories. In particular, the baseline ratio remains \(p_j/p_K=\exp(\eta_j)\).

Worked Example: Predictors That Are Not Logarithms of Integers

For three categories with category 3 as baseline, suppose \(\eta_1=\log 4\) and \(\eta_2=\log(1/2)\). Calculate the probabilities and verify that they sum to one.

The three weights are \(4\), \(1/2\), and \(1\). Their total is \(4+1/2+1=11/2\). Dividing each weight by \(11/2\) gives

$$ p_1=\frac{4}{11/2}=\frac{8}{11},\qquad p_2=\frac{1/2}{11/2}=\frac{1}{11},\qquad p_3=\frac{1}{11/2}=\frac{2}{11}. $$

The sum is \(8/11+1/11+2/11=11/11=1\). The probabilities recover the specified relative weights: \(p_1/p_3=(8/11)/(2/11)=4\), while \(p_2/p_3=(1/11)/(2/11)=1/2\). A negative predictor such as \(\log(1/2)\) therefore gives a weight below one, but it still gives a positive probability.

The Inverse Map: Recovering Predictors

The relationship also works in reverse, provided every category has positive probability. This positivity condition is necessary for the logarithms of the probability ratios to be finite. The result says that the softmax map gives a one-to-one correspondence between finite baseline predictors and probability vectors in the interior of the \(K\)-category probability simplex.

Theorem: Let \(K\ge2\). For any finite real \(\eta_1,\ldots,\eta_{K-1}\), the softmax formulas produce a probability vector with all entries positive. Conversely, for any probabilities \(p_1,\ldots,p_K\) satisfying \(p_j>0\) for every \(j\) and \(\sum_{j=1}^{K}p_j=1\), the unique finite predictors that produce them are \(\eta_j=\log(p_j/p_K)\), \(j=1,\ldots,K-1\).

Proof. The forward direction follows from the preceding theorem. For the converse, define \(\eta_j=\log(p_j/p_K)\). These are finite real numbers because \(p_j>0\) and \(p_K>0\). Exponentiating gives \(\exp(\eta_j)=p_j/p_K\), so the softmax denominator is

$$ 1+\sum_{r=1}^{K-1}\exp(\eta_r) = 1+\sum_{r=1}^{K-1}\frac{p_r}{p_K} = \frac{p_K+\sum_{r=1}^{K-1}p_r}{p_K} = \frac{1}{p_K}. $$

The softmax probability for category \(j<K\) is therefore \((p_j/p_K)/(1/p_K)=p_j\), and the baseline probability is \(1/(1/p_K)=p_K\). This proves existence. For uniqueness, if any finite predictors produce the given probabilities, their baseline ratios must satisfy \(\exp(\eta_j)=p_j/p_K\). Taking the logarithm forces \(\eta_j=\log(p_j/p_K)\) for every \(j<K\). Hence no other finite predictor vector produces the same probabilities. \(\square\)

Worked Example: Recovering Predictors From Probabilities

Suppose the probabilities for three categories are \(p_1=0.2\), \(p_2=0.5\), and \(p_3=0.3\), with category 3 as baseline. Find the baseline-category predictors, then verify that the softmax map returns the original probabilities.

The probabilities are all positive and sum to \(0.2+0.5+0.3=1\), so the inverse formula applies. The predictors are

$$ \eta_1=\log\left(\frac{0.2}{0.3}\right)=\log\left(\frac23\right), \qquad \eta_2=\log\left(\frac{0.5}{0.3}\right)=\log\left(\frac53\right). $$

Their exponentiated weights are \(2/3\) and \(5/3\), with baseline weight \(1\). The denominator is \(1+2/3+5/3=10/3\). Consequently,

$$ p_1=\frac{2/3}{10/3}=\frac15=0.2,\qquad p_2=\frac{5/3}{10/3}=\frac12=0.5,\qquad p_3=\frac{1}{10/3}=\frac{3}{10}=0.3. $$

The reconstructed values match the starting probabilities, as the inverse result guarantees.

Reading a Multicategory Calculation Carefully

For more than three categories, the same steps apply without alteration: exponentiate each nonbaseline predictor, append a baseline weight of one, sum all the weights, and divide each weight by that sum. Keeping the baseline weight visible is a practical safeguard against omitting a category from the denominator.

Worked Example: Four Categories With a Baseline Weight

Take category 4 as baseline and suppose \(\eta_1=\log 2\), \(\eta_2=\log 5\), and \(\eta_3=\log(1/2)\). Find the four probabilities.

The weights for categories 1, 2, and 3 are \(2\), \(5\), and \(1/2\); category 4 has weight \(1\). The total weight is \(2+5+1/2+1=17/2\). Thus

$$ p_1=\frac{2}{17/2}=\frac4{17},\qquad p_2=\frac{5}{17/2}=\frac{10}{17},\qquad p_3=\frac{1/2}{17/2}=\frac1{17},\qquad p_4=\frac{1}{17/2}=\frac2{17}. $$

Their sum is \((4+10+1+2)/17=17/17=1\). The smallest weight is still positive, so category 3 has positive probability even though its predictor is negative.

Common Mistakes and Why the Map Matters

  • Omitting the baseline weight. A tempting but incorrect denominator is \(\sum_{r=1}^{K-1}\exp(\eta_r)\). That expression leaves out the baseline category and generally makes the probabilities sum to more than one when the baseline probability is added. Include its weight \(1=\exp(0)\).
  • Treating predictors as probabilities. A predictor can be negative or greater than one, while a probability must lie between zero and one. Exponentiating and normalizing—not interpreting \(\eta_j\) directly—produces the probability.
  • Claiming finite predictors can produce a zero probability. For every finite real \(\eta_j\), \(\exp(\eta_j)>0\), so the softmax probability is strictly positive. A probability vector containing a zero cannot be represented by finite baseline predictors through the inverse logarithm formula.
  • Forgetting the number of categories. The strict upper bound \(p_j<1\) uses \(K\ge2\). With just one category, the only probability is \(1\), and there are no nonbaseline predictors.

The softmax map matters because it turns unconstrained finite real predictors into a valid probability vector at each covariate profile. It also makes clear what information the predictors encode: each one specifies a log ratio to the baseline, while the normalization determines all category probabilities together.

Check Your Understanding

Use the baseline weight of one whenever you calculate a softmax denominator.

  1. With three categories and category 3 as baseline, calculate the probabilities for \(\eta_1=0\) and \(\eta_2=\log 2\).
  2. Why does the proof that every softmax probability is less than one require \(K\ge2\)?
  3. For \(K=4\), write the softmax denominator when category 4 is the baseline.
  4. Given strictly positive probabilities \(p_1,\ldots,p_K\) summing to one, what is the unique baseline predictor for category \(j<K\)?
  5. Can a finite baseline predictor vector produce a probability vector with \(p_1=0\)? Explain using the formula or the inverse map.
Clinical Biostats