Language Models2013foundational10 min read

Distributed Representations of Words and Phrases and Their Compositionality

التمثيلات الموزَّعة للكلمات والعبارات وخاصية التركيب

Mikolov, T. · Sutskever, I. · Chen, K. · Corrado, G. · Dean, J. — NeurIPS

The problem

Before , representing words for machine learning was crude: either a one-hot of size (sparse, no similarity signal) or hand-crafted features. Full neural language models like Bengio's 2003 model could learn good representations, but the over the entire vocabulary at each step made prohibitively expensive for large corpora. There was no scalable method to learn dense word vectors that captured rich semantic and syntactic patterns.

The contribution

Three practical advances that made the model trainable at billion-word scale: (1) — replace the expensive softmax over the full vocabulary with a binary classification task that contrasts true context words against a few randomly drawn "" words. (2) of frequent words — randomly discard common words like "the" and "a" during training, yielding speedup and better rare-word vectors. (3) — a statistical scoring method identifies multi-word expressions ("New York", "ice cream") and treats them as single tokens. Together these produced word vectors with remarkable compositional arithmetic: vec("king") − vec("man") + vec("woman") ≈ vec("queen").

The impact

Word2Vec democratized word embeddings. Within two years GloVe and fastText followed, and dense word vectors became the default input to virtually every NLP pipeline. The idea of learning representations from context — rather than hand-engineering features — foreshadowed the pre-training revolution that led to BERT, GPT, and every modern large . DeepWalk extended the skip-gram idea to graphs, and Contrastive Predictive Coding generalized it to speech and images.

Imagine a dictionary where every word's definition is just a list of numbers — not characters, but coordinates in a vast conceptual space. Words used in similar sentences drift toward each other like magnets on a whiteboard: "happy" and "joyful" cluster together, while "happy" and "concrete" repel to distant corners.

The astonishing part: directions in this space encode meaning. Walk from "man" to "king" and the same step takes you from "woman" to "queen". The model never learned royal semantics — it learned geometry of context.

The problem: words as meaningless IDs

The simplest way to feed a word to a is : a vector of zeros with a single 1 at the word's index. If the vocabulary has 100,000 words, every word becomes a 100,000-dimensional vector — enormous, sparse, and completely blind to similarity. "Cat" and "kitten" are as far apart as "cat" and "parliament".

Full neural language models (Bengio et al., 2003) solved this by learning dense embeddings, but their computed a softmax over the entire vocabulary at every training step. For a vocabulary of V words, that means V dot products plus a normalization — an operation that scales linearly with V and becomes a bottleneck when V reaches hundreds of thousands.

The Skip-gram model: predict context from a center word

The Skip-gram model flips the typical language model around. Instead of predicting the next word from its history, it takes a center word and tries to predict the surrounding context words within a window of size cc. Think of it as a spotlight: the center word asks, "Who usually stands near me?"

Given a sequence of training words w1,w2,…,wTw_1, w_2, \ldots, w_T, the objective is to maximize the average log probability:

1T∑t=1T∑−c≤j≤cj≠0log⁡p(wt+j∣wt)\frac{1}{T} \sum_{t=1}^{T} \sum_{\substack{-c \le j \le c \\ j \ne 0}} \log p(w_{t+j} \mid w_t)

Each word has two roles — and therefore two vectors. As a center word it uses its input vector vwv_w; as a context word it uses its output vector vw′v'_w. The probability of seeing context word wOw_O given center word wIw_I is defined via softmax over the full vocabulary.

p(wO∣wI)=exp⁡(vwO′⊤vwI)∑w=1Vexp⁡(vw′⊤vwI)p(w_O \mid w_I) = \frac{\exp(v'_{w_O}{}^\top v_{w_I})}{\sum_{w=1}^{V} \exp(v'_w{}^\top v_{w_I})}
Full Softmax Probability — This equation computes the probability of a candidate context word given a center word. Words whose vector representations are more similar receive higher probabilities. To produce a valid probability distribution, the score for every word in the vocabulary must be considered, making this computation expensive for large vocabularies. This cost is the main reason later training methods use approximations instead of the full softmax.
Open in Lab
Slide the window across the sentence. The center word (highlighted) predicts each context word independently.
The demo wakes as you arrive…

Negative Sampling: the key speedup

