Equations · Standard; the negative log-likelihood of a categorical model
The cross-entropy loss formula, explained
The loss used to train classifiers and language models: the average negative log-probability the model gave to the right answer.
Term by term
The target for example , class : 1 for the correct class and 0 otherwise (one-hot). The indexes examples; it is not a power.
The model's predicted probability of class for example , usually a softmax output.
Natural log. Because is one-hot, the inner sum keeps only of the probability given to the correct class.
A small worked example
Target , prediction : the loss is . A confident wrong answer, , would cost .
In code
import numpy as np
def cross_entropy(y_onehot, y_prob):
# y_onehot, y_prob: (N, K)
return -np.mean(np.sum(y_onehot * np.log(y_prob), axis=1))Every symbol in it
Loss (ℒ)ThetaFractionSummationSuperscript in parenthesesSubscript (index or label)Hat (estimate)Logarithm
Other equations
- Scaled dot-product attention
- Softmax
- 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)