Word2Vec (2013) › The Solution: Learning Meaning from Context

Michael BrenndoerferMay 16, 20256 min read
History of Language AIAll chapters
Part 4 of 9Deep Learning Arrives
Chapter 43Word2Vec (2013) › The Solution: Learning Meaning from Context
Reading section 3 of 7 · The Solution: Learning Meaning from Context · 6 minSection 3 of 7 · 6 min

Book contents

Section 3 of 7 · 6 min read

Word2Vec (2013) › The Solution: Learning Meaning from ContextOne section · Sections in this chapter3 / 7 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

Word2Vec's core insight was beautifully simple: instead of trying to define what words mean, learn what they mean by watching how they're used. The method trained a shallow neural network on a simple prediction task.guess which words appear near each other in text. Then, instead of using the network for prediction, Mikolov and his team extracted the network's internal representations. These representations, learned purely to make accurate predictions, turned out to encode rich semantic and syntactic information.

Think about how you learned language as a child. You didn't memorize dictionary definitions. You heard words used in context, over and over, until you understood their meaning through patterns of usage. Word2vec works similarly. By training on billions of words, the model learns that "cat" and "dog" must be related because they appear in similar contexts.near words like "pet," "furry," "feed," and "veterinarian." It learns that "king" and "queen" share something because they both appear near words like "crown," "throne," and "royal."

The genius was in the simplicity. No hand-crafted features. No linguistic rules. No explicit supervision about word relationships. Just a neural network learning to predict context, and meaning emerging as a byproduct.

Skip-Gram: From Word to Context

Skip-Gram, the more commonly used variant, worked like this: given a word, predict the words that appear around it. Consider the sentence "the cat sat on the mat." If "sat" is your target word and you're using a context window of two words on each side, Skip-Gram creates training examples where "sat" tries to predict "cat," "on," and "the."

Why is this clever? Because to predict context words accurately, the model needs to learn that certain words appear in certain contexts. Words that appear in similar contexts will naturally develop similar representations. The word "sat" needs a representation that helps predict words like "cat" (animals sit), "chair" (things you sit on), and "down" (direction of sitting). Through millions of training examples, the model learns embeddings that capture these contextual patterns.

Skip-Gram proved particularly effective for rare words. Each occurrence of a rare word generated multiple training examples.one for each context word in the window. So even if "xylophone" appeared only a few times in your corpus, you'd still get several training examples from those occurrences, helping the model learn a reasonable representation.

CBOW: From Context to Word

CBOW (Continuous Bag of Words) flipped the prediction direction. Given the surrounding context words, predict the target word in the middle. For "the cat sat on the mat," CBOW would use "the," "cat," "on," and "the" to predict "sat."

CBOW averaged the embeddings of context words before making its prediction, which made training faster.you processed multiple context words in a single forward pass. However, this averaging sometimes led to less distinctive embeddings for rare words, since their individual contributions got diluted by the surrounding common words.

Both architectures used a remarkably simple three-layer neural network:

  1. Input layer: A one-hot encoded vector representing the word(s)
  2. Hidden layer: The embedding space, typically 100-300 dimensions.this is the representation we care about
  3. Output layer: A probability distribution over the vocabulary

The hidden layer weights became the word embeddings. After training, you could throw away the output layer entirely. The embeddings.those weights learned to make accurate predictions.contained the semantic and syntactic information you wanted.

How Training Worked

Training started with random numbers.each word got a random vector of 100-300 dimensions. Then the model processed massive amounts of text, sliding a window across sentences and adjusting the embeddings to make better predictions.

Word2vec separated itself from earlier approaches through negative sampling. Without this shortcut, training would have been computationally impractical.

Computing probabilities over the entire vocabulary meant doing calculations for potentially millions of words for every training example. If your vocabulary had 1 million words, each training example required 1 million probability calculations. With billions of training examples, this became impossibly expensive.

Negative sampling solved this elegantly. Instead of computing probabilities over all words, the model learned a simpler task: distinguish actual context words from random words that don't appear in the context. For each real context word (a "positive" example), the model sampled a handful of random words (typically 5-20) as "negative" examples.

So if "cat" and "sat" appeared together, the model learned that their embeddings should be similar. But "cat" and "xylophone" (a randomly sampled negative example) should have different embeddings. This reduced computational complexity from millions of calculations per example to just a handful, making it feasible to train on corpora with hundreds of millions or billions of words.

Through millions of these training examples, a beautiful pattern emerged. Words appearing in similar contexts developed similar embeddings because they needed similar representations to predict similar context words. "Dog" and "cat" both frequently appeared near words like "pet," "animal," "furry," and "veterinarian," so their embeddings naturally became similar. "Dog" and "refrigerator" rarely shared contexts, so their embeddings remained distant.

The Magic of Vector Arithmetic

The embeddings exhibited a property that no one had explicitly programmed into the training objective: vector arithmetic captured semantic analogies.

Consider this: if you took the embedding for "king," subtracted the embedding for "man," and added the embedding for "woman," you'd get a vector very close to "queen."

king−man+woman≈queen\text{king} - \text{man} + \text{woman} \approx \text{queen}

This wasn't a parlor trick. It worked for many analogies:

  • Paris−France+Italy≈Rome\text{Paris} - \text{France} + \text{Italy} \approx \text{Rome}
  • walking−walk+run≈running\text{walking} - \text{walk} + \text{run} \approx \text{running}
  • bigger−big+small≈smaller\text{bigger} - \text{big} + \text{small} \approx \text{smaller}

No one told the model about gender, geography, or verb tenses. These relationships emerged naturally from the training process because the model learned to encode semantic and syntactic regularities into the vector space.

Why Does Vector Arithmetic Work?

The linear relationships emerged because words with similar relationships to other words needed similar vector transformations. The model learned that the relationship between "king" and "queen" (gender transformation in royalty) was similar to the relationship between "man" and "woman" (gender transformation in general). Since both transformations represented the same underlying pattern, they manifested as similar vector offsets in the embedding space.

This meant you could trace relationships in the semantic space through vector arithmetic. Want to find the female version of a word? Subtract "man" and add "woman." Want to find the capital of a country? Look at the vector from "France" to "Paris" and apply it to other countries.

Words with similar meanings clustered together in the embedding space. Animals grouped near each other. Colors formed their own cluster. Verbs of motion occupied a distinct region. Syntactic patterns also manifested as consistent vector offsets.the transformation from present to past tense ("walk" to "walked") created similar vector movements across different verbs.

The individual dimensions of the embeddings weren't directly interpretable. Unlike hand-crafted features where dimension 42 might explicitly represent "is a noun," word2vec's dimensions captured complex interactions between multiple linguistic factors. A single dimension might encode aspects of semantic category, syntactic function, and contextual usage patterns simultaneously. This made the embeddings dense and information-rich.every dimension contributed to representing multiple aspects of meaning.