MLCrack

    NATURAL LANGUAGE PROCESSING · INTERVIEW QUESTION

    What is perplexity and how is it used to evaluate language models?

    🟡 intermediate · Language Modeling

    Hint: Think about how 'surprised' the model is by the test data.

    Answer

    Perplexity measures how well a language model predicts a test set: PPL = exp(-1/N · Σ log P(wi∣w<i)P(w_i|w_{<i})). It represents the average number of equally likely choices the model is considering at each step. Lower perplexity = better model. A perplexity of 1 means perfect prediction; perplexity of V (vocabulary size) means random guessing. Usage:

    Interview reasoning

    1. Comparing language models on the same dataset.

    2. Monitoring training progress.

    3. GPT-3 achieved ~20 PPL on test sets.

    Limitations:

    1. Only measures next-token prediction, not generation quality
    2. Doesn't capture factuality or reasoning
    3. Not comparable across different tokenizers/vocabularies
    4. Doesn't correlate well with human preference scores.

    For LLM evaluation, downstream task performance and human eval are more meaningful than perplexity alone.

    Automatic generation metrics measure proxies with specific reference assumptions. Perplexity exponentiates average negative log probability over the model's tokenization; semantic metrics compare generated and reference meaning, while translation quality also needs adequacy and fluency checks. Scores are not interchangeable across tokenizers or evaluation tasks.

    Worked example. Average token negative log likelihood ln(4) gives perplexity 4; tokenization changes the units being averaged.

    Validation

    Use consistent tokenization and datasets, critical-entity tests, semantic and human assessment, and confidence intervals over independent examples.

    Common pitfalls

    Lower perplexity does not guarantee factuality or useful task behavior. One reference cannot represent every valid translation or summary.