Originally published on almoghagbi.com , where the figures are interactive.
By the end of this post, you'll be able to grade a language model the way
researchers do: hold out text the model has never seen, compute its
perplexity by hand, and say what the number means. In natural language
processing (NLP), perplexity is the standard score for language models. It
works for the n-gram models of the last lesson
and for today's large language models. Sections 3.2 and 3.3 of
Speech and Language Processing
introduce it.
Intuition
Never grade a model on its own homework
Last time we counted bigrams in four café orders:
i want a coffee\
i want a cake\
you want coffee\
i like cake
Here's a puzzle. A second model memorizes these four lines and gives each one
probability 1/4. Our bigram model gave "i want a coffee" only 1/6. Is the
memorizer the better model?…