What a Token Is

We can read the word cat, but a numerical model needs a representation it can process. A tokenizer divides text into pieces and maps those pieces to IDs, giving us a starting point for working with language.

14 sections · 14 questions · 4 coding challenges

1 / 14

How Did Text Become Something a Program Could Work With?

BOTIE

As humans, we recognise letters and words in the text we read. A program needs explicit rules for what to treat as one item. Even before modern language models, a compiler reading a program needed to distinguish a name, a number, and a punctuation symbol instead of treating the input as an undifferentiated stream of characters.

Tools such as Lesk and Schmidt's Lex, documented in 1975, let programmers describe patterns and turn matching character sequences into items for later processing. This is part of the computing history of tokens. Natural-language tokenizers inherited the need to define units, although their rules and goals differ from those of a programming-language lexer.

For a language model, we also associate each recognised piece with an ID. A piece such as cat can have a particular table entry, and the model can use that entry consistently. The ID gives the piece an address; it does not supply its meaning. Our next question is therefore which pieces to recognise, because choosing words, word parts, characters, or bytes creates different practical problems.

Sources for this history