Perplexity Calculator
Enter per-token probabilities or a cross-entropy loss value to compute language model perplexity and understand model quality.
Input
Example: GPT output token probabilities from a log-softmax layer (converted to linear scale).
This is the value reported by nn.CrossEntropyLoss or similar — already averaged over tokens.
Quick examples
Enter probabilities or a loss value, then click Calculate.
Perplexity
Cross-entropy (nats)
H = −(1/N) ∑ ln(pi)
Cross-entropy (bits)
Hbits = Hnats / ln 2
Token count (N)
Avg token probability
Formula
Per-token breakdown
| Token # | Probability | −ln(p) | Contribution |
|---|
Summary
Enter per-token probabilities or a cross-entropy loss value to compute language model perplexity and understand model quality.
How it works
- Choose an input mode: enter per-token probabilities (one per line) or a single cross-entropy loss value.
- For per-token mode, the tool computes the average negative log-likelihood: H = -1/N * sum(log(p_i)).
- For cross-entropy mode, the value is used directly as H.
- Perplexity is then PP = exp(H). Lower perplexity means the model assigns higher probability to the correct tokens.
- The result panel shows perplexity, cross-entropy (nats and bits), and an interpretation of the score.
Use cases
- Evaluate and compare language model quality on a held-out test set.
- Convert a reported cross-entropy loss (e.g., from PyTorch training logs) into the more interpretable perplexity metric.
- Verify perplexity calculations by hand when debugging NLP training pipelines.
- Understand how individual token probabilities contribute to overall model perplexity.
- Quickly sanity-check whether a reported perplexity figure is plausible given the token probabilities.
- Learn the relationship between cross-entropy, bits-per-character, and perplexity.
Frequently Asked Questions
Last updated: 2026-07-22 ·
Reviewed by Nham Vu