LearnPath

python · intermediate · ~6h

Mini tokenizer

Implement a character-level tokenizer first, then merge the most frequent adjacent pairs a few times. Encode and decode must round-trip on the training text.

Requirements

Skills: Transformers & LLMs · Lists, dicts, sets

Starter

tokenizer.py

python editor · loading…

python · sandboxed in your browser

Output

Run to see output.

Hints
  • Start with bytes/characters. Merges are optional extra credit.