A computer only understands numbers. So a language model turns every word (token) into a long list of numbers called a vector. We call that vector the word's embedding.
Think of an embedding as a point in a giant "meaning space." Each number is one coordinate of that point.
Big models like Gemma use 1,152 numbers per word. Our tiny model used just 32. More numbers = more room for meaning.
Words with similar meaning get similar vectors — they sit close together in that space.
Embedding for "king" → [0.23, -1.45, 0.67, ..., 0.12] (1,152 numbers) Embedding for "queen" → [0.25, -1.40, 0.62, ..., 0.15] (almost the same!) Embedding for "apple" → [-0.98, 2.10, -0.33, ..., 0.88] (very different)
To work with embeddings we use the Python library numpy. It makes working with lists of numbers (vectors) and tables of numbers (matrices) easy.
An ordered list of numbers. Example: v = [7, 3, 1, 4] is a 4-number vector.
A table of numbers with rows and columns. The embedding table has one row per word.
How big it is. A vector of 4 numbers has shape (4,). A 2×3 matrix has shape (2, 3).
import numpy as np
# A vector and a 2x3 matrix
v = np.array([7, 3, 1, 4])
M = np.array([[6, 1, 4],
[9, 0, 2]])
print(v.shape) # (4,) -> 4 numbers
print(M.shape) # (2, 3) -> 2 rows, 3 columns
# Grab one row (one word's embedding) and one column
row_3 = embeddings[2, :] # 3rd word's vector
col_7 = embeddings[:, 6] # 7th number across all words
The whole embedding table is just a big matrix: rows = words, columns = meaning-coordinates.
The magic of embeddings: words that mean similar things point in similar directions. "king" and "queen" point almost the same way. "apple" points somewhere else entirely.
A simplified 2D view. In reality the space has 1,152 dimensions!
This is why a model can guess meaning even for words it has rarely seen — their vectors land near related words it already knows.
How do we measure if two vectors point the same way? With the dot product — we multiply their numbers pair-by-pair and add everything up.
dot_product = u·v = u₁v₁ + u₂v₂ + ... + uₖvₖ
Angle < 90°. The vectors point the same way → words are related.
Angle = 90°. Vectors are unrelated (orthogonal).
Angle > 90°. Vectors point opposite ways → words are dissimilar.
A dot product can grow very large in high dimensions, so we usually normalize it — that leads us to cosine similarity.
Cosine similarity is the dot product divided by the lengths of both vectors. The result is always between -1 and +1, so it is easy to compare.
cosine(u, v) = (u · v) / ( ||u|| × ||v|| )
| Pair of words | Cosine | What it means |
|---|---|---|
| "king" & "king" | +1.00 | Identical |
| "king" & "queen" | +0.42 | Closely related |
| "joy" & "happy" | high + | Similar feeling |
| "sad" & "happy" | +0.22 | Both describe feelings |
| "king" & "bus" | +0.04 | Unrelated |
+1 = same direction, 0 = unrelated, -1 = opposite. Notice even antonyms like "sad/happy" score above 0 — they are still both feelings, so the model groups them loosely.
It is tempting to ask "what does the 5th number mean?" In practice, no single number carries a clear meaning. Meaning comes from the whole vector together.
If you plot just two of the 1,152 numbers, words rarely form clean groups. Dimensions mix many ideas at once.
Meaning lives in the pattern across all numbers, like a recipe — one ingredient alone isn't the dish.
We use tricks to compress all dimensions into 2 or 3 so we can actually see the structure.
# Pick any 2 dimensions and plot the words
emb.plot_embeddings_dimensions(embeddings, labels,
dim_x=432, dim_y=877)
Try different pairs — you will rarely find a single pair that cleanly separates "food" from "technology". That is normal!
t-SNE is a technique that compresses 1,152 dimensions down to 2, while trying to keep nearby words nearby and far words far. The result is a map we can actually look at.
emb.plot_embeddings_tsne(embeddings, labels)
Related words form tight clouds: "mobile", "phone", "computer", "internet" sit together.
"man"/"woman" and "king"/"queen" land close — the model learned the relationship.
Compression isn't perfect: "cat" and "car" may look near each other by accident.
t-SNE is a viewing tool, not the model itself. It helps us see and debug what the embeddings learned.
In today's hands-on part we will run the Google DeepMind notebook and watch embeddings come alive. You will:
💻 Notebook: Open the Embeddings Lab notebook in Colab
Original source: Google DeepMind · AI Foundations · course_2
No answers are hidden — run the cells, change the words, and discuss what you see. That is where the learning happens!
Let's Dive into the Lab and Practice Some coding. 💻🔥
An embedding is a list of numbers that captures a word's meaning. Similar words → similar vectors.
The dot product and cosine similarity measure how alike two words are (−1 to +1).
Single numbers don't explain meaning; t-SNE lets us visualize the whole space as clusters.
Today you experimented with real embeddings — the same idea that powers the "meaning" inside every language model, including the tiny SLM we built on Wednesday.
Resources: 📚 Open the Resources page
• Notebook: Embeddings Lab (Colab)
• Repo: github.com/AlexKalll/tri-AI-Teaching
• Instructor: Kaletsidik Ayalew · github.com/AlexKalll
Thank you! Questions, debates, and "why does this happen?" moments are very welcome — that is what today is for. 😊