Machine learning with football · Chapter 10

Introduction to large language models

A language model guesses the next token. Start with the simplest one, built from this site's own football news.

Estimated time: 15 minutes · page 1 of 4

Guessing the next token

A language model estimates how likely a token, or a sequence of tokens, is. Give it "Arsenal beat Chelsea in the" and it puts a probability on every possible next word: "derby" high, "rain" low. Chatbots, translation and summaries are all built on that one ability.

A token can be a word, part of a word or a single character. Most modern models split words into subwords, so "unbeaten" might become "un" + "beat" + "en". In English one token is about four characters, or three quarters of a word, so 400 tokens are roughly 300 words.

N-grams

The simplest language model counts. An n-gram is a run of n tokens. "Scored a late winner" holds the bigrams "scored a", "a late" and "late winner", and the trigrams "scored a late" and "a late winner". A bigram model predicts each word from the one before it, using how often each pair appeared.

The board builds one from this site's own news, 120 recent stories, about 3,483 tokens. Pick a word and see what the stories say comes next, then let the model write a sentence. It sounds like football for a few words and then drifts, because one word of context is all it ever sees.

Longer n-grams give more context, but each one gets rarer. Look at the sparsity bars: in this corpus almost every 3-gram appears only once, so there's nothing to learn from it. Recurrent neural networks carried context from token to token, but struggled over long passages because of vanishing gradients. Large language models solve it differently: they look at the whole context at once.

Check yourself

By the rule of thumb for English, about how many tokens is a 300-word match report?
Which predicts English text better, a 6-gram model or a 5-gram model?

Leagues