The Tokenizer is a necessary and pervasive component of Large Language Models (LLMs), where it translates between strings and tokens (text chunks). Tokenizers are a completely separate stage of the LLM pipeline: they have their own training sets, training algorithms (Byte Pair Encoding), and after training implement two fundamental functions: encode() from strings to tokens, and decode() back from tokens to strings. In this lecture we build from scratch the Tokenizer used in the GPT series from OpenAI. In the process, we will see that a lot of weird behaviors and problems of LLMs actually trace back to tokenization. We’ll go through a number of these issues, discuss why tokenization is at fault, and why someone out there ideally finds a way to delete this stage entirely.
Chapters:
00:00:00 intro: Tokenization, GPT-2 paper, tokenization-related issues
00:05:50 tokenization by example in a Web UI (tiktokenizer)
00:14:56 strings in Python, Unicode code points
00:18:15 Unicode byte encodings, ASCII, UTF-8, UTF-16, UTF-32
00:22:47 daydreaming: deleting tokenization
00:23:50 Byte Pair Encoding (BPE) algorithm walkthrough
00:27:02 starting the implementation
00:28:35 counting consecutive pairs, finding most common pair
00:30:36 merging the most common pair
00:34:58 training the tokenizer: adding the while loop, compression ratio
00:39:20 tokenizer/LLM diagram: it is a completely separate stage
00:42:47 decoding tokens to strings
00:48:21 encoding strings to tokens
00:57:36 regex patterns to force splits across categories
01:11:38 tiktoken library intro, differences between GPT-2/GPT-4 regex
01:14:59 GPT-2 released by OpenAI walkthrough
01:18:26 special tokens, tiktoken handling of, GPT-2/GPT-4 differences
01:25:28 minbpe exercise time! write your own GPT-4 tokenizer
01:28:42 sentencepiece library intro, used to train Llama 2 vocabulary
01:43:27 how to set vocabulary set? revisiting transformer
01:48:11 training new tokens, example of prompt compression
01:49:58 multimodal [image, video, audio] tokenization with vector quantization
01:51:41 revisiting and explaining the quirks of LLM tokenization
02:10:20 final recommendations
02:12:50 ??? :)
Exercises:
- Advised flow: reference this document and try to implement the steps before I give away the partial solutions in the video. The full solutions if you’re getting stuck are in the minbpe code
Links:
- Google colab for the video:
- GitHub repo for the video: minBPE
Supplementary links:
- tiktokenizer
- tiktoken from OpenAI:
- sentencepiece from Google
1 view
3689
1467
10 minutes ago 00:01:53 1
Новости 2004 07 08 №8
11 minutes ago 00:03:51 1
YOUNG POSSE (영파씨) ’ATE THAT’ MV
12 minutes ago 00:01:11 1
✔ КУРСЫ C ОНЛАЙН БЕСПЛАТНО ✔ ШКОЛА ПРОГРАММИСТА 💣
29 minutes ago 00:25:55 1
Научное подтверждение реинкарнации
32 minutes ago 00:18:15 1
Женщины доказали мэру Сыктывкара, что ЖКХ оплачено из бюджета Мэр признался!
37 minutes ago 01:18:04 1
«Я мечтаю, чтобы это произошло, но не думаю, что это произойдет». Познер о ТВ, пропаганде и страхах
38 minutes ago 00:03:16 1
Семинар «Твое Изобилие и Благосостояние»
40 minutes ago 00:18:51 1
ЦЕНЫ на НЕФТЬ РУХНУТ?! Запад ЗАСТАВИТ ОПЕК Увеличить Добычу Нефти
50 minutes ago 00:33:12 1
ТАК МЫСЛЯТ ПСИХОПАТЫ И НАРЦИССЫ! КАК ПОНЯТЬ ЧТО РЯДОМ С ТОБОЙ ПСИХОПАТ? ПРИЗНАКИ НАРЦИССИЗМА
60 minutes ago 00:22:10 1
Постановление Правительства №1710 Оплата ЖКХ
1 hour ago 00:01:11 3
Заработок на ставках на спорт отзывы ⛔ Виды ставок на киберспорт ☑
1 hour ago 00:26:47 1
Налоги отменены ст 12 п 5 Как больше не платить НАЛОГИ!
1 hour ago 00:01:03 1
😲 Заработать деньги за просмотр рекламы без вложений 👍 Идей для самозанятых 🎯
1 hour ago 00:08:07 1
Костя Питерский он же Череп как сложилась судьба самого известного героя первой Чеченской Войны
1 hour ago 00:07:25 1
Би-2 — Колыбельная (2022)
1 hour ago 00:01:11 1
🚫 Самообучение на программиста
2 hours ago 00:25:51 1
Мартин Ллойд Джонс – Определённый грех [ЦЕРКОВЬ БЕЗ СТЕН]
2 hours ago 00:00:14 1
Колымчан приглашают участвовать в конкурсе «Дальний Восток – Земля приключений» (6+)
2 hours ago 00:12:02 1
КОНОПЛЯ - КТО И ЗАЧЕМ ЕЁ ЗАПРЕТИЛ И ОБОЛГАЛ ? 7 причин выращивать техническую коноплю
2 hours ago 02:42:39 1
Как ИЗ РУИН появились автомобили, изменившие мир.
2 hours ago 01:55:26 1
Deep Emotions 2024 | Deep House • Nu Disco • Chill House Mix #5
2 hours ago 00:08:51 1
Лечим хроническую боль в спине: полезные упражнения от доктора Бубновского
3 hours ago 00:03:22 1
Samsung Galaxy S25 Ultra - NEVER BEFORE SEEN UPGRADES!
3 hours ago 00:03:30 1
Samsung Galaxy S25 Ultra Desert Gold - Finally, The Wait is OVER!