Perplexity evaluates next-token prediction uncertainty by exponentiating cross entropy loss. Lower perplexity means the predicted distribution more closely matches the dataset distribution. section 5.1.2
Compute perplexity from model outputs in three stages:
- Obtain logits shaped [batch, sequence, vocabulary] and align them with target token IDs. section 5.1.2
- Calculate cross entropy over flattened logits and targets, combining token positions across the batch. section 5.1.2
- Apply torch.exp(loss) to convert the loss into a more interpretable uncertainty measure. section 5.1.2
Worked value
A cross entropy loss of approximately 10.7940 produces perplexity 48,725.8203. This indicates uncertainty equivalent to choosing among roughly 48,725 vocabulary tokens at each step. section 5.1.2




