Lesson 4

How does a model know "cat" and "dog" are alike?

What an embedding is, where its numbers come from, and how a computer measures whether two words are close in meaning.

1Does a token's number tell the model what a word means?

No. A token id is only a label. It tells the model which token it has, but nothing about what the token means.

How far is each id from the id of ␣cat?

    1. ␣cat9059
    The token we compare with.
    1. ␣kitten114502
    A baby cat. 114502 − 9059 = 105443 away (about 1 lakh).
    1. ␣car1669
    Not an animal at all. 9059 − 1669 = 7390 away.

Real ids from GPT-4o's tokenizer. ␣ marks a space that is part of the token. "Away" is the bigger id minus the smaller one.

So the id can't tell the model that cat and kitten are alike. The model needs a second thing for each token, one that carries meaning. To see how a model builds it, start with how you learned what a cat is.

2How did you learn what a cat is when you were a baby?

You learned from examples, not from rules. Someone pointed at an animal and told you whether it was a cat.

3What is an embedding?

An embedding is a list of numbers that a model keeps for every token.

The model works with this list, not with the token id.

From a token to its list of numbers

✂️ The token and its id (lesson 3)
  1. ␣cat9059

from I fed my cat

📖 The model's table: one row for each token id

Made-up names, to help you read the table. Real lists have no names.

idtokenanimalpetwheels… 1669␣car0.050.100.95… 6446␣dog0.850.900.05… 9059␣cat0.900.800.05… 114502␣kitten0.880.850.02… … and one row for every other token in the vocabulary
📋 What comes out: the list for ␣cat, its embedding

␣cat → 0.90, 0.80, 0.05, …

In I fed my cat, the word cat is the token ␣cat. Its id is 9059.

The model keeps a table. It has one row for every token id, and each row holds a list of numbers.

The model finds row 9059, the row for ␣cat (in green).

Out comes the list for ␣cat. This list is the embedding of ␣cat. The model works with this list, not with 9059.

Step 1 of 4

The ids are real, from GPT-4o's tokenizer. ␣ marks a space that is part of the token. The column names (animal, pet, wheels) and every number in the table are made up, and only 3 numbers per row are shown. Green marks the row the model looks up.

Real lists differ from this made-up table in two ways:

4Why do cat and dog end up with similar lists?

Because people use cat and dog in the same kinds of sentences. Training then pushes their two lists to become alike.

5How can a computer measure how close two meanings are?

One simple way: compare the two lists number by number, and add up the differences. A small total means the meanings are close, and a big total means they are far apart.

  1. 1️⃣Put the two lists side by side. ␣cat is 0.90, 0.80, 0.05. ␣kitten is 0.88, 0.85, 0.02.
  2. 2️⃣For each position, take the bigger number minus the smaller one. The first numbers: 0.90 − 0.88 = 0.02.
  3. 3️⃣Add up the differences. We call this total the gap. 0.02 + 0.05 + 0.03 = 0.10.
  4. 4️⃣A small gap means close in meaning. A big gap means far apart. The gap from ␣cat to ␣kitten is 0.10. The gap to ␣car is 2.45.

How far is each list from the list for ␣cat?

Step 1 of 4

The lists are the made-up ones from section 3, 3 numbers each. The gap is the sum of the differences, worked out on this page. Adding up the differences is one real way to measure a gap. Many tools use a different formula, but it answers the same question: how alike are two lists?

6Can a model learn the wrong clue?

Yes. A model keeps any clue that keeps matching its training examples, even a clue that is wrong. In section 2, "morning means cat" stayed until a cat came at night.

A real case from 2018, with chest X-rays:

Embeddings can pick up a wrong clue from text:

Each token gets only one list. ␣bank has one list, but a river bank and a money bank are different things. How does a model work out which bank you mean? Lesson 5 starts there.

← Lesson 3  ·  All lessons  ·  Next lesson →

