AI-ENGINEERING
    intermediate

    Evaluation Metrics: Perplexity & Similarity

    AI Engineer path · lesson 87 of 124
    The idea
    Marking an essay by counting how many of the model answer's words appear in it. It works surprisingly often, fails completely on a good paraphrase, and fails silently — and dangerously — on an answer that says the exact opposite in the same vocabulary.
    How to use
    Pick each of the four pairs in turn and read the three scores side by side. The pairs are chosen so that at least one metric is badly wrong about each of them.
    Cross-entropy measures how surprised a model is by the text it is shown. Perplexity is the same quantity in friendlier units: the effective number of equally-likely options the model was choosing between.
    0.500
    1.00
    cross-entropy (bits)
    2.0
    perplexity
    ~2-way guess
    reads as
    cross-entropy = −log₂ P(token)   ·   perplexity = 2^cross-entropy
    P(correct token) →bitsrare surprises are expensiveconfident + right is nearly free
    What perplexity is good for — and what it is not
    Perplexity is the right tool for pretraining diagnostics, for detecting whether a text is in-distribution for a model, and for spotting data contamination (suspiciously low perplexity on a benchmark you are about to report). It is the wrong tool for evaluating an application: a model can be beautifully unsurprised by text that is fluent, confident and wrong.

    Key insight

    Perplexity 1 means total certainty; perplexity equal to the vocabulary size means the model learned nothing. Everything useful happens in between — and none of it tells you whether the answer was true.

    What is this metric measuring?

    Sort

    Sort each metric by what it compares.

    Tap a piece, then tap where it goes — or drag it. Tap the tray to take one back.

    Token overlap with a reference

    Drop items here

    Meaning, via embeddings

    Drop items here

    The model’s own confidence

    Drop items here
    6 pieces left to place

    Test your knowledge

    20 questions
    Question 1 of 20
    Score: 0

    Perplexity is defined as:

    The short version

    Marking an essay by counting how many of the model answer's words appear in it. It works surprisingly often, fails completely on a good paraphrase, and fails silently — and dangerously — on an answer that says the exact opposite in the same vocabulary.

    In more depth

    Evaluation Metrics: Perplexity & Similarity

    Two families of reference-based metric.

    Language-modelling metrics

    Cross-entropy = −log₂ P(token): how surprised the model is by the text.
    Perplexity = 2^cross-entropy: the effective number of equally-likely options.

    Useful for pretraining diagnostics, in-distribution detection and contamination hunting. Useless for application quality — a model can be beautifully unsurprised by text that is fluent, confident and wrong. Not comparable across different tokenizers.

    Similarity metrics

    1.Exact match — 1 if the strings match after normalisation. The right metric whenever the task has one answer.
    2.Lexical similarity (BLEU, ROUGE, edit distance) — n-gram overlap. False-negative prone on paraphrase; false-positive prone on negation and numbers.
    3.Semantic similarity (embedding cosine, BERTScore) — survives rewording, and is nearly blind to negation because a sentence and its opposite sit close together in embedding space.

    Choosing

    Pick from the shape of the task, not the shape of the output. Classification → exact match. Code → run the tests. Retrieval → Recall@k / nDCG. Open-ended → a calibrated judge. Anything factual → field-level checks, never similarity.

    Report more than one, and treat divergence between metrics as the alarm.

    Interview Questions

    OpenAI
    Google
    Meta
    Google
    Amazon
    Microsoft
    Anthropic
    Meta
    Netflix
    OpenAI
    Google
    Anthropic

    Love this visualization?

    Sign up to track your progress, earn achievements, use the AI assistant, and access your personal learning dashboard.

    100% free • No credit card required