AI Hints
Home›Generative AI Tutorial›Tokens, Embeddings and Context
Generative AI · Lesson 11 of 77

Embeddings

How meaning becomes numbers.

⏱ 2 min read▶ Video at 28:32🎓 Free
Watch this lesson in the Generative AI courseWatch on YouTube ↗Full Generative AI course

A token number, like four thousand and twelve, tells the model nothing about meaning. The word king, and the word queen, should feel close. The word banana should feel far away. Embeddings solve this problem, and they are one of the most beautiful ideas in AI.

Embeddings
From the video: Embeddings
  • A bare number carries no meaning
  • Similar meanings should be close
  • Embeddings: meaning as a position

A map of meaning

An embedding turns every token into a list of numbers, which you can imagine as a position on a map. Words with similar meanings land close together. Here is a simplified two dimensional picture. Animals gather in one region. Fruits in another. Cities in a third. Real models use hundreds, or thousands of dimensions, which we cannot draw, but the idea is the same. Closeness on the map means closeness in meaning.

cat, dog, horseclose together in meaning
apple, banana, grapeclose together in meaning
Paris, London, Tokyoclose together in meaning
A map of meaning
From the video: A map of meaning

Meaning has directions

The most amazing part is that directions on the map carry meaning too. Start from the word king, subtract the idea of man, and add the idea of woman. You arrive very close to queen. The model was never taught this. The relationship between king and queen, is the same direction as between man and woman. The maths of meaning emerges from the patterns in the data.

man, kingclose together in meaning
woman, queenclose together in meaning
Meaning has directions
From the video: Meaning has directions

What embeddings make possible

Embeddings are used everywhere. Search engines use them to find results by meaning, not just by matching words. Recommendation systems use them, to suggest films similar to ones you like. And they are the foundation of a technique called retrieval, which lets a chatbot look up your own documents. Later in the course, you will build exactly that.

Search by meaningfind ideas, not just keywords
Recommendationsfilms and music similar to your taste
Retrieval for chatbotslook up your own documents
Clusteringgroup similar items automatically

Summary

Excellent. An embedding turns a token into a list of numbers, a position on a map of meaning. Similar things land close together, and even relationships become directions. Next, a problem. Word order matters. How does a model know that dog bites man, is not the same as man bites dog?

Key takeaways
  • Embedding = position on a map of meaning
  • Close in space = close in meaning
  • Directions can carry relationships
Next up: Position and Context — why word order matters