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
50 views
4627
1728
10 years ago 00:32:04 106
Let`s #8 (допрыгался?)
12 years ago 00:46:53 154
let’s play по игре Трансформеры - Битва за Кибертрон Глава 8
11 years ago 00:34:39 18
Заправка - Let’s play на The sims 3 #8 - Схватка
10 years ago 00:25:21 1
Let`s Play Valiant Hearts #8 - Форт
10 years ago 01:08:14 0
Let’s Play #8
12 years ago 00:20:31 362
UNDERGROUND #8 [LET’S ROCK]
12 years ago 00:12:30 826
[Monster High Ghoul Spirit] #8 [let’s play] обзор с Мийком
12 years ago 00:25:42 27
Mundo Pocoyó (incluye Let’s Go Pocoyo!) - Episodio 8
6 years ago 02:59:43 1
TERA let’s play #8 PS4
11 years ago 00:29:39 493
Russian Let’s Play - Spartacus Legends #8 - Триумф Ролло
13 years ago 00:14:53 173
Tekkit SMP #8 - Let’s play with SkittleS
11 years ago 00:21:52 516
[Real GOT7 Season 2] episode 8. Let’s Play Pretend
5 years ago 00:09:24 77
Let’s learn to make Ocarinas video #8
6 years ago 02:27:52 0
Valkyria Chronicles Remastered let’s play #8 PS4
11 years ago 00:54:39 987
Let’s Play: Gothic Part 8
11 years ago 00:03:58 131
Let’s kick Moscow #8 2014
13 years ago 00:11:03 138
Let’s play Ib part 8: FINALE
1 year ago 00:57:10 0
ШТУРМУЕМ ОТЕЛЬ КАРАТ!!! (Contraband Police #8) | Let’s Play Lvov