Skip to content

Build a modern LLM from scratch. Every line commented. Explained like we are five.

add description to notebook

raiyanyahyadd65c63cf01b
diff --git a/notebooks/02_tokenization.ipynb b/notebooks/02_tokenization.ipynb
index df97c0c..410d996 100644
--- a/notebooks/02_tokenization.ipynb
+++ b/notebooks/02_tokenization.ipynb
@@ -7,7 +7,17 @@
"source": [
"# Chapter 2 — Tokenization\n",
"\n",
- "Turning words into numbers using Byte Pair Encoding (BPE)."
+ "Computers don't understand letters. They only understand numbers.\n",
+ "So before we can train a language model we need to turn every word\n",
+ "and every punctuation mark into a number. This process is called\n",
+ "tokenization and it is the first step in every modern LLM.\n",
+ "\n",
+ "In this notebook we will use the same tokenizer that GPT-2 uses.\n",
+ "It breaks words into small pieces called subwords so even rare\n",
+ "words and emojis can be handled gracefully. We will see how\n",
+ "\"unbelievably\" becomes three tokens and how emojis don't break\n",
+ "anything. By the end you will understand how text becomes the\n",
+ "raw input for a transformer model."
]
},
{
@@ -20,7 +30,7 @@
},
{
"cell_type": "code",
- "execution_count": 6,
+ "execution_count": 1,
"id": "1efdf6ed",
"metadata": {},
"outputs": [],
@@ -39,7 +49,7 @@
},
{
"cell_type": "code",
- "execution_count": 7,
+ "execution_count": 2,
"id": "da490ead",
"metadata": {},
"outputs": [],
@@ -60,7 +70,7 @@
},
{
"cell_type": "code",
- "execution_count": 8,
+ "execution_count": 3,
"id": "95364f63",
"metadata": {},
"outputs": [],
@@ -95,7 +105,7 @@
},
{
"cell_type": "code",
- "execution_count": 9,
+ "execution_count": 4,
"id": "13322dca",
"metadata": {},
"outputs": [
@@ -139,7 +149,7 @@
},
{
"cell_type": "code",
- "execution_count": 10,
+ "execution_count": 5,
"id": "e7f0ffda",
"metadata": {},
"outputs": [
@@ -150,7 +160,9 @@
"Pieces: ['ant', 'idis', 'establishment', 'arian', 'ism']\n",
"Decoded: 'antidisestablishmentarianism'\n",
"\n",
- "Emoji test: Hello world!\n"
+ "Decoded: Hello world!\n",
+ "\n",
+ "Emoji test: Hello 😊 world\n"
]
}
],
@@ -161,11 +173,11 @@
"print(f\"Decoded: '{tokenizer.decode(rare)}'\")\n",
"print()\n",
"\n",
-"text = tokenizer.encode(\"Hello world!\")\n",
-"print(f\"Decoded: {tokenizer.decode(text)}\")\n",
-"print()\n",
-"emoji = tokenizer.encode(\"Hello \\U0001f60a world\")\n",
-"print(f\"Emoji test: {tokenizer.decode(emoji)}\")"
+ "text = tokenizer.encode(\"Hello world!\")\n",
+ "print(f\"Decoded: {tokenizer.decode(text)}\")\n",
+ "print()\n",
+ "emoji = tokenizer.encode(\"Hello \\U0001f60a world\")\n",
+ "print(f\"Emoji test: {tokenizer.decode(emoji)}\")"
]
},
{