Where this comes from

  • Token ids: run on 2026-10-31 with OpenAI's tiktoken 0.14.0, encoding o200k_base, which tiktoken maps to gpt-4o. github.com/openai/tiktoken. Each with its leading space, as in a sentence: ␣cat 9059 (in I fed my cat, which is I 40, ␣fed 28033, ␣my 922, ␣cat 9059; and in My cat is sleeping), ␣dog 6446, ␣car 1669 (in I parked the car), ␣kitten 114502 (in I have a pet kitten), ␣bank 6922 (in I sat on the river bank). Without the space they differ: cat is 8837, and kitten is two tokens, kit 11498 + ten 1305.
  • Embeddings are lists of numbers, also called vectors; similar meaning sits close: How Large Language Models Work (Raff, Farris, Biderman; Manning 2025), ch.3, PDF p.57-58: "the lists of numbers used to represent tokens are referred to as embeddings ... As a shorthand, we call such arrays vectors. Each position in the vector is called a dimension." Hands-On Large Language Models (Alammar, Grootendorst; O'Reilly 2024), ch.1, PDF p.31: compressed to two dimensions, "words with similar meaning tend to be closer".
  • Features don't have human names: Hands-On Large Language Models, ch.1, PDF p.30: "We may oversimplify by imagining that dimensions represent concepts (which they don't)"; "these properties are often quite obscure and seldom relate to a single entity or humanly identifiable concept."
  • A table with one row per token, part of the model; starts random; size fixed: Hands-On Large Language Models, ch.2, PDF p.95: "a portion of the model is this embeddings matrix"; "these vectors are randomly initialized like the rest of the model's weights". PDF p.106: the matrix has "dimensions vocab_size x embedding_dimensions". ch.1, PDF p.30: "the size of embeddings is fixed". GPT-4o's list length is not published, so the page uses Phi-3-mini for real sizes.
  • Phi-3-mini: 3,072 numbers per token: "hidden_size": 3072 in the model's config file, huggingface.co/microsoft/Phi-3-mini-4k-instruct.
  • Similar neighbours, similar lists; not guaranteed: Hands-On Large Language Models, ch.1, PDF p.29: "If the two words tend to have the same neighbors, their embeddings will be closer to one another". How Large Language Models Work, ch.3, PDF p.58: "we cannot guarantee that these semantic relationships will form during the training process. It just so happens that they often do." That is why the page says "usually".
  • A dial that did not affect the guess does not move: lesson 2, section 3, and its sources.
  • Measuring the gap: the sum of differences is a standard distance between two lists (also called the Manhattan or L1 distance). Many embedding tools use cosine similarity instead: Hands-On Large Language Models, ch.4. The gaps on this page (0.10, 0.15, 2.45) are worked out by the page script from the made-up lists, and were checked separately with a script.
  • Pneumonia X-rays: 34 in 100 vs about 1 in 100, 22,050 of 22,062, metal marker, worse at a new hospital: Zech et al., "Variable generalization performance of a deep learning model to detect pneumonia in chest radiographs: A cross-sectional study", PLOS Medicine, 6 November 2018. Pneumonia in 34.2% of Mount Sinai images, 1.2% at NIH and 1.0% at Indiana; hospital system identified for "99.95% NIH (22,050/22,062)"; Fig 2: "the CNN has learned to detect a metal token that radiology technicians place on the patient in the corner of the image field of view ... When these strong features are correlated with disease prevalence, models can leverage them to indirectly predict disease"; better internal than external performance "in 3 out of 5 natural comparisons". journals.plos.org/plosmedicine/article?id=10.1371/journal.pmed.1002683
  • Doctor closer to man, nurse closer to woman (the book says male and female): How Large Language Models Work, ch.3, PDF p.58: "models will often determine that doctor is more similar to male and nurse is more similar to female ... The relationships are thus not a discovered truth of the world but a reflection of the data". The same bias shows up in generated text, ch.9, PDF p.179.
  • One list per token, so "bank" has one list: Hands-On Large Language Models, ch.1, PDF p.32-35 (lesson 5 starts from it).
  • Made up on purpose: the column names and numbers in the table (section 3), the random starting lists (section 4), the "500th number" value 0.31, and the gaps worked out from them (section 5). Each is labelled where it appears. All web pages accessed 2026-10-31.