The Nightly Build.
Paper of the Day

word2vec's most famous demo predates word2vec

The King–Queen analogy that made the paper famous first appeared in an earlier RNN model, and the version word2vec actually ran only works with its own question words ruled out as candidates.

Efficient Estimation of Word Representations in Vector Space

Tomas Mikolov, Kai Chen, Greg Corrado, Jeffrey Dean · arXiv:1301.3781 · 2013

Read the paper
We propose two novel model architectures for computing continuous vector representations of words from very large data sets. The quality of these representations is measured in a word similarity task, and the results are compared to the previously best performing techniques based on different types of neural networks. We observe large improvements in accuracy at much lower computational cost, i.e. it takes less than a day to learn high quality word vectors from a 1.6 billion words data set. Furthermore, we show that these vectors provide state-of-the-art performance on our test set for measuring syntactic and semantic word similarities.1

The cost word2vec was built to cut

Before 2013, the strongest word-vector models ran every prediction through a nonlinear hidden layer. A language model read a window of context words, mixed them together in a layer that squashed the combination nonlinearly, and only then predicted a word. That layer gave the older neural language models their expressive power, and it is also what made them slow to train on more than a few hundred million words at a time.1

Mikolov, Chen, Corrado, and Dean's answer was to remove it. Continuous bag-of-words (CBOW) predicts a word from the words around it. Skip-gram runs the same idea backward, predicting the surrounding words from one word in the middle. Neither model passes its input through anything nonlinear, so a training step costs a sum and a lookup instead of a matrix mixture. The paper states the saving as a formula: CBOW costs N·D + D·log2(V) per training example, and skip-gram costs C·(D + D·log2(V)). D is the vector size and V the vocabulary. The older, nonlinear language models added a much larger term instead.1

On identical training data and vector size, the paper's own comparison shows what removing that layer bought.1

Same data, same vector size: accuracy on the paper's own analogy test, by architecture.1
Architecture Semantic Syntactic
RNNLM 9% 36%
NNLM 23% 53%
CBOW 24% 64%
Skip-gram 55% 59%

Turned loose on more data, skip-gram's best reported run reached 52.2% semantic and 55.1% syntactic accuracy on the paper's own 19,544-question test. That run used 300 dimensions, trained on 1.6 billion words drawn from a 6-billion-token Google News corpus, with the vocabulary capped at the million most frequent words.1 Google never released that training corpus or the resulting vectors. Every accuracy figure attached to it is the number Mikolov and coauthors reported, not a number anyone outside Google has independently reproduced on the same data.1

Scoring every word was still too slow

Removing the hidden layer fixed one cost. It left another standing: both models still trained by ranking the correct next word against every other word in the vocabulary, a full softmax over hundreds of thousands of candidates at each step. On a billion-word corpus, that ranking is more of the same expense the paper had just spent its effort cutting.2

So what happens when the vocabulary the model has to score, at every single step of training, runs past a million words? Mikolov, Sutskever, Chen, Corrado, and Dean's companion paper, published nine months after the first, answered by not scoring the vocabulary at all.2

Negative sampling trains the model to tell the true neighbor apart from a handful of words drawn at random, rather than ranking it above every word in the language. Picture a five-word toy vocabulary: cat, dog, ran, fast, moon, and a training pair (ran, fast). Negative sampling does not ask the model to rank fast above cat, dog, and moon all at once. It asks a few small yes-or-no questions instead: is fast the right neighbor for ran (yes), is moon (no), is cat (no), is dog (no). The paper recommends drawing five to twenty such negative words for a small corpus, and as few as two to five for a large one.2 Multiply the toy example by a real vocabulary, and a training step costs a handful of comparisons instead of one comparison per word in the language.

Where King − Man + Woman = Queen actually comes from

The sentence that made “Efficient Estimation” famous sits early, in the paper's own statement of its goals. It reads: “Using a word offset technique where simple algebraic operations are performed on the word vectors, it was shown for example that vector('King') − vector('Man') + vector('Woman') results in a vector that is closest to the vector representation of the word Queen.”1 That sentence carries a citation, numbered [20], to a different paper: Mikolov, Yih, and Zweig, “Linguistic Regularities in Continuous Space Word Representations.”3

That earlier paper, not the one this piece opened with, is where the vector-offset method and the King/Queen example both originate. Its vectors come from a recurrent neural network language model, the same family of architecture “Efficient Estimation” was built to replace. It trained on 320 million words of Broadcast News transcripts with an 82,000-word vocabulary, roughly a tenth the data of the Google News runs that made skip-gram's own numbers. On its own 8,000-question syntactic test, the best RNN model reported 39.6% accuracy.3

“Efficient Estimation” adopted the offset idea and reran it, at far larger scale, on the two new architectures the paper actually introduces. The popular account credits CBOW and skip-gram with discovering that word vectors encode analogies through direction and distance in vector space. The offset technique itself credits an earlier, smaller, differently built model, in a bracketed citation most retellings of the story drop.

Why the search never considers King, Man, or Woman

