Inference EngineeringInteractive lab
Byte-pair tokenizer
Train BPE on your own text and watch the merges form
Paste any text and run real byte-pair encoding over it, one merge at a time. The merge table, the resulting tokens and the characters-per-token ratio all update as you turn the dial.
What this teaches
- Subword vocabularies
- Why token counts are not word counts
- Merge order
Training text
351 / 4,000 charactersTraining stops when the most frequent remaining pair occurs only once. A pair seen a single time is not a pattern, so this text supports 62 merges and no more.
What the merges bought
50 distinct words24 merges applied. 235 tokens over 352 characters, a ratio of 1.50 characters per token, from a vocabulary of 54 symbols.
Vocabulary is the 30 distinct characters this text starts with, plus one entry per merge. Characters counts the normalised stream, in which every run of whitespace has become a single ▁ boundary marker.
A production tokenizer trained on billions of characters gets English to roughly four characters per token. A few hundred characters cannot reach that, and the gap is the lesson: the ratio is a property of the corpus the vocabulary was trained on, not of the text you are counting. It is also why a bill quoted in tokens moves when you write in a language, or a codebase, the vocabulary never saw.
Merge table
in the order they were learneds + t → st▁co + mmon → ▁common · seen 3 times| # | Pair | New symbol | Occurrences | State |
|---|---|---|---|---|
| 1 | m + o | mo | 8 | applied |
| 2 | e + n | en | 7 | applied |
| 3 | ▁ + w | ▁w | 7 | applied |
| 4 | ▁ + a | ▁a | 7 | applied |
| 5 | c + o | co | 7 | applied |
| 6 | ▁ + s | ▁s | 7 | applied |
| 7 | r + e | re | 6 | applied |
| 8 | ▁ + t | ▁t | 6 | applied |
| 9 | h + e | he | 5 | applied |
| 10 | ▁ + co | ▁co | 5 | applied |
| 11 | m + mo | mmo | 5 | applied |
| 12 | mmo + n | mmon | 5 | applied |
| 13 | ▁w + o | ▁wo | 4 | applied |
| 14 | ▁wo + r | ▁wor | 4 | applied |
| 15 | ▁wor + d | ▁word | 4 | applied |
| 16 | ▁word + s | ▁words | 4 | applied |
| 17 | ▁ + p | ▁p | 4 | applied |
| 18 | ▁ + o | ▁o | 4 | applied |
| 19 | ▁ + T | ▁T | 3 | applied |
| 20 | ▁ + n | ▁n | 3 | applied |
| 21 | c + e | ce | 3 | applied |
| 22 | ▁t + he | ▁the | 3 | applied |
| 23 | ▁ + mo | ▁mo | 3 | applied |
| 24 | s + t | st | 3 | applied |
| 25 | ▁co + mmon | ▁common | 3 | not yet |
| 26 | o + l | ol | 3 | not yet |
| 27 | ▁w + h | ▁wh | 3 | not yet |
| 28 | o + k | ok | 2 | not yet |
| 29 | ok + en | oken | 2 | not yet |
| 30 | e + r | er | 2 | not yet |
| 31 | ▁ + re | ▁re | 2 | not yet |
| 32 | ▁re + a | ▁rea | 2 | not yet |
| 33 | ▁rea + d | ▁read | 2 | not yet |
| 34 | ▁T + he | ▁The | 2 | not yet |
| 35 | ▁p + i | ▁pi | 2 | not yet |
| 36 | ▁pi + e | ▁pie | 2 | not yet |
| 37 | ▁pie + ce | ▁piece | 2 | not yet |
| 38 | ▁piece + s | ▁pieces | 2 | not yet |
| 39 | ▁o + f | ▁of | 2 | not yet |
| 40 | ▁a + n | ▁an | 2 | not yet |
| 41 | ▁an + d | ▁and | 2 | not yet |
| 42 | ▁a + re | ▁are | 2 | not yet |
| 43 | c + h | ch | 2 | not yet |
| 44 | ▁ + b | ▁b | 2 | not yet |
| 45 | u + n | un | 2 | not yet |
| 46 | un + t | unt | 2 | not yet |
| 47 | unt + i | unti | 2 | not yet |
| 48 | ▁mo + st | ▁most | 2 | not yet |
| 49 | ▁p + a | ▁pa | 2 | not yet |
| 50 | ▁pa + i | ▁pai | 2 | not yet |
| 51 | ▁pai + r | ▁pair | 2 | not yet |
| 52 | ▁s + y | ▁sy | 2 | not yet |
| 53 | ▁sy + m | ▁sym | 2 | not yet |
| 54 | ▁sym + b | ▁symb | 2 | not yet |
| 55 | ▁symb + ol | ▁symbol | 2 | not yet |
| 56 | m + e | me | 2 | not yet |
| 57 | ▁o + n | ▁on | 2 | not yet |
| 58 | ▁t + h | ▁th | 2 | not yet |
| 59 | u + l | ul | 2 | not yet |
| 60 | ▁ + i | ▁i | 2 | not yet |
| 61 | ▁i + s | ▁is | 2 | not yet |
| 62 | en + t | ent | 2 | not yet |
Resulting tokens
▁ marks a word boundary- ▁T
- o
- k
- en
- i
- z
- e
- r
- s
- ▁
- d
- o
- ▁n
- o
- t
- ▁
- re
- a
- d
- ▁words
- .
- ▁T
- he
- y
- ▁
- re
- a
- d
- ▁p
- i
- e
- ce
- s
- ▁o
- f
- ▁words
- ,
- ▁a
- n
- d
- ▁the
- ▁p
- i
- e
- ce
- s
- ▁a
- re
- ▁
- c
- h
- o
- s
- en
- ▁
- b
- y
- ▁co
- u
- n
- t
- i
- n
- g
- .
- ▁T
- he
- ▁mo
- st
- ▁co
- mmon
- ▁p
- a
- i
- r
- ▁o
- f
- ▁s
- y
- m
- b
- o
- l
- s
- ▁
- b
- e
- co
- m
- e
- s
- ▁o
- n
- e
- ▁s
- y
- m
- b
- o
- l
- ,
- ▁t
- h
- en
- ▁the
- ▁n
- e
- x
- t
- ▁mo
- st
- ▁co
- mmon
- ▁p
- a
- i
- r
- ,
- ▁a
- n
- d
- ▁s
- o
- ▁o
- n
- ▁
- u
- n
- t
- i
- l
- ▁the
- ▁
- v
- o
- c
- a
- b
- u
- l
- a
- r
- y
- ▁
- i
- s
- ▁
- f
- u
- l
- l
- .
- ▁
- C
- o
- mmon
- ▁words
- ▁s
- u
- r
- v
- i
- v
- e
- ▁w
- h
- o
- l
- e
- .
- ▁
- U
- n
- co
- mmon
- ▁words
- ▁a
- re
- ▁s
- p
- en
- t
- ▁a
- s
- ▁s
- e
- v
- e
- r
- a
- l
- ▁t
- o
- k
- en
- s
- ,
- ▁w
- h
- i
- c
- h
- ▁
- i
- s
- ▁w
- h
- y
- ▁a
- ▁
- r
- a
- re
- ▁n
- a
- m
- e
- ▁co
- st
- s
- ▁mo
- re
- ▁t
- h
- a
- n
- ▁a
- ▁co
- mmon
- ▁s
- en
- t
- en
- ce
- .
Everything on this page runs in your browser. Nothing you type is sent anywhere, there is no account, and it keeps working offline.