ai.page · learn

Embeddings

How a model turns each token into a list of numbers, so that related meanings end up close together.

Builds on: Tokenization

Explanation

A tokenizer turns text into token ids: just numbers in a list, like 403 or 34711. The id says nothing about meaning; 403 isn't "closer" to 404 in any useful way. So the first thing a language model does with each id is look up its embedding: a list of numbers, a vector, that stands for that token.

token "cat"  → id 9246 → [0.12, -0.83, 0.40, …]   (hundreds or thousands of numbers)

The vectors aren't chosen by hand. They start random and are learned during training, nudged a little at a time so the model predicts text better. Because tokens that appear in similar places in text get used in similar ways, their vectors end up pointing in similar directions: "cat" near "kitten" and "dog", far from "truck".

Measuring closeness: cosine similarity

Two vectors are compared by the angle between them, not their length. The cosine similarity is

cos⁡θ=a⋅b‖a‖‖b‖

where a⋅b multiplies the vectors number by number and adds the results, and ‖a‖ is a vector's length. It's 1 when they point the same way, 0 when they're at right angles, and −1 when they point opposite ways.

Many dimensions

Real embeddings have hundreds or thousands of numbers, not two. That's room for many kinds of relatedness at once: topic, grammar, tone. No single number means one human idea like "animal" or "royalty"; meanings are spread across many of them, which is why pictures of embeddings squash them down to 2D and lose a lot.

Where they're used

  • Inside every language model: embeddings are the model's first layer, and its later layers keep working with vectors like these.
  • Search by meaning: turn documents and a question into embeddings, then find the documents whose vectors are most similar, even when they share no words with the question.

@si / anthropic (says) / claude-opus 5.5 (says) / high (says) · 2026-10-14 · new, not checked yet · Markdown

See it

Which words point the same way?
Described

A 2D map with a few words placed as arrows from the centre. These positions are made up for illustration; real embeddings have hundreds of dimensions and are learned. Choose a word (with its button, or the arrow keys) and its arrow is highlighted, and every other word is listed with its cosine similarity to it, most similar first, as text. Animals point one way, vehicles another and fruit a third, so the closest words to "cat" are "kitten" and "dog", and "truck" is far off. You can also drag a word's point to move it, and the list updates.

@si / anthropic (says) / claude-opus 5.5 (says) / high (says) · 2026-10-14 · based on d12115873874 · new, not checked yet · Markdown

1 more: See it

beginner · visual

Which words point the same way?
Described

A 2D map with a few words placed as arrows from the centre. These positions are made up for illustration; real embeddings have hundreds of dimensions and are learned. Choose a word (with its button, or the arrow keys) and its arrow is highlighted, and every other word is listed with its cosine similarity to it, most similar first, as text. Animals point one way, vehicles another and fruit a third, so the closest words to "cat" are "kitten" and "dog", and "truck" is far off. You can also drag a word's point to move it, and the list updates.

@si / anthropic (says) / claude-opus 5.5 (says) / high (says) · 2026-10-14 · new, not checked yet · Markdown

Worked example

Three tiny vectors

Real embeddings are long, but the sums are the same in 2D. Compare A=(3,4), B=(4,3) and C=(−4,3) with cosine similarity.

  1. Step 1

    Lengths first: ‖A‖=32+42=5, and B and C are also length 5.

  2. Step 2

    A⋅B=3×4+4×3=24, so cos⁡=24/(5×5)=0.96: nearly the same direction, very similar.

  3. Step 3

    A⋅C=3×(−4)+4×3=0, so cos⁡=0: at right angles, unrelated.

  4. Step 4

    B⋅C=4×(−4)+3×3=−7, so cos⁡=−7/25=−0.28: pointing somewhat apart. Of the three, A and B are the closest pair.

@si / anthropic (says) / claude-opus 5.5 (says) / high (says) · 2026-10-14 · new, not checked yet · Markdown

Practice

What is a token's embedding?

Choose one

@si / anthropic (says) / claude-opus 5.5 (says) / high (says) · 2026-10-14 · new, not checked yet · Markdown

What is the cosine similarity of (1,0) and (0,1)?

Hint

Multiply number by number and add. What do you get?

@si / anthropic (says) / claude-opus 5.5 (says) / high (says) · 2026-10-14 · new, not checked yet · Markdown

Put what happens to text on its way into a language model in order.

Put these in order with the buttons.

  1. Look up the embedding vector for each id
  2. Cut the text into tokens
  3. Pass the vectors through the model's layers
  4. Look up each token's id

@si / anthropic (says) / claude-opus 5.5 (says) / high (says) · 2026-10-14 · new, not checked yet · Markdown

Fill the gaps.

Two vectors pointing the same way have cosine similarity . Two pointing in opposite directions have cosine similarity .

@si / anthropic (says) / claude-opus 5.5 (says) / high (says) · 2026-10-14 · new, not checked yet · Markdown

Check yourself

Which of these are true? Choose all that are.

Choose all that are right

@si / anthropic (says) / claude-opus 5.5 (says) / high (says) · 2026-10-14 · new, not checked yet · Markdown

What is the cosine similarity of (5,12) and (12,5)? Give it to two decimal places.

@si / anthropic (says) / claude-opus 5.5 (says) / high (says) · 2026-10-14 · new, not checked yet · Markdown

Common mistakes

The embedding is the token id

Both are numbers attached to a token, so they're easy to mix up. The id is one whole number that only says which row to look in, and nearby ids mean nothing. The embedding is the long list of numbers stored in that row, learned so that similar tokens point in similar directions.

Fix: id = which row; embedding = what's in the row.

@si / anthropic (says) / claude-opus 5.5 (says) / high (says) · 2026-10-14 · new, not checked yet · Markdown

Each number in an embedding means one idea

Popular explanations draw embeddings with labelled axes, like "animal" or "royalty", so it's natural to think each number has a meaning you could name. In real models, nobody chooses what the numbers mean; training spreads every kind of relatedness across many of them at once. Directions in the whole space can line up with ideas, but single numbers usually don't.

Fix: think of similarity between whole vectors (their angle), not the meaning of any one number.

@si / anthropic (says) / claude-opus 5.5 (says) / high (says) · 2026-10-14 · new, not checked yet · Markdown