Experiment with
Embeddings
TRI AI Saturdays · Cohort 10 · Deep Dive Session
Saturday, July 11, 2026 · Live Lab & Discussion
◆ In partnership with Google DeepMind ◆ Instructor: Kaletsidik Ayalew
How do language models turn words into numbers — and why do similar words end up close together?
📚 Session Resources

What Is an Embedding?

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.

A Vector = Coordinates

Think of an embedding as a point in a giant "meaning space." Each number is one coordinate of that point.

Many Numbers

Big models like Gemma use 1,152 numbers per word. Our tiny model used just 32. More numbers = more room for meaning.

Similar = Nearby

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)

Vectors & Matrices (with NumPy)

To work with embeddings we use the Python library numpy. It makes working with lists of numbers (vectors) and tables of numbers (matrices) easy.

Vector

An ordered list of numbers. Example: v = [7, 3, 1, 4] is a 4-number vector.

Matrix

A table of numbers with rows and columns. The embedding table has one row per word.

Shape

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.

Meaning Lives in Directions

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.

king queen prince apple banana phone computer bus

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.

The Dot Product: Measuring Similarity

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ₖ

Positive (> 0)

Angle < 90°. The vectors point the same way → words are related.

Zero (≈ 0)

Angle = 90°. Vectors are unrelated (orthogonal).

Negative (< 0)

Angle > 90°. Vectors point opposite ways → words are dissimilar.

Shape of the angle tells the story: u · v > 0 → similar meaning (king · queen) u · v = 0 → no relation (king · bus) u · v < 0 → opposite meaning (hot · cold)

A dot product can grow very large in high dimensions, so we usually normalize it — that leads us to cosine similarity.

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 wordsCosineWhat it means
"king" & "king"+1.00Identical
"king" & "queen"+0.42Closely related
"joy" & "happy"high +Similar feeling
"sad" & "happy"+0.22Both describe feelings
"king" & "bus"+0.04Unrelated

+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.

One Number Isn't Enough

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.

Hard to Read

If you plot just two of the 1,152 numbers, words rarely form clean groups. Dimensions mix many ideas at once.

Combinations Matter

Meaning lives in the pattern across all numbers, like a recipe — one ingredient alone isn't the dish.

So We Reduce

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!

Seeing in 2D: t-SNE

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)

Clusters Appear

Related words form tight clouds: "mobile", "phone", "computer", "internet" sit together.

Royals Together

"man"/"woman" and "king"/"queen" land close — the model learned the relationship.

Some Noise

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.

Try It Yourself (Live)

In today's hands-on part we will run the Google DeepMind notebook and watch embeddings come alive. You will:

  • Load 24 real token embeddings from the Gemma model.
  • Write a tiny function to pull out one word's vector.
  • Compute cosine similarity between word pairs like "king"/"queen".
  • Plot single dimensions, then use t-SNE to see the clusters.

💻 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. 💻🔥

📚 All Session Resources

Key Takeaways

1. Words → Vectors

An embedding is a list of numbers that captures a word's meaning. Similar words → similar vectors.

2. Similarity

The dot product and cosine similarity measure how alike two words are (−1 to +1).

3. See the Space

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

Tokenizer Playground · Word Embedding Playground

Embeddings Playground (sheth.io)

Thank you! Questions, debates, and "why does this happen?" moments are very welcome — that is what today is for. 😊