Muhammad Hanzla — independent alignment & safety researcher

Courses/Field Foundations/The Forward Pass/Embeddings

Field Foundations · Part 1 — The Forward Pass

Embeddings

Module 2 — where meaning enters the machine
includes a 2-min math sidebar (vectors) ~20–30 min read + your own notes Free · last updated
The one-sentence version: A token ID like 278 is just a name tag — it carries no meaning. An embedding turns that ID into a list of numbers that places the token at a point on a giant "map of meaning," where words with similar meanings sit close together. This is where meaning first enters the machine.

Section 0

Why we're here (the problem we're fixing)

End of Module 1, your text was a list of token IDs — one integer per brick. But those IDs are arbitrary: cat might be 9246 and dog might be 5011, and the fact that 9246 > 5011 means nothing — cats aren't "more" than dogs. The ID is a coat-check number: it points at the right brick, but it doesn't describe it.

That's a problem, because the model needs to compute with meaning — to feel that cat and dog are related and that cat and democracy aren't. Raw IDs can't give that. Embeddings fix exactly this.

By the end you'll be able to explain
what a vector is · what an embedding is (a table lookup) · how "meaning" lives in geometry · king − man + woman ≈ queen · where the numbers come from · and why we bolt on position.

Section 1

First, what's a vector?

Don't worry — this is the only math you need, and it's easy.

The whole trick
a list of numbers = a location. Hold that, and embeddings are easy.

Section 2

What an embedding actually is — a lookup table

An embedding is the vector that stands for a token. And getting it is dead simple: a table lookup. The model keeps one giant table — the embedding matrix — with one row per token. Each row is that token's vector:

"cat"9246→[ 0.21, -0.93, 0.44, 0.10, … ]
"dog"5011→[ 0.19, -0.88, 0.51, 0.07, … ]
"ing"278→[-0.62, 0.33, -0.05, 0.71, … ]
↑ notice cat & dog have similar vectors (both pets); "ing" looks nothing like them.

So the pipeline grows by one step:

"playing"→ playing→ 1991278→ [vec][vec]
text  →  tokens  →  token IDs  →  embeddings (Module 2)

The ID's only job was to say which row to grab. Once grabbed, the model holds a list of numbers that describes the token — not a bare name tag. Real models use vectors of a few hundred to a few thousand numbers per token.


Section 3

The big idea — meaning lives in geometry

Because every token is now a point in space, we can talk about tokens being near or far. The model arranges them so that:

The core rule
Tokens with similar meanings sit at nearby points. Tokens with unrelated meanings sit far apart.

Picture a giant map (really hundreds of dimensions, but let's draw it flat):

pets district
royalty district
cat
dog
kitten
puppy
king
queen
prince
banana
Analogy — the map of meaning
Every word is a pin on one enormous map. Related words are neighbors; unrelated words are across the city. "Distance on the map" = "difference in meaning." The model built this map during training so it could reason about words by their location, not their spelling.

Section 4

Directions mean things too — king − man + woman ≈ queen

This is the famous one. On the map, it's not just where a word is — the directions between words carry meaning. There's a direction that means "royalty" and one that means "gender." So you can do arithmetic on meaning:

king− man+ woman≈ queen
royal maleremove "male"add "female"royal female

Start at king. Walk the "remove male" direction, then the "add female" direction — and you land right next to queen. Nobody told the model "queen is the female king." It falls out of the geometry, because the map encoded "gender" and "royalty" as consistent directions.

“Meaning isn't stored as a definition. It's stored as a location — and the directions between locations are themselves meaningful.”

First shown dramatically by a 2013 model called word2vec (Mikolov et al. [1]). Modern LLM embeddings are richer and get refined by context later (that's attention, Module 3) — but this idea is the foundation underneath all of it.


Section 5

So where do the numbers come from?

Not from a human. The vectors are learned during training.

At the start, every token's vector is random — the map is pure noise, every word scattered nonsensically. Then, as the model trains on trillions of tokens (predicting the next token, over and over), training nudges the vectors (gradient descent). Words appearing in similar contexts get nudged together; words that don't drift apart. After enough training, the random scatter has organized into the meaningful map. Nobody designed the map — frequency and context built it, the same way BPE built the vocabulary in Module 1.

Key takeaway
The embedding matrix is part of the model's learned weights. It starts random and is shaped by training. "Learning the language" includes "learning where to put every word on the map."

Section 6

One more thing the model needs — position

A catch we must fix before Module 3. The embedding for dog is the same vector no matter where it appears. But order matters enormously:

dogbitesman vs manbitesdog
same three tokens · same three embeddings · opposite meaning

If all the model had were the word-vectors, these two sentences would look identical to it. Disaster. The fix: add a second piece of information to each embedding — its position. Token 1 gets a "position-1" signal, token 2 a "position-2" signal, and so on. This is positional encoding. So the real vector that enters the next stage is:

word-meaning vector  +  position vector  =  "this word, here."

Now dog-in-slot-1 and dog-in-slot-3 are distinguishable, and word order survives. (How the position signal is built has a few flavors you'll meet in papers — but the why is all you need here: order would otherwise be lost.)


Section 7

The handoff to Module 3

You now have, for every token, a rich vector saying what the word means and where it sits. A sentence is now a little row of meaningful points in space.

But each token's vector is still context-blind — bank has one vector whether you mean a river bank or a money bank. Module 3 (Attention) fixes that: it lets tokens look at each other and mix their vectors based on context, so bank next to river ends up meaning something different than bank next to money. That's where the sentence starts to understand itself.


🧠 Recap

The whole module in six lines
  1. A token ID is a meaningless name tag. An embedding turns it into a vector that describes the token.
  2. A vector = a list of numbers = a location in space (2 numbers → 2D point; 300 numbers → a point in 300D — same idea, unpicturable).
  3. An embedding is a table lookup: the embedding matrix has one row (one vector) per token; the ID says which row to grab.
  4. Meaning lives in geometry — similar words sit nearby (the map of meaning); and directions carry meaning (king − man + woman ≈ queen).
  5. The vectors are learned during training — start random, nudged into a meaningful map by frequency + context. The embedding matrix is part of the weights.
  6. We add position (positional encoding) so "dog bites man" ≠ "man bites dog."

✅ Now go and use it

Read it, write your own notes, then talk it through

Step 1 — talk it through. This copies a prompt with the whole module already inside it. Paste it into any AI assistant: it asks you questions one at a time, answers the ones you wrote down, and explains why a wrong answer was tempting. It will not test you.

Step 2 — only when you feel ready. The closed-book gate. It carries this module's own questions and tells the assistant to score you strictly and explain what you misunderstood. Write your own notes first — the notes are for encoding, not for shrinking the test, and the questions cover the whole module, not just what you wrote down.

Download the .md
a read b your own notes c discuss d scored check e on to Module 3

Any assistant works — Claude, ChatGPT, Gemini, an open-source model you run yourself. Free tiers are fine. You can dictate your answers instead of typing.

Sources

  1. Tomas Mikolov, Kai Chen, Greg Corrado, Jeffrey Dean, Efficient Estimation of Word Representations in Vector Space, 2013 — arXiv:1301.3781. The word2vec paper.
← back to the index Free · no account · no tracking