Embeddings

An embedding turns a word, sentence or image into a list of numbers, so that similar things get similar numbers. Explore a map of words and measure meaning as distance.

9 min Free

A computer can’t compare “dosa” and “idli” as words. To a program they’re just different strings. An embedding fixes that: it turns each item into a vector (a list of numbers) so that items with similar meanings get similar numbers. Each vector is a point in an embedding space, and the distance between two points tells you how related they are.

You’ve seen embeddings already: inside an LLM, every token becomes an embedding before the transformer runs (see What is an LLM?). The same idea powers semantic search, recommendations and the “retrieval” step that grounds an agent in your documents.

The usual way to compare two embeddings is cosine similarity: how closely the two vectors point in the same direction. Close to 1 means very similar. Close to 0 means unrelated.

Press Play to walk through the map. Afterwards, tap any word to see its nearest neighbours.

Meaning as distance
  1. Map
  2. Vector
  3. Neighbours
  4. Far apart
  5. Directions
  6. Explore
Embedding map (tap a word)
dosaidlisambarvada pavpav bhajipizzaChennaiMaduraiMumbaiPunerainmonsoonhumidsunnytrainbusmetroauto
foodplaceweathertransport
“dosa” as 8 numbers
0.90food
0.00weather
0.00travel
0.00place
0.60TN
0.00MH
0.10dim 7
0.20dim 8
Cosine similarity to “dosa”
  • Press Play, or tap a word.
Map

An embedding turns each word into a list of numbers: a point in space. Here every word has 8 numbers, squashed onto this 2D map. Words used in similar ways end up near each other. Press Play.

The 8 numbers per word are made up so the dimensions can be labelled. Real embeddings have hundreds of unlabelled dimensions (256 to 1024 is common for words). Cosine similarity and the vector arithmetic are the real maths, and the map was computed from these vectors.

What to notice

  1. Meaning becomes geometry. Foods cluster together, cities cluster together, weather words cluster together. Nobody drew those groups: they fall out of the numbers.
  2. There’s structure inside a cluster too. Chennai sits nearer Madurai than Mumbai, and idli nearer dosa than vada pav, because the vectors also carry a sense of region.
  3. Directions can mean something. Subtracting Chennai and adding Mumbai moves “idli” towards Mumbai’s food. Real embedding models show patterns like this, though they’re never this neat.
  4. Real dimensions have no names. The toy example labels its 8 dimensions so you can read them. Real word embeddings typically have 256, 512 or 1024 dimensions, learned during training, and single dimensions rarely mean anything a person could name.
  5. Similarity is a choice of maths. Google’s guide describes three common measures: Euclidean distance, cosine and dot product. Cosine ignores the length of the vectors; dot product doesn’t. When vectors are normalised to length 1, all three rank neighbours the same way.

Keyword search

Matches the exact letters. A search for “monsoon” misses a document that only says “rain”.

Embedding search

Matches meaning. “monsoon” and “rain” have nearby embeddings, so the document is found.

Check your understanding

1. Two words have a cosine similarity of 0.97. What does that tell you?
2. Why can embedding search find a document about “rain” when you search for “monsoon”?
3. Can you read off what dimension 37 of a real embedding means, like “food-ness”?