Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 3

Geometric Relationships in Embedding Spaces

Recommended resources

In our previous lesson, we investigated the inner workings of Word2Vec, exploring how the CBOW and Skip-gram architectures learn dense vector representations for words by processing vast amounts of text. You now understand that these embeddings are a "side effect" of training a simple neural network on the pretext task of predicting words from their context.

Today, we'll explore the remarkable outcome of that training process. We will shift our focus from how embeddings are made to what they represent. You will discover that the resulting high-dimensional vector space is not a random jumble of numbers but a structured landscape where geometry corresponds to semantic meaning. By the end of this lesson, you will be able to interpret these geometric relationships and understand how they enable us to solve word analogies using simple vector arithmetic.

From Personality Traits to Word Meanings

Before diving into word vectors, let's build an intuition with a more familiar concept: personality. Imagine representing a person's personality as a vector of scores on different traits. This is precisely what Jay Alammar does in his article, "The Illustrated Word2vec," which provides some of the clearest explanations available on this topic.

The Illustrated Word2vec - Jay Alammar

This article provides an excellent analogy for understanding embeddings.

Please read the first two sections. Start with "Personality Embeddings" to understand how we can represent concepts as vectors and measure their similarity using cosine similarity. Then, continue to the section "Word Embeddings" to see how this same idea applies to words, where each word is a long vector of numbers.

As the article illustrates, just as we can compare people by the "closeness" of their personality vectors, we can compare words by the closeness of their word embeddings. The training process we examined in the last lesson arranges words in this vector space such that words with similar meanings (e.g., "king" and "queen," or "man" and "woman") end up with vectors that are near each other.

The image below shows this concept. On the left, each word is represented by a numerical vector. Each number in the vector can be thought of as a coordinate along some abstract dimension of meaning. On the right, these vectors are visualized as points in a 2D space, where semantically related words are clustered together.

An illustration of how words are mapped to numerical vectors (word embeddings) and how their relationships can be visualized in a geometric space. Note the proximity of related pairs like 'man'/'woman' and 'king'/'queen'.

The Geometry of Semantics: Directions Have Meaning

The most profound property of these embedding spaces is not just that similar words are close, but that the directions within the space encode specific semantic relationships.

Think of it like a map. The direction "north" consistently moves you towards colder climates, regardless of your starting point. Similarly, in an embedding space, there might be a specific direction that corresponds to "gender," another to "royalty," and another to "verb tense."

The article "Transformers, the tech behind LLMs" from 3Blue1Brown offers a fantastic explanation of this core idea.

Transformers, the tech behind LLMs | Deep Learning Chapter 5

Although this article is about Transformers, its introduction to embeddings is one of the best available. It clearly explains the geometric interpretation we are focusing on.

First, read the brief section under the heading "Embedding Matrix" to solidify the idea of embedding words in a high-dimensional space. Then, focus on the section titled "Direction". This is the key part of the reading. It explains how directions in this space have meaning, using the classic woman - man vector as an example.

This discovery that relationships can be encoded as consistent vector offsets is what allows for the "word algebra" that Word2Vec became famous for.


Word Analogies as Vector Arithmetic

The most famous demonstration of this property is the analogy:
"Man is to woman as king is to ___?"

In the embedding space, we can translate this analogy into a vector equation:

Let's break down what this operation is doing semantically:

  1. : This subtraction isolates the vector that represents the concept of "royalty" by removing the "maleness" from "king." You are left with a vector that points from man to king.
  2. : You then add this "royalty" vector to the vector for "woman." This effectively applies the concept of royalty to a female context.

The resulting vector won't be identical to the vector for "queen," but it will be extremely close. If you then search the entire vocabulary for the word whose embedding has the highest cosine similarity to this resulting vector, the top answer will be "queen."

The following video from the codebasics channel provides a simple numerical walkthrough of this exact calculation, making the abstract idea very concrete.

What is Word2Vec? A Simple Explanation | Deep Learning Tutorial 41 (Tensorflow, Keras & Python)

Let's watch a segment of the video "What is Word2Vec? A Simple Explanation," which you saw briefly in the last lesson.

Start from the beginning of the video to see the motivating example. Then, pay close attention to the numerical example presented between "And for different words", which shows exactly how the vector components are added and subtracted to solve the king - man + woman analogy.

The diagrams below visualize this vector arithmetic. The left diagram shows the literal addition and subtraction of the vectors, while the right diagram shows how the vector difference king - man is parallel to queen - woman, illustrating the consistent "gender" direction.

Two visualizations of the vector arithmetic `king - man + woman ≈ queen`. The left panel shows the explicit vector operations. The right panel highlights the parallel relationship, showing that the vector from 'Man' to 'King' is similar to the vector from 'Woman' to 'Queen'.

Generalizing the Concept

This principle extends far beyond the "king-queen" example. It captures a wide variety of linguistic relationships. The video "What Are Word Embeddings?" gives another clear explanation and provides a great example involving countries and capitals.

What Are Word Embeddings?

This video from the channel Under The Hood offers another perspective and a new example to help generalize your understanding.

Watch the segment from "now that feature vectors are encoded semantically". It first recaps the king - queen analogy and then introduces a new one: Beijing - China + Japan ≈ Tokyo. This demonstrates that the model has learned a "is capital of" relationship.

Other famous examples include:

  • Verb Tense: walking - walk + swim ≈ swimming
  • Country-Currency: Germany - Euro + Japan ≈ Yen

These analogies reveal that the Word2Vec training process, without any explicit instruction, organizes the embedding space to reflect complex real-world semantic and syntactic structures. The model learns these relationships simply by observing which words appear in similar contexts across a massive dataset.


Conclusion

In this lesson, you've moved beyond the mechanics of training and into the interpretive power of word embeddings. You now understand one of the most celebrated results in modern NLP.

Here are the key takeaways:

  • Meaningful Geometry: Word embeddings are not just arbitrary points; they exist in a vector space where proximity and direction encode semantic relationships.
  • Directions as Concepts: Consistent directions in the embedding space can represent abstract concepts like gender, royalty, or the relationship between a country and its capital.
  • Vector Arithmetic for Analogies: By performing simple vector addition and subtraction, we can solve word analogies, effectively navigating the learned semantic landscape of the embedding space. The operation king - man + woman results in a vector very close to queen.
  • Similarity Measurement: We find the answer to an analogy by calculating the resulting vector and then searching for the word in our vocabulary whose embedding has the highest cosine similarity to it.

You have now completed a deep dive into Word2Vec, from its training process to the interpretation of its results. This foundational knowledge is crucial as we move forward.

In the next lesson, we will compare Word2Vec to other important word embedding techniques, GloVe and fastText. This will give you a broader understanding of the landscape of "static" embeddings before we move on to the contextual embeddings that power modern LLMs.