10 Kitty Scent Trails
Embeddings, Word2Vec, and High-Dimensional Spaces
🐾 Evergreen Chapter: Core mathematics and theory do not expire. Last verified: 2026-02-24
Prerequisites: Chapter 8 & 9 Technical Keywords: Tokenization, BPE, SentencePiece, Embeddings, Word2Vec, High-Dimensional Space, Semantic Similarity, Cosine Similarity, Dense Vectors, Sparse Vectors (One-Hot Encoding)
In Chapter 9, Pixel learned how to look at a grid of pixels and recognize a picture of a “Dog.”
But what if we don’t have a picture? What if the human just says the word “Dog”? Or “Puppy”? Or “Car”?
To us, “Dog” and “Puppy” are incredibly similar concepts. “Dog” and “Car” are completely different. But to a computer, these are just letters. The computer has no idea that a “Puppy” is just a small “Dog.” It has no idea that “King” is related to “Queen,” or that “Meow” is related to “Cat.”
How do we teach a mathematical brain what a word means?
We can’t just feed the word “Dog” into a neural network. Neural networks only eat numbers. We need a way to translate every concept in the universe—every word, every user profile, every song on Spotify—into a geometry that the math can understand.
We need Embeddings.
10.1 Tokenization: Slicing the Treats
Before we map words to numbers, we have an annoying problem. Is “Dog” the same word as “Dogs”? Is “un-believable” one word or three distinct ideas (“un”, “believe”, “able”)? If a user types “asdfghjkl”, does our network need a number for that whole string?
We solve this using Tokenization (specifically algorithms like BPE - Byte-Pair Encoding or SentencePiece).
Tokenization mathematically chops textual input into the most efficient sub-word chunks (Tokens). “Unbelievable” might be chopped into three tokens: [Un], [believ], [able]. Each of these tokens is given a unique integer ID from our vocabulary dictionary.
By slicing the treats into sub-words before giving them to the kitten, we can represent infinite human language using a small, finite vocabulary of maybe 50,000 token pieces!
10.2 The Naive Approach: One-Hot Encoding (The Giant, Empty Room)
Let’s say Pixel has a vocabulary of exactly 4 words: [Cat, Dog, puppy, Car].
The simplest way to turn these words into numbers is One-Hot Encoding. We create a vector (a list of numbers) that is exactly as long as our vocabulary (4). We put a 1 in the slot for the word we want, and 0s everywhere else.
- Cat =
[1, 0, 0, 0] - Dog =
[0, 1, 0, 0] - puppy =
[0, 0, 1, 0] - Car =
[0, 0, 0, 1]
This works mathematically, but it has two massive, catastrophic flaws:
1. The Vocabulary Problem: If Pixel learns 100,000 English words, every single word becomes a vector of 100,000 numbers. 99,999 of those numbers are zero. This is called a Sparse Vector. It wastes an unbelievable amount of memory.
2. The Meaning Problem: Remember the Dot Product from Chapter 1? It measures how similar two vectors are. If we take the dot product of Dog and puppy: [0, 1, 0, 0] · [0, 0, 1, 0] = (0*0) + (1*0) + (0*1) + (0*0) = 0.
The math says “Dog” and “puppy” have exactly zero similarity. They are completely orthogonal (perpendicular) in space. To the network, a puppy is just as different from a dog as a car is.
One-Hot Encoding contains absolutely zero meaning.
10.3 Embeddings: The Scent Trail of Meaning
Pixel doesn’t use massive, empty lists of zeros to understand the world. He uses scent.
Imagine Pixel walks into a room. He smells something. He doesn’t know the word “Dog,” but he can break the scent down into three fundamental properties (dimensions): 1. Fuzziness (0 to 1) 2. Loudness (0 to 1) 3. Speed (0 to 1)
If he smells a Dog, his brain might assign it the vector: [0.8, 0.9, 0.7] (Very fuzzy, very loud, pretty fast). If he smells a puppy: [0.9, 0.5, 0.9] (Extremely fuzzy, somewhat loud, very fast). If he smells a Car: [0.0, 1.0, 1.0] (Not fuzzy at all, extremely loud, extremely fast).
This is a Dense Vector. It is only 3 numbers long, but every single number is packed with meaning. This dense, meaningful vector is called an Embedding.
Now, let’s look at the math. Are Dog and puppy similar? Yes! Their numbers are very close together in our 3D space. Is Dog similar to Car? No! The “Fuzziness” dimension instantly pulls them far apart.
By compressing a massive, sparse vocabulary into a small, dense space (like 300 dimensions), we force the network to organize concepts by their actual meaning.
Analogy
One-Hot Encoding is giving every toy in the world its own perfectly isolated shelf in a massive warehouse. Embeddings are throwing all the toys into a small box, forcing the soft toys to clump together in one corner, and the hard toys to clump in the other.

