Perplexity measures how well a language model predicts a target token distribution. It equals the exponential of average cross-entropy loss, so lower values indicate better fit and less surprise on the evaluation data. section 7.4
Perplexity
Perplexity is a language-modeling metric equal to the exponential of average cross-entropy loss, measuring how well a model predicts a target token distribution.
How Transformers in Action covers it
- How deep it goes
- Defines the metric and works through tokenization, padding, loss masking, batching, averaging, and exponentiation.
- Examples
- Compares base and fine-tuned Gemma checkpoints on up to 500 chat-formatted evaluation examples.
- What it assumes
- Assumes language-model evaluation, tokenization, chat templates, and model loss interfaces.
- What you can do after
- Diagnose/debug with it: Compare checkpoint fit using a batched PyTorch calculation that ignores padded tokens.
- How it connects
- Connects language modeling, cross-entropy loss, tokenization, chat templates, causal language models, and supervised fine-tuning.
Also explained in
-
Build a Large Language Model (From Scratch)An evaluation metric defined as the exponential of cross entropy loss, indicating how uncertain the model is about the next token.
-
Sutskever's ListPerplexity is a language-model metric representing the effective number of plausible next tokens, with lower values indicating greater predictive certainty.
-
Generative AI in ActionPerplexity is a language-model metric that quantifies uncertainty in predicting the next token of a sequence.
-
Domain-Specific Small Language ModelsA measure of how well a language model predicts tokens in sequence, with lower values generally indicating better predictive fit.
Compare how 5 books explain perplexity →
Related concepts
- compressioncontrasts with · Compression is the reduction of a representation’s size or resource requirements while preserving enough information or behavior for its intended use.
- fluencymeasures · Fluency is the degree to which language can be used or produced grammatically, coherently, naturally, and with ease.
- input reversalproduced by · Input reversal is the technique of presenting a source sequence to a sequence model in reverse element order.
- language modelmeasures · A language model is a computational model that represents patterns in linguistic tokens to assign probabilities to, predict, or generate sequences of language.
This explainer was generated by Manning's knowledge graph from the text of Transformers in Action. The section links point to the parts of the book it draws on.




