Loading...

Build your own Tokenizer

Learn about byte-pair encoding, UTF-8, and more

Start Building
C++
C++
Go
Go
Java
Java
Python
Python
Rust
Rust
TypeScript
TypeScript

Members get early access to this ALPHA challenge.

You can read the stage instructions for free. To start building, you'll need a membership.

Want to try a free challenge? Try Build your own Redis — it's free until 31 December 2026.

Why does GPT-2 split strawberry into three tokens, but keep strawberry as one?

Its tokenizer converts text into token IDs, the numbers the model receives. Its learned vocabulary includes the space-prefixed word as one token, while the unspaced word uses smaller pieces. You'll build a tokenizer that learns merge rules from text, encodes and decodes text, and loads GPT-2's vocabulary to match its IDs.

You'll learn how UTF-8 represents text as bytes, how byte-pair encoding learns merges, and why token boundaries depend on whitespace.

Stages

UTF-8 bytes
Login via GitHub to view this stage
Most frequent pair
Login via GitHub to view this stage
Merge a pair
Login via GitHub to view this stage
Learn merges
Login via GitHub to view this stage
Encode
Login via GitHub to view this stage
Decode
Login via GitHub to view this stage
Split like GPT-2
Login via GitHub to view this stage
Match GPT-2
Login via GitHub to view this stage