The expensive part of Skip-gram is the softmax denominator — summing exp⁡(vw′⊤vwI)\exp(v'_w{}^\top v_{w_I}) over every word in the vocabulary. Negative Sampling (NEG) replaces this with a far cheaper surrogate objective.

The idea is elegant: instead of asking "what is the probability of this context word among all V words?", ask a binary question — "did this word-context pair come from real data, or is it noise?" For each real (wI,wO)(w_I, w_O) pair the model should output high probability. Then draw kk random "negative" words from a and the model should output low probability for each of them.

Imagine a customs officer. Instead of checking every passenger on the plane (full softmax), she checks the ticket of the arriving passenger (the positive pair) and then spot-checks kk random people from the airport crowd (negative samples). Much faster, and still catches counterfeits.

log⁡σ(vwO′⊤vwI)+∑i=1kEwi∼Pn(w)[log⁡σ(−vwi′⊤vwI)]\log \sigma(v'_{w_O}{}^\top v_{w_I}) + \sum_{i=1}^{k} \mathbb{E}_{w_i \sim P_n(w)} \left[\log \sigma(-v'_{w_i}{}^\top v_{w_I})\right]
Negative Sampling Objective (NEG) — Instead of comparing a word against every word in the vocabulary, negative sampling trains the model using only a small set of examples. The objective encourages the representations of genuine word pairs to become more similar while pushing randomly selected noise words farther apart. This dramatically reduces computational cost while still producing high-quality word embeddings. Negative examples are sampled from a smoothed frequency distribution so that both common and less frequent words participate in training.
Open in Lab
Compare full softmax (touching all V words) vs. Negative Sampling (touching only k+1 words). Toggle k to see the tradeoff.
The demo wakes as you arrive…

Subsampling frequent words: less is more

Words like "the", "a", and "in" appear millions of times in any large . They provide much less information than rare words — seeing "the" next to "France" tells you almost nothing, while "Paris" next to "France" is highly informative. Yet without correction, the model spends most of its compute on these uninformative pairs.

The paper introduces a simple subsampling formula: each word wiw_i in the training data is discarded with a probability that grows with its frequency.

P(discard wi)=1−tf(wi)P(\text{discard } w_i) = 1 - \sqrt{\frac{t}{f(w_i)}}
Subsampling Probability — This rule reduces the number of extremely common words seen during training while keeping most rare words. Frequent words often contribute less new information because they appear in many contexts, so removing a portion of them speeds up training and allows the model to focus more on informative examples. The result is both faster learning and improved representations for less frequent words.
Open in Lab
Adjust the threshold t and see which words survive. Notice how "the" and "of" get aggressively filtered while rare words pass through.
The demo wakes as you arrive…

Learning phrases: "New York" is not "New" + "York"

Some word combinations carry meaning that their parts alone do not convey. "New York" is a city, not something new and something called York. "Ice cream" is a dessert, not frozen cream. Treating these as separate tokens loses critical meaning.

The paper uses a data-driven scoring function based on to identify such phrases:

score(wi,wj)=count(wi wj)−δcount(wi)×count(wj)\text{score}(w_i, w_j) = \frac{\text{count}(w_i\, w_j) - \delta} {\text{count}(w_i) \times \text{count}(w_j)}

When the score exceeds a threshold, the bigram is merged into a single . Running this process multiple times discovers longer phrases like "New_York_Times". The approach is simple but effective — no linguistic rules, purely statistical co-occurrence.

Open in Lab
See how phrase scoring identifies multi-word expressions in a sample sentence. High scores indicate likely phrases.
The demo wakes as you arrive…

Vector arithmetic: the magic of compositionality

The most celebrated result of Word2Vec is that its vector space encodes semantic relationships as directions. The classic demonstration:

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

This is not a trick or cherry-picked example — it works across many relationship types. The direction from "man" to "woman" captures a gender axis; the direction from "Paris" to "France" captures a capital-country axis. These directions are consistent: the same offset that maps "Paris" → "France" also maps "Berlin" → "Germany".

This arises because the Skip-gram objective implicitly factorizes a word-context co-occurrence matrix. Words that share similar contexts end up at similar positions, and systematic relationships in language create systematic geometric patterns in the space.

Open in Lab
Try different word analogies. The model finds the closest word to a − b + c by cosine similarity.
The demo wakes as you arrive…

