Gradient LabStart the lesson

Lessons › Chapter 10: Sequences and text

Word embeddings

An embedding turns each token into a list of numbers: a point in space. Before training, the points are scattered at random and mean nothing.

Watch it move. This lesson is interactive on Gradient Lab: every step is an animated scene you can replay.

Start the interactive lesson

Step by step

Story

Same meaning, different words

“Card blocked” and “can’t use my debit card” mean the same thing. Pip needs to know that.

Concept

Every word becomes a point

An embedding turns each token into a list of numbers: a point in space. Before training, the points are scattered at random and mean nothing.

Key idea

Similar words move close

During training, words used in similar ways get pulled together. Animals end up near animals, places near places, royalty near royalty. Meaning becomes distance.

Build

Directions carry meaning

Even directions mean something. The step from “man” to “woman” is roughly the same as from “king” to “queen”. So king − man + woman lands near queen.

Real life

In real life: search that understands you

Search “cheap flights to Rome” and you also get pages that say “budget airfare to Italy”, even though they share almost no words. Search engines and shops compare embeddings, so matching is by meaning rather than exact spelling.

Quick check: In a good embedding space, which pair sits closest together?

Words used in similar contexts get similar vectors, so cat and dog are neighbors.

Pseudocode

embedding = a learned list of numbers for each token
king  → [0.8, 0.3, 0.9, …]
queen → [0.8, 0.9, 0.9, …]
similar meanings → nearby vectors
king − man + woman ≈ queen      # directions carry meaning

Key terms

embedding
A learned list of numbers that represents a token (or a document) so similar meanings sit close together.

Build it: Build a mini search engine (the R in RAG) (30 min, runs in your browser)

See the project

In the news

Recent models and papers that build on this idea: