a hands-on course

Build a Tokenizer
From Scratch

(Byte Pair Encoding (BPE))

Build the byte-pair encoding tokenizer behind GPT — in pure Python, in about half an hour.

A free, hands-on tutorial: build a byte pair encoding (BPE) tokenizer from scratch in pure Python — the exact algorithm behind GPT and most modern LLMs. Train it to learn merges from text, then encode and decode, and see how words become tokens. Zero dependencies, runs entirely on your laptop.

in the real world

Every LLM reads text through a tokenizer like this one — it decides what a 'token' is, why you're billed per token, and why models sometimes stumble on spelling and rare words.

Start with the bytes →

Part 1 — Text is just numbers

Part 2 — Build BPE

Part 3 — Use it and scale up