Picture the vectors for King, Man, Woman, and Queen as four points in a high-dimensional space. The offset technique computes a new point, X = vector(King) − vector(Man) + vector(Woman). It then asks which word's vector sits closest to X by the angle between them, cosine distance rather than straight-line distance. Word2vec's own paper adds one more step, stated plainly in its results section: “we discard the input question words during this search.”1 King, Man, and Woman are not allowed to be the answer to a question that already contains them.

\operatorname*{arg\,max}_{b^* \in V} \cos\!\left(b^*,\ b - a + a^*\right)

Levy and Goldberg's 2014 paper gave that rule a name and a formal definition, 3CosAdd: the highest-cosine word in a vocabulary V that specifically excludes the three question words, a, a*, and b.4 They also showed the formula rearranges, once vectors are unit length, into cos(b*,b) − cos(b*,a) + cos(b*,a*). That is the candidate word's similarity to Queen, minus its similarity to Man, plus its similarity to Woman. Read that way, an analogy answer is three ordinary similarity scores added together. The term with the largest raw similarity can swamp the other two. London:England :: Baghdad:? answers “Mosul” under 3CosAdd, because Mosul sits close to Baghdad geographically and that one term dominates the sum. The actual answer, Iraq, only wins once the three terms are multiplied instead of added, the fix Levy and Goldberg call 3CosMul.4

Which formula runs the search changes which kind of vector looks smarter, not just by how much it wins but by whether it wins at all. The comparison below runs on the same Wikipedia corpus, the same skip-gram embeddings, and the GOOGLE test set: 19,258 of its original 19,544 questions, after removing entries with out-of-vocabulary words. An older count-based representation trails badly under 3CosAdd and comes out ahead under 3CosMul.4

Same corpus, same skip-gram vectors: which representation wins depends on the scoring rule.4
Rule, dataset Skip-gram Explicit PPMI Result
3CosAdd, MSR 53.98% 29.04% skip-gram wins by 25 points
3CosAdd, GOOGLE 62.70% 45.05% skip-gram wins by 18 points
3CosMul, MSR 59.09% 56.83% a 2-point margin
3CosMul, GOOGLE 66.72% 68.24% explicit vectors edge ahead

Levy and Goldberg add one further complication neither 2013 paper discloses. On the semantic half of Mikolov and coauthors' own published evaluation, the answers were actually scored with a different formula, PAIR_DIRECTION, not 3CosAdd. Levy and Goldberg say they confirmed that by corresponding with the original authors, not by reading it in the published text.4 That detail rests on one paper's account of a conversation, not on anything either 2013 paper states in print.

Turn off the exclusion and the analogy falls apart

Tal Linzen tested what the search finds without that rule, training his own skip-gram-with-negative-sampling spaces and running the raw, unconstrained version of the offset method: search the entire vocabulary, King, Man, and Woman included.5

98%Top match was one of the three question words
0.71→0.213CosAdd accuracy, exclusion on vs off

Broken down, the nearest neighbor to X was Woman, the input word itself, in 93% of cases, and King, the other input word, in another 5%. It was never Man.5 In word2vec's own famous example, the unconstrained search's top guess for King − Man + Woman is Woman, not Queen, because the input word already sitting in the search is, geometrically, the closest point to X there is. The exclusion rule is not a footnote to the offset technique. It is most of what makes the technique look correct at all.

Nissim, van Noord, and van der Goot ran the same test on the actual, publicly distributed GoogleNews vectors, the ones millions of people have downloaded and used. They found the same collapse. Macro-accuracy under 3CosAdd fell from 0.71 with the exclusion enforced to 0.21 without it, and macro-accuracy under 3CosMul fell from 0.73 to 0.45.6 In most of the failures, the model's answer was simply the second input word handed back to the questioner.6

The same rule shapes a debate well outside the analogy literature. A bias analysis asking “man is to doctor as woman is to X” can never return “doctor” as X. That holds whatever the embedding actually encodes, because the code running the search has already ruled the input words out. Nissim and coauthors point out that the constraint is documented, in word2vec's own paper and in several papers that followed it, and still is not common knowledge among people running the test.6

The count hiding inside skip-gram

Negative sampling is a training shortcut, not an explanation of what the resulting vectors mean. Omer Levy and Yoav Goldberg went looking for one, in a separate paper, and found that skip-gram with negative sampling is, under the right conditions, doing something with a much older name: counting.7

Consider a large enough vector dimension, one big enough to let the model fit every word-context pair's target value exactly. At that size, the objective skip-gram with negative sampling optimizes has an exact solution, and that solution is not arbitrary.7 It equals a quantity computed straight from word co-occurrence counts in the training corpus, shifted by a constant fixed by how many negative samples the model draws:

\htmlClass{nb-mc1}{\vec{w}_i \cdot \vec{c}_j} = \htmlClass{nb-mc2}{\operatorname{PMI}(w_i, c_j)} - \htmlClass{nb-mc3}{\log k}
  • w⃗i · c⃗jThe dot product skip-gram's training actually optimizes, between a word i and a context word j.
  • PMI(wi, cj)Pointwise mutual information: how much more often i and j co-occur than independent counts would predict.
  • log kA constant set by k, the number of negative samples drawn per positive example.
