Tokenisation
Splits text into the pieces (words or sub-words) a model works with.
The idea
Models cannot read raw characters efficiently, so text is cut into tokens. Word tokenisers split on spaces and punctuation, but they cannot handle unseen words. Sub-word methods such as Byte-Pair Encoding repeatedly merge the most frequent pair of symbols, so common words become one token and rare words are built from pieces.
Watch it run
This is a real computation, not a drawing. Pause, step, change the settings, or try new random data.
- single character
- merged token
Byte-pair encoding builds a vocabulary by repeatedly merging the most common neighbouring pair of symbols. Training words (with counts): low×5, lower×2, newest×6, widest×3. "_" marks the end of a word.
This is the algorithm behind the tokenisers of most modern language models.
Step by step
- 1Normalise the text (case, Unicode).
- 2Start with characters as the vocabulary.
- 3Count adjacent pairs and merge the most frequent pair into a new symbol.
- 4Repeat until the vocabulary reaches the wanted size.
- 5Encode new text by applying the learnt merges.
Where it is used
Every language model, search index and spell checker.
Watch out for
Different tokenisers split the same text differently, which affects cost and quality, particularly for non-English languages.