ElemedexA pocket encyclopedia of AI architectures
No. 019

word2vec

Skip-gram · CBOW (word to vector)

Good Company

It never read a definition: it learned each word by watching the company it keeps. It does sums with kings and queens, but the trick has fine print: it is not allowed to answer with the words in the question. And it has a single face for “bank,” whether of river or of money.

Height
1 linear projection, no hidden layer
Weight
≈ 3.6 GB (fp32, Google News vectors)
Parameters
2 matrices V × d · 3 M × 300 = 900 M (released vectors)
Context
±4 (CBOW) to ±10 (skip-gram) words
Training data
Google News: ≈ 6,000 M tokens (paper); > 100,000 M words (released vectors)
Year
2013
Generation
3 · Deep learning
Creators
Mikolov, Chen, Corrado & Dean (Google)
Kind
Model

Base stats

Total
230

Approximate, ordinal scales meant for comparing species with each other; the hard numbers are in the data sheet.

Weaknesses

  • A single vector per word: it cannot tell the senses of “bank” or “bat” apart.
  • It ignores word order and does not compose phrase meanings.
  • It has no vector for words it never saw in training.
  • It absorbs the stereotypes of the corpus it was trained on.

Habitat

It grew up reading the news: an internal Google News corpus. Between 2013 and 2018, its vectors (or those of its cousin GloVe) were the usual front door of neural language networks. Today it survives in recommender systems (songs treated as words, playlists as sentences), in the digital humanities, where it is used to track shifts in meaning across decades, and in introductory courses.

Moves

Abilities

Shallowness
No nonlinear hidden layer: a log-linear model, less expressive than its predecessors but able to train on billions of words.
Learning by contrast
Instead of choosing among the whole vocabulary, it tells real neighbors apart from randomly drawn words.
Linear regularities
Some relations (country–capital, adjective–superlative) show up as roughly constant offsets in the space.

Anatomy

W is keptW is keptw(t−2)w(t−1)w(t+1)w(t+2)Look up vectors (matrix W)Average:bag ofwordsPredicts w(t)w(t): “king”Vector of w(t) (matrix W)Real neighbor:“crown”k random wordsDot product with W′Neighbor or noise? (yes/no)V × d table of vectorsking − man + woman ≈ ?CBOWSkip-gram (negative sampling)What is kept

The two word2vec architectures. CBOW averages the neighbors and predicts the middle word; skip-gram starts from the middle word and, in the negative-sampling version, learns to tell real neighbors from random words. After training, the task is thrown away and the matrix W is kept: one row per word.

Evolution chain

019 word2vec
  • context: one vector per occurrence, from a bidirectional LSTM026 ELMo

word2vec is a method for turning every word in a vocabulary into a vector of a few hundred numbers, so that words appearing in similar contexts end up close to one another. It neither writes nor classifies: its product is a table of embeddings, one row per word, meant as raw material for other systems. The name covers two architectures that Mikolov and colleagues presented at Google in 2013, CBOW and skip-gram (Mikolov, Chen, et al., 2013).

How it works

A window slides over the text. In CBOW (continuous bag of words), the vectors of the neighboring words are averaged and the model tries to guess the word in the middle; since they are averaged, order does not matter: hence the "bag of words." Skip-gram does the reverse: from the middle word it predicts the neighbors (Mikolov, Chen, et al., 2013, secs. 3.1–3.2). Nobody labels anything: the text itself supplies the answers (self-supervised learning).

The decisive move was to take things away. The neural language model of Bengio et al. (2003) learned word vectors together with a nonlinear hidden layer, where almost all the computation went. Mikolov and colleagues removed it: a less expressive model, but one that could be trained on vastly more data (2013, sec. 3). A few months later the same team also replaced the expensive softmax over the whole vocabulary with a yes-or-no question: is this word a real neighbor or one drawn at random? This negative sampling is an early form of contrastive learning (Alammar & Grootendorst, 2024, pp. 64–65, 293). In the end, the prediction task is thrown away and the input weight matrix is kept: each row is the vector of one word (M. Mitchell, 2019, ch. 11).

The corpus was Google News, about 6 billion tokens, with a vocabulary of one million words (Mikolov, Chen, et al., 2013, sec. 4.2); the best skip-gram (1,000-dimensional vectors) trained in about two and a half days on ≈ 125 CPU cores (2013, sec. 4.4). The team then released the code and vectors trained on more than 100 billion words (2013, sec. 7).

What changed

In a one-hot encoding, each word is an arbitrary index: nothing says that hated and abhorred are alike. With word2vec, likeness is an angle between vectors (cosine similarity), and the neighbors of France turn out to be other European countries although nobody ever taught it what a country is (M. Mitchell, 2019, ch. 11). A space of this kind can be explored in the embeddings lab.