Rosetta Stone
| Kitten World | Math/Concept | Python (PyTorch) |
|---|---|---|
| “The empty warehouse shelf” | Sparse One-Hot Vector | F.one_hot(tensor([1]), num_classes=4) |
| “The dense scent profile” | Embedding Matrix (E \in \mathbb{R}^{V \times d}) | nn.Embedding(num_embeddings=100_000, embedding_dim=300) |
| “Look up the scent of ‘Dog’” | e = E^T x_{\text{one\_hot}} | embed_layer(tensor([1])) |
10.4 Word2Vec: You Are Known by the Company You Keep
How do we actually find these magical embedding vectors? We don’t have humans sit around grading words on “Fuzziness” and “Loudness.” We let the AI figure it out on its own.
In 2013, researchers created Word2Vec (Mikolov et al., 2013). It relies on a famous linguistic theory: You shall know a word by the company it keeps.
If I say to you: “The fluffy ____ barked at the mailman.” You instantly know the missing word is “Dog” (or a very similar word, like “puppy” or “Hound”).
Word2Vec trains a tiny neural network to play exactly this fill-in-the-blank game on massive text corpora—such as the Google News corpus (~6 billion tokens in Mikolov et al., 2013).
The network’s only job is to look at a word and predict the words immediately surrounding it (or vice-versa).
To win the game, the network must assign similar mathematical vectors to words that appear in the same contexts. Because “Dog” and “puppy” both appear after “fluffy” and before “barked,” the optimization engine physically pushes their vectors together in the 300-dimensional space.
The hidden layer weights of this tiny network become the Embeddings.
10.5 The Magic of Vector Math: King - Man + Woman = Queen
Because Embeddings are just geometry (Chapter 1), we can do math on concepts.
When researchers mapped the Word2Vec embeddings into a 300-dimensional space, they discovered something mind-blowing. The physical distance and direction (the vector) between “Man” and “Woman” was almost perfectly parallel to the vector between “King” and “Queen”, and “Uncle” and “Aunt”.
The network had organically discovered the concept of “Gender” and encoded it as a physical direction in space!
You can literally write the equation: \vec{v}_{\text{King}} - \vec{v}_{\text{Man}} + \vec{v}_{\text{Woman}} \approx \vec{v}_{\text{Queen}}
You can do this with capitals (Paris - France + Italy = Rome), with plurals (Cats - Cat + Dog = Dogs), and with concepts. The geometry is the meaning.
10.6 Cosine Similarity: Measuring the Scent
If we have two word vectors, how do we mathematically measure how similar they are?
We could measure the direct straight-line distance between them (Euclidean distance). But in high-dimensional space (300D), distance gets weird. Sometimes a word is mentioned very rarely, so its vector is very short, but it points in the exact same direction as a common word.
Instead, we use Cosine Similarity. We imagine drawing an arrow from the origin (0,0,0) to the first word, and an arrow to the second word. We measure the angle between the two arrows.
- If the angle is 0^\circ, Cosine = 1.0. (The vectors point in the exact same direction. Identical meaning).
- If the angle is 90^\circ, Cosine = 0.0. (The vectors are orthogonal. No relation, like Dog and Car).
- If the angle is 180^\circ, Cosine = -1.0. (The vectors point in opposite directions. Antonyms, like Hot and Cold).
\text{Cosine Similarity} = \frac{\vec{A} \cdot \vec{B}}{\|\vec{A}\| \|\vec{B}\|} (Look closely! This is just the Dot Product from Chapter 1, divided by the lengths of the vectors).
10.7 Everything is an Embedding
Embeddings don’t just work for words. They are the universal translator for Modern AI.
- Spotify creates embeddings for songs. If the vector for “Bohemian Rhapsody” is close to the vector for “Stairway to Heaven,” the recommendation algorithm plays it next.
- Netflix creates embeddings for users. If your 300-number profile is close to my profile, Netflix recommends the movies I watched to you.
- Computer Vision (CLIP) maps images and text into the exact same embedding space. It forces the vector for the picture of a dog to be physically close to the vector for the word “Dog”. This is how image-generators like Midjourney understand your prompts!
10.8 Removing the Training Wheels
The Real Engineering
We talked about scent trails and word math. In the real world, an Embedding is a lookup table mapping discrete token IDs to dense floating-point vectors in high-dimensional space. Word2Vec optimizes these vectors via negative sampling or hierarchical softmax. Semantic similarity is commonly approximated via Cosine Similarity—the dot product of two normalized vectors (a useful geometric proxy, not literal human meaning). If your embeddings are biased, your downstream RAG application or classification model will mathematically encode and amplify human prejudice.
10.9 Paws and Reflect: Chapter Quiz
Work through these conceptually before checking the answers.
You are using One-Hot Encoding for a vocabulary of 10,000 words. What is the cosine similarity between the vector for “Happy” and the vector for “Joy”?
Why are Dense Embeddings better for neural networks than Sparse One-Hot vectors? (Give two reasons relating to memory and meaning).
In Word2Vec, how does the AI figure out that “Run” and “Sprint” have similar meanings, even though the human never provided a dictionary definition?
You calculate the Cosine Similarity between “Kitten” and “Machine Learning” and get a score of
0.01. What does this mean geometrically, and what does it mean conceptually?
Reveal answers
- Exactly 0.0. In One-Hot Encoding, every single word is perpendicular to every other word. The math is completely blind to semantic similarity.
- Efficiency: An embedding lookup table avoids constructing massive explicit 10,000-element one-hot vectors and eliminates unnecessary sparse matrix multiplication compute (though the V \times d embedding table still stores the same number of parameters as a dense first layer from one-hot inputs). Representation: Distances and directions between dense vectors capture distributional similarity from the training data.
- Because “Run” and “Sprint” show up in the exact same contexts in sentences (e.g., “I had to ___ to catch the bus”). The network is forced to push their vectors together to win the word-prediction game.
- Geometrically, the two vectors are nearly perpendicular (\arccos(0.01) \approx 89.43^\circ; an exact 90^\circ orthogonal angle gives
0.0). Conceptually, it indicates very weak distributional similarity in this embedding space—a geometric proxy for shared training context, not literal human understanding of meaning.
10.10 Chapter 10 Summary
You’ve learned the universal translator of AI:
- One-Hot Encoding: The naive way to represent words as massive, empty, meaningless vectors.
- Embeddings: Compressing concepts into dense, rich, high-dimensional spaces where geometry equals meaning.
- Word2Vec: The algorithm that learns meaning purely by looking at which words hang out together in sentences.
- Vector Math: The magical ability to add and subtract concepts (
King - Man + Woman = Queen). - Cosine Similarity: Measuring the angle between two vectors to determine how closely related they are.
Pixel can see (CNNs). He understands concepts (Embeddings).
But what happens when the human speaks a whole sentence? “Pixel, do not jump on the counter, or you will get no treats.”
Pixel needs to read the words in order. He needs to remember the “not” at the beginning of the sentence when he hears “treats” at the end. He needs a memory that spans across time.
It is time to build Recurrent Neural Networks and the Attention Mechanism. 🐈🧠🕰️
AI Safety Thread: Chapter 10
Embedded Bias: Because embeddings learn from human text (like Reddit or Wikipedia), they mathematically absorb all human prejudices.
When researchers tested the famous Word2Vec embeddings, they found that Doctor - Man + Woman resulted in a vector extremely close to Nurse. Computer Programmer - Man + Woman resulted in Homemaker. The geometry literally encoded sexism. If you use these embeddings to build an AI resume-screening tool for a tech company, the algorithm will quietly, mathematically down-rank female applicants, because they are further away from the “Programmer” vector. You cannot “clean” an embedding easily. The bias is woven into the very fabric of the high-dimensional space.