Gradient
Lesson 8.2ModelCode~1 h 15 min

The bigram model

Count which letter follows which, then dream up new names. A language model in a table.

Module 8 · 0/8 done

A language model in a table

A language model predicts the next token from the ones before it: P(next∣previous)P(\text{next} \mid \text{previous}). The simplest possible version only looks at one previous token. Take ~600 first names, and for every letter, count which letter comes next. That table of counts is the model — a bigram model (bi = two: pairs of letters).

We add a special “.” token for the start and end of a name, so the model also learns how names begin and end.

Fig 8.2Every cell counts how often the column letter follows the row letter (darker = more). Click a row to see the next-letter probabilities. Then generate names by repeatedly sampling from the row of the letter you just produced.