What drew the most attention were the linear regularities: vector(biggest) − vector(big) + vector(small) lands near smallest, and something similar happens with countries and capitals (Mikolov, Chen, et al., 2013, sec. 4). To measure this, the authors built a benchmark of 8,869 semantic and 10,675 syntactic questions (2013, sec. 4.1). (The famous king − man + woman ≈ queen came from earlier work with vectors taken from a recurrent network (2013, secs. 1.1, 4.3).)

Until 2018, vectors like these were the usual input of nearly every language system (M. Mitchell, 2019, ch. 11); the encoders of Seq2seq could take them as input (Alammar & Grootendorst, 2024, p. 12), and the recipe was exported to other domains, such as recommending songs by treating them as words (2024, p. 67). Levy & Goldberg (2014) showed that skip-gram with negative sampling implicitly factorizes a matrix of co-occurrences weighted by mutual information: the old count-based distributional semantics in new clothes.

Limits

Sources

  • Alammar, J., & Grootendorst, M. (2024). Hands-on large language models: Language understanding and generation. O’Reilly Media. §
  • Bender, E. M., & Koller, A. (2020). Climbing towards NLU: On meaning, form, and understanding in the age of data. In D. Jurafsky, J. Chai, N. Schluter, & J. Tetreault (Eds.), Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics (pp. 5185–5198). Association for Computational Linguistics. https://doi.org/10.18653/v1/2020.acl-main.463 §
  • Bengio, Y., Ducharme, R., Vincent, P., & Jauvin, C. (2003). A neural probabilistic language model. Journal of Machine Learning Research, 3, 1137–1155. https://www.jmlr.org/papers/v3/bengio03a.html §
  • Brandom, R. B. (2000). Articulating reasons: An introduction to inferentialism. Harvard University Press. §
  • Brunila, M., & LaViolette, J. (2022). What company do words keep? Revisiting the distributional semantics of J.R. Firth & Zellig Harris. In M. Carpuat, M.-C. de Marneffe, & I. V. Meza Ruiz (Eds.), Proceedings of the 2022 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies (pp. 4403–4417). Association for Computational Linguistics. https://doi.org/10.18653/v1/2022.naacl-main.327 §
  • Buckner, C. J. (2024). From deep learning to rational machines: What the history of philosophy can teach us about the future of artificial intelligence. Oxford University Press. https://doi.org/10.1093/oso/9780197653302.001.0001 §
  • Firth, J. R. (1957). A synopsis of linguistic theory, 1930–1955. In Studies in linguistic analysis (pp. 1–32). Blackwell. §
  • Harris, Z. S. (1954). Distributional structure. Word, 10(2–3), 146–162. https://doi.org/10.1080/00437956.1954.11659520 §
  • Levy, O., & Goldberg, Y. (2014). Neural word embedding as implicit matrix factorization. In Advances in Neural Information Processing Systems (Vol. 27). Curran Associates. https://proceedings.neurips.cc/paper_files/paper/2014/hash/b78666971ceae55a8e87efb7cbfd9ad4-Abstract.html §
  • Linzen, T. (2016). Issues in evaluating semantic spaces using word analogies. In Proceedings of the 1st Workshop on Evaluating Vector-Space Representations for NLP (pp. 13–18). Association for Computational Linguistics. https://doi.org/10.18653/v1/W16-2503 §
  • Mikolov, T., Chen, K., Corrado, G., & Dean, J. (2013). Efficient estimation of word representations in vector space (arXiv:1301.3781). arXiv. https://doi.org/10.48550/arXiv.1301.3781 §
  • Mikolov, T., Sutskever, I., Chen, K., Corrado, G. S., & Dean, J. (2013). Distributed representations of words and phrases and their compositionality. In Advances in Neural Information Processing Systems (Vol. 26). Curran Associates. https://proceedings.neurips.cc/paper_files/paper/2013/hash/9aa42b31882ec039965f3c4923ce901b-Abstract.html §
  • Mitchell, M. (2019). Artificial intelligence: A guide for thinking humans. Pelican Books. §
  • Nissim, M., van Noord, R., & van der Goot, R. (2020). Fair is better than sensational: Man is to doctor as woman is to doctor. Computational Linguistics, 46(2), 487–497. https://doi.org/10.1162/coli_a_00379 §
  • Wittgenstein, L. (2009). Philosophical investigations (G. E. M. Anscombe, P. M. S. Hacker, & J. Schulte, Trans.; P. M. S. Hacker & J. Schulte, Eds.; Rev. 4th ed.). Wiley-Blackwell. (Original work published 1953) §