Tokenization and Byte Pair Encoding
A language model never sees your letters, it sees tokens, chunks of text that fall between letters and words. Train a real BPE merge table on a small corpus, then watch your own text break into the pieces a model actually reads.
Tokenization and Byte Pair Encoding
Ask a model how many r's are in strawberry and it stumbles, because it never sees the letters. It sees tokens, chunks of text that usually land somewhere between a single letter and a whole word. Below, a merge table is trained on a short corpus the way real tokenizers learn theirs, then your text is broken into the exact pieces a model would read. Watch where the splits fall and where the letters disappear inside a chunk.
common words the corpus saw often collapse to one token each.
Each colored chunk is one token, with its vocabulary id below it. The id is what the model actually embeds: it never receives the characters, only this sequence of integers. Spaces show as · and a question mark means the piece is not in the trained vocabulary.
Here 15 tokens carry 4 words and 19 characters. Tokens sit between the two: rarer or longer words split into several, while words the corpus saw often stay whole.
lossless: joining the tokens back rebuilds your text exactly
Take strawberry. With the current merges it lands as these tokens:
The three r's are buried inside those chunks, never lined up as separate symbols. A model that only sees token ids has no direct view of the letters within a token, which is why counting characters or spelling backwards trips it up. The information is there in the bytes, just not in a form the model reads position by position.
Tokenizing starts from single characters and learns merges. More merges means a larger vocabulary and coarser tokens: common words fuse into one piece and the same text needs fewer tokens. Drag to add or remove merges and watch the chunks above grow.
Training scans the corpus, finds the most frequent adjacent pair, and merges it into a new token, then repeats. Early merges glue common letter pairs like t + h; soon after, th + e builds the word the. The underscore marks a word end. Step through and watch whole words emerge.
t+hth17xth+e_the_12xe+rer9xa+nan6xan+d_and_6xf+ofo5xe+r_er_5xa+s_as_5xb+erber5xber+rberr5xr+ara4xd+s_ds_4xr+e_re_4xi+t_it_4xberr+y_berry_4xm+omo3xt+ttt3xw+owo3xwo+rwor3xwor+ds_words_3xt+o_to_3xi+s_is_3xfo+x_fox_2xd+odo2xdo+g_dog_2xl+ele2xmo+dmod2xmod+emode2xmode+l_model_2xt+ete2xt+oto2xto+ktok2xtok+etoke2xtoke+ntoken2xtoken+s_tokens_2xtt+ertter2xtter+s_tters_2xc+oco2xco+mcom2xb+ebe2xi+nin2xa+re_are_2xs+psp2xs+msm2xsm+asma2xsma+lsmal2xi+eie2xo+f_of_2xi+n_in_2xth+atha2xtha+t_that_2xfo+r_for_2xth+erther2xw+awa2xThe merge table here is trained live on the corpus by counting adjacent pairs, not loaded from a file. Encoding replays those merges on your text, and joining the tokens back reproduces the input exactly, the same property a production tokenizer guarantees.