Skip to content

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 characters

Training 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 words
1.50
Characters per token
235
Tokens
352
Characters
54
Vocabulary

24 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 learned
Last applieds + t st
Next up▁co + mmon ▁common · seen 3 times
Every merge this text supports, in learned order, with the pair merged, the symbol it produced, and how often the pair occurred at the moment it was chosen.
#PairNew symbolOccurrencesState
1m + omo8applied
2e + nen7applied
3 + w▁w7applied
4 + a▁a7applied
5c + oco7applied
6 + s▁s7applied
7r + ere6applied
8 + t▁t6applied
9h + ehe5applied
10 + co▁co5applied
11m + mommo5applied
12mmo + nmmon5applied
13▁w + o▁wo4applied
14▁wo + r▁wor4applied
15▁wor + d▁word4applied
16▁word + s▁words4applied
17 + p▁p4applied
18 + o▁o4applied
19 + T▁T3applied
20 + n▁n3applied
21c + ece3applied
22▁t + he▁the3applied
23 + mo▁mo3applied
24s + tst3applied
25▁co + mmon▁common3not yet
26o + lol3not yet
27▁w + h▁wh3not yet
28o + kok2not yet
29ok + enoken2not yet
30e + rer2not yet
31 + re▁re2not yet
32▁re + a▁rea2not yet
33▁rea + d▁read2not yet
34▁T + he▁The2not yet
35▁p + i▁pi2not yet
36▁pi + e▁pie2not yet
37▁pie + ce▁piece2not yet
38▁piece + s▁pieces2not yet
39▁o + f▁of2not yet
40▁a + n▁an2not yet
41▁an + d▁and2not yet
42▁a + re▁are2not yet
43c + hch2not yet
44 + b▁b2not yet
45u + nun2not yet
46un + tunt2not yet
47unt + iunti2not yet
48▁mo + st▁most2not yet
49▁p + a▁pa2not yet
50▁pa + i▁pai2not yet
51▁pai + r▁pair2not yet
52▁s + y▁sy2not yet
53▁sy + m▁sym2not yet
54▁sym + b▁symb2not yet
55▁symb + ol▁symbol2not yet
56m + eme2not yet
57▁o + n▁on2not yet
58▁t + h▁th2not yet
59u + lul2not yet
60 + i▁i2not yet
61▁i + s▁is2not yet
62en + tent2not yet

Resulting tokens

marks a word boundary
  1. ▁T
  2. o
  3. k
  4. en
  5. i
  6. z
  7. e
  8. r
  9. s
  10. d
  11. o
  12. ▁n
  13. o
  14. t
  15. re
  16. a
  17. d
  18. ▁words
  19. .
  20. ▁T
  21. he
  22. y
  23. re
  24. a
  25. d
  26. ▁p
  27. i
  28. e
  29. ce
  30. s
  31. ▁o
  32. f
  33. ▁words
  34. ,
  35. ▁a
  36. n
  37. d
  38. ▁the
  39. ▁p
  40. i
  41. e
  42. ce
  43. s
  44. ▁a
  45. re
  46. c
  47. h
  48. o
  49. s
  50. en
  51. b
  52. y
  53. ▁co
  54. u
  55. n
  56. t
  57. i
  58. n
  59. g
  60. .
  61. ▁T
  62. he
  63. ▁mo
  64. st
  65. ▁co
  66. mmon
  67. ▁p
  68. a
  69. i
  70. r
  71. ▁o
  72. f
  73. ▁s
  74. y
  75. m
  76. b
  77. o
  78. l
  79. s
  80. b
  81. e
  82. co
  83. m
  84. e
  85. s
  86. ▁o
  87. n
  88. e
  89. ▁s
  90. y
  91. m
  92. b
  93. o
  94. l
  95. ,
  96. ▁t
  97. h
  98. en
  99. ▁the
  100. ▁n
  101. e
  102. x
  103. t
  104. ▁mo
  105. st
  106. ▁co
  107. mmon
  108. ▁p
  109. a
  110. i
  111. r
  112. ,
  113. ▁a
  114. n
  115. d
  116. ▁s
  117. o
  118. ▁o
  119. n
  120. u
  121. n
  122. t
  123. i
  124. l
  125. ▁the
  126. v
  127. o
  128. c
  129. a
  130. b
  131. u
  132. l
  133. a
  134. r
  135. y
  136. i
  137. s
  138. f
  139. u
  140. l
  141. l
  142. .
  143. C
  144. o
  145. mmon
  146. ▁words
  147. ▁s
  148. u
  149. r
  150. v
  151. i
  152. v
  153. e
  154. ▁w
  155. h
  156. o
  157. l
  158. e
  159. .
  160. U
  161. n
  162. co
  163. mmon
  164. ▁words
  165. ▁a
  166. re
  167. ▁s
  168. p
  169. en
  170. t
  171. ▁a
  172. s
  173. ▁s
  174. e
  175. v
  176. e
  177. r
  178. a
  179. l
  180. ▁t
  181. o
  182. k
  183. en
  184. s
  185. ,
  186. ▁w
  187. h
  188. i
  189. c
  190. h
  191. i
  192. s
  193. ▁w
  194. h
  195. y
  196. ▁a
  197. r
  198. a
  199. re
  200. ▁n
  201. a
  202. m
  203. e
  204. ▁co
  205. st
  206. s
  207. ▁mo
  208. re
  209. ▁t
  210. h
  211. a
  212. n
  213. ▁a
  214. ▁co
  215. mmon
  216. ▁s
  217. en
  218. t
  219. en
  220. ce
  221. .

Everything on this page runs in your browser. Nothing you type is sent anywhere, there is no account, and it keeps working offline.