TL;DR
This 2013 paper is a follow-up to word2vec. It makes the Skip-gram model much faster by throwing away many of the most common words during training (subsampling) and by replacing the expensive output layer with a cheaper training loss called negative sampling. It then treats frequent word pairs such as "New York" as single tokens, so that a phrase gets its own vector, and it tests those vectors on analogies between phrases.
Builds on: Efficient Estimation of Word Representations in Vector Space (word2vec), Skip-Gram Model, Hierarchical Softmax, Negative Sampling · Leads to: Word Embedding, Language Model
Why it mattered
Word vectors became a standard way to give a computer a usable numerical picture of language. The paper made that cheap enough to run on very large text collections. The authors trained on about one billion words of news text for their main comparisons, and their largest phrase model used about 33 billion words. Two ideas from this paper spread beyond word2vec. The first is negative sampling, which became a common choice whenever a model must score one true pair against many unlikely ones. The second is the idea of treating a multi-word unit as one token. Later systems take this further with Subword Tokenization, which splits rare words into pieces, but the core move is the same: the unit the model sees is not always a single dictionary word. The authors also released their training code as an open-source project.
The problem
A word vector learned from context has three weaknesses.
- Training is slow. The output step of Skip-gram in its plain form (the Softmax over the whole vocabulary) costs time in proportion to the vocabulary size W, which the paper says is often between 10^5 and 10^7 terms.
- Frequent words dominate. Words such as "in", "the" and "a" can appear hundreds of millions of times in a large corpus. They co-occur with almost everything, so they carry little information about any one word, yet each occurrence still costs a training step.
- Words do not always combine. "Boston Globe" names a newspaper. Its meaning is not the meaning of "Boston" plus the meaning of "Globe". A model that gives each word its own vector cannot represent that unit.
The paper therefore asks for three things: faster training, better vectors for rare words, and vectors for phrases, together with a test that checks whether those phrase vectors are any good.
How it works
The paper's pipeline runs in this order: find phrases in the raw text, merge them into single tokens, thin out the frequent tokens, and then train Skip-gram with negative sampling.
flowchart LR A[Raw text] --> B[Count single words and word pairs] B --> C[Score each pair and join the high scorers into one token] C --> D[Drop frequent tokens at random] D --> E[Train Skip-gram with negative sampling] E --> F[One vector per word and per phrase]
Here is one small instance traced through. The counts are invented for the example; the paper's own counts are much larger.
-
Start with a sentence. Take the text "the new york times said the cat sat". The pair "new york" appears as two words in a row. The question is whether they should become one token. Check: the pair is two adjacent tokens, so it is a candidate.
-
Score the pair. Suppose the corpus has count(new) = 100, count(york) = 50 and count(new york) = 40. The paper's discount term is δ = 5. The score is (40 − 5) / (100 × 50) = 35 / 5000 = 0.007. Check: 35 divided by 5000 is 0.007.
-
Compare with a threshold. Suppose the chosen threshold is 0.005. Since 0.007 is above it, the two words are joined into one token, "new_york". A pair that scores below the threshold stays as two separate words. Check: 0.007 is greater than 0.005, so the join happens.
-
Repeat with a lower threshold. The paper runs two to four passes over the data with a decreasing threshold. On the next pass, "new_york" and "times" can be scored as a pair, which lets a longer phrase form, such as "new_york_times". Check: each pass sees the tokens the previous pass created.
-
Drop frequent tokens. Suppose "the" makes up 1 percent of the tokens, and the paper's threshold t is 10^-5. The probability of discarding each copy of "the" is 1 − sqrt(10^-5 / 0.01) = 1 − sqrt(0.001) = about 0.968. So about 97 of every 100 copies are skipped during training. Check: sqrt(0.001) is about 0.0316, and 1 minus that is about 0.968.
-
Train one step. The centre token is "new_york" and the true context word is "times". Negative sampling picks one noise word, "cat". Suppose the model gives the true pair a score of 2 and the noise pair a score of 1. The contribution to the objective is log σ(2) + log σ(−1), which is about −0.127 + (−1.313) = −1.44. Training adjusts the vectors so this number rises toward 0. Check: σ(2) is about 0.881 and σ(−1) is about 0.269, and their logarithms add to about −1.44.
-
Read off the result. "new_york" now has its own row in the vector table, and it can be queried like any word. The paper's phrase test asks this: vec("Montreal Canadiens") − vec("Montreal") + vec("Toronto") should be closest to vec("Toronto Maple Leafs"). Check: the query vector is built from three vectors and then compared with the vocabulary by cosine similarity.
The math
The Skip-gram objective and the softmax are the ones from Skip-Gram Model. This paper changes three parts of it.
For two adjacent tokens and , the score is . Here count(w_i w_j) is how often the pair occurs together, count(w_i) and count(w_j) are how often each word occurs alone, and δ is a discount that stops pairs of very rare words from being joined.
Step 2 in symbols
With the toy counts from step 2 above, count(w_i w_j) = 40, count(w_i) = 100, count(w_j) = 50 and δ = 5, so the score is . Dividing by the product of the two single counts is what makes a pair score high when its words rarely appear apart. The pair "the cat" can have a large raw count and still score low, because "the" is so frequent.
Subsampling in symbols
Each token is discarded with probability
where is the token's frequency in the corpus and is a threshold, typically around . The paper notes that this formula was chosen heuristically. It discards tokens whose frequency is above and keeps the order of frequencies intact.
Using the numbers from step 5 above, and give .
Negative sampling in symbols
Negative sampling replaces each term in the Skip-gram objective with
Here is the input vector of the centre word, is the output vector of the true context word, is the number of noise words drawn for each true pair, and is the Sigmoid Function. The first term asks the true pair to score high. The sum asks the noise pairs to score low. The paper's noise distribution is the unigram distribution raised to the power 3/4 and normalised, , which it found better than either the plain unigram or the uniform distribution.
Step 6 in symbols: with a true score of 2 and one noise score of 1 (), the term is .
Hierarchical softmax in symbols
The paper's hierarchical softmax is the baseline in its comparisons. A word is a leaf of a binary tree. Let be the -th node on the path from the root to , and let be a fixed child of . The probability of is
where is the path length and is 1 when is true and -1 otherwise. Each factor is a binary decision at one inner node. For a word whose path goes to the designated child at the root and to the other child at the second node, with scores 2 and 1, the probability is .
Results
All numbers below are copied from the paper's tables and text.
Word analogies (Table 1). The task is the word analogy set from earlier work, with 300-dimensional Skip-gram models trained on about one billion words of news text. Total accuracy, time, and the two categories:
| Method | Time (min) | Syntactic (%) | Semantic (%) | Total (%) |
|---|---|---|---|---|
| NEG-5 | 38 | 63 | 54 | 59 |
| NEG-15 | 97 | 63 | 58 | 61 |
| HS-Huffman | 41 | 53 | 40 | 47 |
| NCE-5 | 38 | 60 | 45 | 53 |
| NEG-5, 10^-5 subsampling | 14 | 61 | 58 | 60 |
| NEG-15, 10^-5 subsampling | 36 | 61 | 61 | 61 |
| HS-Huffman, 10^-5 subsampling | 21 | 52 | 59 | 55 |
Negative sampling beat hierarchical softmax on this task and was slightly better than noise contrastive estimation. Subsampling cut training time several times and raised accuracy.
Phrase analogies (Table 3). On the phrase analogy set, with the same 300-dimensional setting and about one billion words: NEG-5 scored 24 percent without subsampling and 27 percent with it; NEG-15 scored 27 and 42; hierarchical softmax scored 19 and 47. With subsampling, hierarchical softmax became the best of the three, which the authors called surprising.
Scale. The best phrase model used about 33 billion words, hierarchical softmax, 1000 dimensions and the whole sentence as context. It reached 72 percent on the phrase set of 3218 examples. With 6 billion words it reached 66 percent, which the authors take to show that the amount of data matters a great deal.
Compositionality (Table 5). Adding two vectors gives meaningful results in several cases. The sum of the vectors for "Russian" and "river" has "Volga River" among its nearest tokens. The sum of "German" and "airlines" has "airline Lufthansa" as its top neighbour.
Limits. The main training data was an internal news collection, not a public benchmark, so the numbers cannot be checked against the same data. The phrase detection threshold and the number of passes are chosen by the authors. The nearest-neighbour examples in Table 4 were inspected by hand, and Table 6 gives examples rather than a measured score. The subsampling formula is heuristic. The paper's claims about rare words rest on those inspected examples and on the phrase accuracy numbers.
Reading guide
- Abstract and Section 1 (the goal and the three contributions): Word Embedding and Efficient Estimation of Word Representations in Vector Space (word2vec).
- Section 2, the Skip-gram objective and the softmax: Skip-Gram Model, Softmax, Language Model.
- Section 2.1, hierarchical softmax: Hierarchical Softmax. The tree is a Huffman tree, see Huffman Coding.
- Section 2.2, negative sampling: Negative Sampling, Logistic Regression, Sigmoid Function, Stochastic Gradient Descent.
- Section 2.3, subsampling: the frequency argument needs only Probability; the formula is the one in The math above.
- Section 3, word analogies and Table 1: Cosine Similarity and Dot Product.
- Section 4, learning phrases: the score is built from N-gram Language Model style bigram counts.
- Section 5, additive compositionality: Dot Product and Word Embedding.
- Sections 6 and 7: comparisons with earlier vectors and the conclusion; no new prerequisites.
Check yourself
QuestionIn one sentence, what does negative sampling replace in the Skip-gram objective, and what does it train the model to do instead?Show answer
It replaces the term , which needs a softmax over the whole vocabulary, with a logistic loss. The loss asks the true context word to score high against the centre word and asks randomly drawn noise words to score low. Each update therefore touches only output vectors instead of all .
QuestionA word makes up 4 percent of the tokens in a corpus, and the threshold t is 10^-5. What is its probability of being discarded under the paper's subsampling formula?Show answer
Compute . Then , so . About 98 of every 100 copies are discarded.
QuestionWhy does subsampling help the vectors of rare words as well as speeding training?Show answer
A frequent word such as "the" co-occurs with nearly every other word, so its co-occurrences say little about any particular word. Those pairs use up most of the training steps. Dropping many copies of the frequent word lets the rare words' real neighbours shape their vectors, and the paper reports that this improves rare-word accuracy.
QuestionA team wants to join the pair machine learning into one token. The counts are count(machine) = 2000, count(learning) = 1500 and count(machine learning) = 900, with δ = 5. What is the phrase score, and what should the team compare it with?Show answer
The score is . The team should join the pair only if this is above the threshold it chose for the corpus, and the paper runs passes with a decreasing threshold, so a second pass can join longer phrases.
Sources
- Mikolov, Sutskever, Chen, Corrado and Dean, "Distributed Representations of Words and Phrases and their Compositionality", arXiv:1310.4546 (2013). https://arxiv.org/abs/1310.4546
- The same paper's DOI record. https://doi.org/10.48550/arXiv.1310.4546