mb

bpe tokenizer

a language model reads tokens, not letters or words. byte-pair encoding learns them from a corpus: start with single letters, find the neighbouring pair that occurs most, glue it into one symbol everywhere, and repeat. the merges it learns, in order, are the tokenizer.

  • ×5low_
  • ×2lower_
  • ×2lowest_
  • ×6newer_
  • ×3wider_

boxes: each word's tokens right now. inked: what the last merge made. _ ends a word

neighbouring pairs, most frequent first

pairseen
e + r next11
r + _11
w + e10
l + o9
o + w9
n + e6
merges
0
vocab
11
tokens
100

11 letters and _, no merges yet

    • slower_
    • newest_

    ties go to the pair that appears first in the corpus. letters the corpus never had stay single, drawn dashed. new text is merged in the order the merges were learned.

    try this

    1. press play and let it run out. on a corpus this small the merges end up building whole words: low_, lower_, newer_.
    2. type slower in the bottom box. it was never in the corpus, yet it splits into s + lower_, pieces the merges did build.
    3. add newest three times to the corpus. the very first merge changes from e + r to w + e, and widest now splits as wide + st_.