Softmax & Temperature Lab
Softmax & Temperature Lab
Interactive lab · From a score to a probability

Logistic regression, softmax & temperature

Classifiers and language models produce raw scores. Three small functions turn those scores into probabilities you can act on: the sigmoid for two choices, the softmax for many, and a temperature dial that decides how sharply the probabilities favor the top score. Every number on this page is computed live as you move the controls.

1
The sigmoid

A score becomes a probability through the odds

Logistic regression treats its score z as the log-odds of the positive class. Undo the log and the odds, and you get the sigmoid:

p = σ(z) = 1 / (1 + e−z)  ⇔  z = ln( p / (1 − p) )

Each unit of score multiplies the odds by e ≈ 2.72. A score of 0 is a coin flip. The curve is steepest there and flattens toward 0 and 1, so the score can range over all real numbers while p stays strictly between 0 and 1.

p = σ(z)
Odds p : (1 − p)
1 − p = σ(−z)

2
Logistic regression

A line through the data, and a probability on either side

With two features the score is z = w₁x₁ + w₂x₂ + b. The decision boundary is the line where z = 0 and p = 50%. The arrow is the weight vector w: it points toward class A, and its length sets how fast p climbs as you move across the line.

L = −mean[ y log p + (1 − y) log(1 − p) ] + (λ/2)‖w‖²

Press Train to run gradient descent on this log loss. Drag the arrow to set w yourself, or click the field to add points. On data that separates cleanly, try λ = 0: the boundary stops moving but ‖w‖ keeps growing, and the model becomes ever more confident. The temperature slider rescales the score as z / T, which changes confidence without moving the boundary.

Click adds
Log loss at T
Accuracy
‖w‖
Step
3
Softmax

Many scores, one distribution

With more than two classes, each class gets its own score (a logit). Softmax exponentiates every logit so all values are positive, then divides by their total so they sum to 1:

pk = ezk / Σj ezj

Only differences between logits matter. Adding the same number to every logit changes each ez but leaves the probabilities alone. With two classes, softmax reduces to the sigmoid of the score difference, so logistic regression is the two-class case of softmax.

class
1 · logit z (drag)
2 · ez
3 · ÷ total = p
Σ ez
Σ p

4
Temperature

One dial from certainty to chaos

Temperature divides every logit before the softmax:

pk(T) = ezk/T / Σj ezj/T

At T = 1 you get the model's own distribution. Below 1, gaps between logits widen and the top choice takes over; as T → 0 the softmax becomes argmax, which is greedy decoding. Above 1, gaps shrink and the distribution flattens toward uniform. The ranking never changes; only the confidence does.

Language models pick each next word by sampling from this distribution. Below are invented logits a model might give for the next word. Generate a few sentences at different temperatures and compare the counts to the probabilities.

The cat sat on the mat.
0.05 · greedy1 · model as trained10 · near-uniform
Top word probability
Entropy
Effective choices 2H
Log scale. The vertical line is the current T.

Bars show probability. The black tick shows the share of samples so far.

Summary

How the four pieces fit

PieceFormulaRelationship
Sigmoidσ(z) = 1 / (1 + e−z)Inverse of the log-odds. Maps any score to a probability between 0 and 1.
Logistic regressionp = σ(w·x + b)A linear score passed through the sigmoid and trained with log loss, which is binary cross-entropy.
Softmaxpk = ezk / Σ ezjGeneralizes the sigmoid to K classes. With K = 2, p₁ = σ(z₁ − z₂).
Temperaturesoftmax(z / T)Rescales logits. Equivalent to scaling the weights by 1/T, so it changes confidence but never the ranking or the decision boundary.