At the objective's exact optimum, skip-gram's trained dot product equals a corpus co-occurrence statistic shifted by a constant the negative-sampling count sets.7

Pointwise mutual information is an old idea in distributional semantics, nothing more exotic than a ratio of counts. Levy and Goldberg's theorem says the vectors skip-gram spends its training budget arriving at are, at the mathematical optimum, a compressed encoding of that same ratio, for every word and context in the corpus at once.7

The theorem carries a condition the paper states itself. It holds exactly only when the dimension is large enough to reconstruct the full word-context matrix without loss, a condition real, low-dimensional word vectors do not meet. On the analogy task specifically, trained skip-gram clears an exact factorization of that same matrix by the paper's own correlation measure: 0.627 against 0.448 on the syntactic analogy set.7 The paper offers a conjecture for why, not a proof. Skip-gram's training weighs frequent word pairs more heavily than rare ones. An exact factorization of the matrix treats every pair the same.7

The picture of King, Man, Woman, and Queen as four points whose distances and directions can be read off directly still holds for describing what the search finds. It stops explaining why skip-gram's particular arrangement of those points beats a matrix built to hit the identical target on the analogy task. That gap stays open in the very paper that proved the two were connected in the first place.

What word2vec actually established

Word2vec's practical case rests on more than the King-Queen demo. Marco Baroni, Georgiana Dinu, and German Kruszewski ran an independent, much larger test in 2014. They trained 36 traditional count-based vector configurations against 48 predict-based ones, word2vec and its relatives among them, all on the same 2.8-billion-word corpus, and scored each across 14 separate tasks. Predict models won 13 of the 14, often by a wide margin, and the authors, who expected the older count methods to hold up, called the result a “thorough and resounding victory.”8

Levy and Goldberg's CoNLL paper, published the same year, complicates that victory rather than confirming it. Their own head-to-head, run on a shared corpus, put 3CosMul-scored count vectors essentially tied with skip-gram. On the GOOGLE analogy set specifically, count vectors even edged ahead, 68.24% to 66.72%. The paper says so directly: the result runs “contrary to the recent findings of Baroni et al. (2014).”4 Two papers, the same year, reached opposite conclusions from the same kind of test.

Levy, Goldberg, and Dagan's 2015 paper is often read as the resolution. Word2vec's own tooling popularized a set of hyperparameters: context distribution smoothing, dynamically sized windows, and more. Port those into the older count-based pipeline on equal terms, and “there is no consistent advantage to one algorithmic approach over another.”9 That is a careful, controlled result, and it is also the same two authors' account of a dispute they were already one side of. No outside group has run the adjudicating fourth experiment.

Verdict

Two things stay fixed across every source here. The architecture is cheap enough to train on a billion-plus words in about a day. And the resulting vectors are practically useful on ordinary similarity and category tasks, confirmed by a lab that trained on its own corpus, not word2vec's.8 Three things vary, and the analogy claim depends on all three. Which formula runs the search: 3CosAdd and 3CosMul flip which representation wins.4 Whether the three question words are barred from being the answer: removing that rule collapses 3CosAdd's accuracy from 0.71 to 0.21 on the paper's own test set.6 And whose hyperparameters the count-versus-predict comparison inherits: the closest thing to a resolution is one lab's account, not an outside referee's.9 The King − Man + Woman demo that carries the popular story is not even word2vec's demo. It is an earlier RNN paper's, rerun at scale.3 Word2vec itself established one thing nothing collected here overturns: removing a nonlinear hidden layer and training on far more data produces vectors good enough to win on nearly every practical benchmark tried against them since. It did not establish that linear offsets are a stable, general property of the space. What the demo shows is one scoring rule, applied to one excluded set, on one test.

Sources

  1. arXiv · Efficient Estimation of Word Representations in Vector Space (Mikolov, Chen, Corrado & Dean, 2013)
  2. arXiv · Distributed Representations of Words and Phrases and their Compositionality (Mikolov, Sutskever, Chen, Corrado & Dean, 2013)
  3. ACL Anthology · Linguistic Regularities in Continuous Space Word Representations (Mikolov, Yih & Zweig, NAACL-HLT 2013)
  4. ACL Anthology · Linguistic Regularities in Sparse and Explicit Word Representations (Levy & Goldberg, CoNLL 2014)
  5. ACL Anthology · Issues in Evaluating Semantic Spaces Using Word Analogies (Linzen, RepEval 2016)
  6. ACL Anthology · Fair Is Better than Sensational: Man Is to Doctor as Woman Is to Doctor (Nissim, van Noord & van der Goot, Computational Linguistics 2020)
  7. NeurIPS Proceedings · Neural Word Embedding as Implicit Matrix Factorization (Levy & Goldberg, NeurIPS 2014)
  8. ACL Anthology · Don't Count, Predict! A Systematic Comparison of Context-Counting vs. Context-Predicting Semantic Vectors (Baroni, Dinu & Kruszewski, ACL 2014)
  9. ACL Anthology · Improving Distributional Similarity with Lessons Learned from Word Embeddings (Levy, Goldberg & Dagan, TACL 2015)