Originally published on almoghagbi.com , where the figures are interactive.
By the end of this post, you'll be able to compute the probability of a
sentence from a handful of counts, and predict the next word the way your
phone's keyboard does. A language model is the part of natural language
processing (NLP) that does this: it gives a probability to each word that could
come next. Section 3.1 of
Speech and Language Processing
starts with the simplest kind, the n-gram model. Its trick: look only at the
last word or two, count, and divide.
Intuition
A language model scores what comes next
Type "i want a" on your phone and it suggests a few next words. A speech
recognizer that hears "I scream" or "ice cream" picks the one people say more
often in that spot.…