Hierarchical Softmax: the tree-based alternative

Before Negative Sampling, the paper also discusses — an earlier approach to avoiding the full-vocabulary sum. The idea: arrange all words as leaves of a binary tree. Instead of computing one V-way softmax, the model makes a series of binary decisions as it walks down the tree from root to the target word's leaf.

Each internal node has a learned vector, and at each branch the model computes a to decide left or right. The total path length is log⁡2V\log_2 V — so the cost drops from O(V)O(V) to O(log⁡V)O(\log V). A Huffman tree assigns shorter paths to frequent words, further speeding up common predictions.

The paper found that Negative Sampling outperformed Hierarchical Softmax on analogy tasks, particularly for frequent words, while being simpler to implement. This is why Negative Sampling became the default training method for Word2Vec.

Open in Lab
Click a word to see its path through the Huffman tree. Frequent words get shorter paths — fewer binary decisions.
The demo wakes as you arrive…

Full training pipeline

The complete Word2Vec training pipeline combines all three contributions into a streamlined process:

Step 1 — Phrase detection. Scan the corpus and merge high-scoring bigrams into single tokens. Run multiple passes for longer phrases.

Step 2 — Build vocabulary. Count all (merged) tokens. Discard any below a minimum frequency threshold.

Step 3 — Subsample frequent words. For each training sentence, randomly drop words with probability tied to their frequency. This both accelerates training and improves quality.

Step 4 — Train with Negative Sampling. For each surviving center-context pair: push their vectors closer together; sample kk noise words and push their vectors apart from the center word. Update via .

The result: a matrix of dense vectors — one per word — where geometric relationships encode semantic meaning. Training on a billion-word corpus takes hours, not weeks.

Open in Lab
Step through the full pipeline — from raw text to trained embeddings.
The demo wakes as you arrive…

Why addition works: the log-linear connection

It may seem magical that vector addition captures semantic analogies. The paper offers an intuitive explanation rooted in the training objective.

Skip-gram's probability is defined via exponentiated dot products. Taking logs converts multiplication to addition. If words that share a relationship consistently appear in similar contexts, the offset vector between them points in a consistent direction. Adding and subtracting these offsets navigates the space along meaningful axes.

This is not a guaranteed property of any embedding — it emerges because the Skip-gram objective implicitly captures log-probability ratios of co-occurrence statistics. Later work (Levy & Goldberg, 2014) showed this connection rigorously: Skip-gram with negative sampling implicitly factorizes a shifted PMI (pointwise mutual information) matrix.

What Word2Vec unlocked

  1. 2013

    Word2Vec (this paper)

    Skip-gram + Negative Sampling. Showed that simple log-linear models trained on vast text produce vectors with remarkable compositionality.

  2. 2014

    GloVe

    Pennington et al. combined global co-occurrence statistics with local context windows. Showed Word2Vec implicitly factorizes a PMI matrix and proposed an explicit factorization that matched or beat it.

  3. 2014

    DeepWalk

    Applied Skip-gram to random walks on graphs — nodes become "words", walks become "sentences". Extended embeddings beyond language to social networks and knowledge graphs.

  4. 2017

    fastText

    Bojanowski et al. enriched Word2Vec with character n-grams, allowing the model to construct embeddings for unseen words by combining sub-word pieces. Essential for morphologically rich languages.

  5. 2018

    ELMo → contextualized embeddings

    Peters et al. showed that static vectors (one vector per word) miss polysemy. Contextual embeddings from deep LSTMs gave "bank" different vectors in "river bank" vs "bank account". The idea Word2Vec planted evolved into context-dependent representations.

  6. 2019

    CPC — Contrastive Predictive Coding

    Van den Oord et al. generalized the "predict context from target" idea to speech, images, and video. The contrastive objective descends directly from Negative Sampling.

Word2Vec's most enduring contribution is not any particular set of vectors — it is the idea that unsupervised co-occurrence prediction creates structured representations. Every modern pre-trained model, from BERT to GPT, is a descendant of this insight: learn from context, and meaning emerges in the geometry of the learned space.

CitationMikolov, Sutskever, Chen, Corrado, Dean. Distributed Representations of Words and Phrases and Their Compositionality. NeurIPS, 2013.

Terms in this paper