← CS Lab AI & Machine Learning / Softmax Open standalone ↗

Softmax turns a vector of raw scores into a probability distribution. Feed it the unnormalised outputs of a network — the logits — and it hands back numbers that are all positive and sum to exactly 1, ready to read as probabilities.

Where you meet it

What it does

It maps an arbitrary real-valued vector to the probability simplex: each component lands in (0, 1) and the components add up to 1. A large input score becomes a large share of the probability mass, a small one a tiny share — but nothing ever drops to a hard zero, which is what keeps gradients flowing during training.

Softmax is a soft argmax: it crowns a winner without ever zeroing the rest, so gradients keep flowing.

How it works

For a logit vector z, the probability of class i is:

softmax(z)ᵢ = e^(zᵢ) / Σⱼ e^(zⱼ)

Two moves. Exponentiate each logit — e^(zᵢ) is always positive and stretches the gaps between scores. Then normalise by dividing by the sum of all exponentials, so the results add to 1. Because exp grows fast, the largest logit grabs most of the mass — softmax behaves like a smooth, differentiable argmax (a "soft argmax").

A temperature T rescales the logits first, z/T. Low T sharpens the distribution toward winner-take-all; high T flattens it toward uniform. This is the knob that controls randomness when sampling from a language model.

Watch out

  • Numerical stability. e^(zᵢ) overflows for large logits. The fix is exact and standard: subtract the max first, e^(zᵢ − max z) — same result, no overflow. Frameworks do this for you.
  • Don't confuse it with sigmoid. Softmax models mutually exclusive classes (one winner, probabilities coupled). Sigmoid gives independent per-class probabilities — use it for multi-label, not single-label.
  • Probabilities ≠ confidence. A 0.99 softmax output is not a calibrated 99% chance of being right; modern networks are often overconfident. Treat it as a ranking, not a guarantee.
  • Pair it with cross-entropy, not separately. Implementations fuse log-softmax and the loss (e.g. log_softmax + nll_loss) for stability — applying softmax then a separate log invites the overflow above.

Go deeper

Softmax macht aus einem Vektor roher Scores eine Wahrscheinlichkeitsverteilung. Du gibst die unnormierten Ausgaben eines Netzes hinein — die Logits — und bekommst Zahlen zurück, die alle positiv sind und sich exakt zu 1 summieren, fertig zum Ablesen als Wahrscheinlichkeiten.

Wo es vorkommt

Was es tut

Es bildet einen beliebigen reellwertigen Vektor auf das Wahrscheinlichkeits-Simplex ab: jede Komponente liegt in (0, 1) und alle zusammen ergeben 1. Ein großer Eingabe-Score bekommt einen großen Anteil der Wahrscheinlichkeitsmasse, ein kleiner einen winzigen — aber nichts fällt je auf hart null, was die Gradienten beim Training fließen lässt.

Softmax ist ein weiches argmax: es kürt einen Sieger, ohne den Rest auf null zu setzen — so fließen die Gradienten weiter.

Wie es funktioniert

Für einen Logit-Vektor z ist die Wahrscheinlichkeit der Klasse i:

softmax(z)ᵢ = e^(zᵢ) / Σⱼ e^(zⱼ)

Zwei Schritte. Exponenzieren jedes Logits — e^(zᵢ) ist immer positiv und spreizt die Abstände zwischen den Scores. Dann normieren, indem man durch die Summe aller Exponentiale teilt, sodass das Ergebnis zu 1 summiert. Weil exp schnell wächst, schnappt sich der größte Logit den Großteil der Masse — Softmax verhält sich wie ein glattes, differenzierbares argmax (ein „soft argmax").

Eine Temperatur T skaliert die Logits vorab, z/T. Niedriges T schärft die Verteilung Richtung „Sieger nimmt alles"; hohes T flacht sie Richtung Gleichverteilung ab. Das ist der Regler, der den Zufall beim Sampling aus einem Sprachmodell steuert.

Worauf achten

  • Numerische Stabilität. e^(zᵢ) läuft bei großen Logits über (Overflow). Der Fix ist exakt und Standard: erst das Maximum abziehen, e^(zᵢ − max z) — gleiches Ergebnis, kein Overflow. Frameworks erledigen das für dich.
  • Nicht mit Sigmoid verwechseln. Softmax modelliert sich gegenseitig ausschließende Klassen (ein Sieger, Wahrscheinlichkeiten gekoppelt). Sigmoid liefert unabhängige Wahrscheinlichkeiten pro Klasse — das ist für Multi-Label, nicht für Single-Label.
  • Wahrscheinlichkeiten ≠ Konfidenz. Ein Softmax-Wert von 0.99 ist keine kalibrierte 99-%-Chance, richtig zu liegen; moderne Netze sind oft überkonfident. Nimm es als Rangfolge, nicht als Garantie.
  • Mit Cross-Entropy paaren, nicht getrennt. Implementierungen verschmelzen Log-Softmax und Loss (z. B. log_softmax + nll_loss) wegen der Stabilität — erst Softmax und dann ein separates Log lädt den Overflow von oben ein.

Mehr dazu

Next up
AI & Machine LearningTokenization AI & Machine LearningTemperature Sampling All concepts →