Skip to content
StackDecode
AI & ML Atlas
Artificial IntelligencealgorithmInteractive simulation

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.

l o w _×5l o w e r _×2n e w e s t _×6w i d e s t _×3
  • 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.

1/13

This is the algorithm behind the tokenisers of most modern language models.

Step by step

  1. 1Normalise the text (case, Unicode).
  2. 2Start with characters as the vocabulary.
  3. 3Count adjacent pairs and merge the most frequent pair into a new symbol.
  4. 4Repeat until the vocabulary reaches the wanted size.
  5. 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.

Related