Equations · Bridle (1990) named it; used by every classifier and attention layer since
The softmax formula, explained
Softmax turns arbitrary scores (logits) into a probability distribution over options.
Term by term
The vector of scores (logits), one per class. Any real numbers.
The -th entry of the output: the probability given to class .
Exponentiating makes every score positive and stretches the gaps between them.
The total over all classes. Dividing by it makes the outputs sum to 1.
A small worked example
For : , total , so . Adding 100 to every score gives the same answer, which is why code subtracts the largest score first.
In code
import numpy as np
def softmax(z):
e = np.exp(z - z.max()) # subtracting the max avoids overflow
return e / e.sum()Every symbol in it
Other equations
- Scaled dot-product attention
- Cross-entropy loss
- Adam update
- Layer normalization
- RMSNorm
- The ELBO
- KL divergence
- Backpropagation through one layer
- LoRA
- GELU
- Dropout
- Batch normalization
- Rotary position embedding (RoPE)
- Multi-head attention
- PPO clipped objective
- DPO loss
- Policy gradient (REINFORCE)
- Bellman equation
- Q-learning update
- InfoNCE contrastive loss
- Diffusion forward process
- DDPM simplified loss
- VAE reparameterization trick
- GAN minimax objective
- AdamW
- Cosine learning-rate schedule
- Perplexity
- Logistic regression
- Normal equation (linear regression)
- Singular value decomposition (SVD)
- Principal component analysis (PCA)