A Word Is Its Friends, or How to Guess Meaning Without a Dictionary
Imagine your friend shows you an unknown word: "zythophile". You don't have a definition. But you see it used like this: "This zythophile loves breweries", "Zythophiles debate hops", "A true zythophile, he collects rare beers". After three sentences, you guess it's someone who loves beer, no dictionary needed, just context.
That's exactly Word2Vec's trick.
In 1957, linguist John Firth formulated this idea: you understand a word by its neighbors. Word2Vec (created by Tomas Mikolov at Google in 2013) translated this linguistic intuition into an algorithm: show a model enough text and it learns the "meaning" of words solely by looking at which words appear next to which others. The original paper reports good-quality vectors obtained "in less than a day" from a 1.6-billion-word data set, the only corpus figure its abstract actually gives.
Concrete example: "cat" and "dog" systematically appear in similar contexts, after "The", before "sleeps", next to "pet", "feed", "veterinarian". They are so contextually similar that the algorithm concludes: "These two words must have similar meanings." And it's right.
From Abstraction to Algebra: Word Embeddings
Before Word2Vec, the classic way to represent a word for a computer was one-hot encoding: "cat" = a list of 100,000 numbers, a single 1 at the position of "cat" and 99,999 zeros everywhere else. The problem? Any two words are always the same distance from each other. "Cat" and "dog" are just as far apart as "cat" and "philosophy". No notion of similarity.
Word2Vec does something radically different: it transforms each word into a list of numbers (a dense vector, also called an embedding, the word gets embedded in a geometric space) of small dimension. "Cat" is no longer an index, it's: [0.2, -0.5, 0.8, 0.1, -0.3, ...] across a few hundred dimensions. The vector sets Google released use 300 dimensions, and that number stuck as the convention.
Each dimension captures a "trait" of the word. We don't know exactly what each number means individually (it's learned automatically, not defined manually), but collectively, these 300 numbers encode the word's meaning in a way that's exploitable by math. Similar words end up close in this space, and different words are far apart. "Close" has a precise meaning here: see norms and distances.
The striking part: with these vectors, arithmetic on the numbers turns out to have semantic meaning. We come back to it below, with the caveats it deserves.
Efficient Estimation of Word Representations in Vector SpaceTwo Opposite Strategies: CBOW vs Skip-gram
Word2Vec offers two variants that approach the problem from opposite angles.
CBOW: Guessing the Middle Word
Imagine a game where you see a sentence with a hole: "The [???] black sleeps". You have to guess the missing word. It's easy: "cat", obviously.
CBOW (Continuous Bag of Words, where "bag of words" means you keep track of which words are present while throwing away their order) plays exactly this game. It takes the context words ["The", "black", "sleeps"], computes the average of their vectors, and uses this mean vector to predict the central word "cat". It's fast and natural.
But CBOW has a flaw: for a rare word, there are few training examples (few contexts where this word appears in the center), and the model learns its representation poorly. Frequent words are well represented, rare words poorly.
The Reverse Game: Skip-gram
Now, flip the game. You see the word "cat" and you have to guess each of its neighbors: "The", "black", "sleeps".
Skip-gram does exactly that. The name comes from gram, an item in the sequence, and skip: you look at neighbours while allowing yourself to skip over the words in between. For each neighbor, it's a separate prediction. This means a single word "cat" in the center generates multiple training examples (one per neighbor in the context window). And a rare word? Even if it appears infrequently, each appearance generates proportionally more examples.
Result: Skip-gram produces better embeddings for rare words. It's the most commonly used variant in practice.
In summary:
- CBOW: Context ["The", "black"] -> Average -> Predict "cat" (fast, good for frequent words)
- Skip-gram: Word "cat" -> Predict "The" (example 1), Predict "black" (example 2), Predict "sleeps" (example 3) (slower, better for rare words)
Not only does Skip-gram produce more training examples, but it forces the model to discriminate each contextual relationship individually. "The" has a subject-article relationship with "cat", while "black" is a descriptive adjective. Skip-gram captures these relational nuances that CBOW crushes by averaging.
Technical Corner: The Computational Problem, and the Trick That Saves Everything
To understand why Word2Vec was a breakthrough, you need to grasp the technical challenge it solved.
For each prediction, the model would ideally calculate a probability for every word in the vocabulary, say 100,000 words. The exact formula is a softmax, the function that turns a list of arbitrary scores into probabilities summing to 1:
Every symbol, one at a time. is the probability that the word we want is word number , given the context we observed, the vertical bar reads "given". is the candidate word's vector, the context's, and the dot between them is the dot product: multiply the coordinates pairwise and add them up. That number is larger when the two vectors point in the same direction, so it measures compatibility. is the exponential, which makes everything positive and crushes negative values toward zero. The big says "do the same for all 100,000 words in the vocabulary and add the results".
In one sentence: give every word in the vocabulary a compatibility score with the context, then divide the candidate's score by the sum of all scores to get a probability.
And there's the problem: the denominator needs a dot product and an exponential for each of the 100,000 words, for every word of every sentence in the corpus, billions of times over. Even on a graphics processing unit (GPU, the chip that runs neural networks), it's out of reach.
Negative Sampling: The Trick of the Century
Negative sampling bypasses this wall by completely reformulating the problem. The trick is not in the first Word2Vec paper but in the follow-up published the same year; paired with skip-gram it is so widespread that it goes by its initials, SGNS (skip-gram with negative sampling). It descends from an earlier statistical method, noise-contrastive estimation (NCE), of which it is a simplified version.
Distributed Representations of Words and Phrases and their Compositionality Instead of computing "which word is most probable among 100,000?", you ask a much simpler question:
"Do these two words actually appear together, or is it random noise?"
Concretely, for the real pair ("cat", "black"):
- Positive example: ("cat", "black", label=1), yes, they appear together
- Negative examples: ("cat", "apple", label=0), ("cat", "philosophy", label=0), ("cat", "staircase", label=0), randomly drawn, these are fake contexts
You generate 5 to 15 negative examples for each positive example. The model just learns a binary classification: real context or noise? It's a simple logistic regression instead of a softmax over 100,000 classes.
You can see the saving on the page: instead of 100,000 dot products per prediction, you do 1 for the positive plus 5 to 15 for the negatives, about sixteen at most. The ratio is 100,000 over 16, several thousand. In practice the real speedup is smaller, because other costs take over, but this is the trick that moved training from "months" to the "less than a day" the paper reports.
The Refinement: Don't Draw Negatives Uniformly
If you draw negative words completely at random (uniformly), you'll mostly draw "the", "of", "and", "a", ultra-frequent words. The model then learns a trivial distinction: "If it's a common word, it's probably noise." That's not useful.
Mikolov's solution: draw negatives according to a modified distribution:
The symbols: is the probability of drawing that word as a negative example, is its frequency in the corpus, and reads "is proportional to", everything is then normalised so the probabilities sum to 1. Read back: draw negatives roughly in line with their frequency, but flatten that frequency by raising it to the power 3/4.
Where does the flattening come from? A power below 1 compresses large numbers far more than small ones. Check it yourself: is 1,000, while is 8. So a word 625 times more frequent ends up only 125 times more likely to be drawn. Very frequent words stay over-represented, since they are useful as negatives, without swamping everything else.
With exponent 1 you would draw exactly in proportion to frequency: articles and prepositions would take nearly every draw, and the model would learn only a trivial distinction. With a smaller exponent you would approach uniform sampling and common words would lose their usefulness. The value 3/4 is not derived from theory: the authors say they picked it because it performed best in their experiments.
The Miracle of Vectors: The Algebra of Meaning
This is the most astonishing moment in the Word2Vec story. Once the vectors are trained, you can add and subtract word vectors and land on a word that makes sense:
How to read these lines: the arrows denote the words' vectors, addition and subtraction happen coordinate by coordinate, and does not mean "equals" but "the vocabulary word whose vector is closest to the result is this one". You compute a point in space, then look up its nearest neighbour among all words.
Nobody asked the model to learn analogies. No labels, no specific training examples. The model just observed contexts, and semantic relationships ended up encoded as geometric shifts.
It is the most-quoted illustration in the field, and its reproducibility is disputed. Vector arithmetic works well on some families of analogy (gender, country to capital, singular to plural) and fails on many others. On top of that, the standard protocol excludes the three input words from the answer: without that exclusion, the nearest neighbour of "king - man + woman" is often... "king". Treat these as good teaching intuitions, not as a reliable property to build a system on.
Why does it work? Because in the corpora, "king" and "queen" appear in very similar contexts (royalty, power, crown), and the difference between their vectors reflects exactly what distinguishes them: gender. This difference "king - queen" is approximately the same vector as "man - woman". Semantic relationships are encoded as directions in the vector space.
Certain semantic relationships are remarkably linear in the embedding space. Gender (man/woman), capital cities (country/capital), verb tense (present/past) manifest as coherent directions. Not all aspects of meaning are linear (some relationships are very non-linear), but enough to create these vector "magic tricks".
The Flip Side: Invisible Biases
The same mechanism reveals the prejudices hidden in the training corpus. The landmark example comes from a 2016 study of the Word2Vec vectors Google trained on news articles:
The corpus (the internet, newspapers, books) contains gendered occupational stereotypes, and Word2Vec faithfully learned and encoded them. That is useful for detecting a corpus's biases, since embeddings are a measurable mirror of them, but dangerous if you deploy the model untouched.
Man is to Computer Programmer as Woman is to Homemaker? Debiasing Word EmbeddingsThis discovery launched an entire field of research: debiasing embeddings, with techniques to identify and mitigate gender, origin, or other biases in vector representations. A caveat here too: later work showed that these techniques often hide the bias from the measurements without removing it from the representations.
Word2Vec doesn't invent anything. It looks at the corpus and faithfully reflects what it sees. If the corpus contains sexism, discrimination, misinformation, Word2Vec will learn and reproduce it. It's not the technology that's biased, it's the data. Hence the crucial importance of documenting training sources, measuring embedding biases, and implementing correction techniques.
Important Settings
Word2Vec's hyperparameters (the settings you fix yourself before training, as opposed to the parameters the model learns on its own) have a significant impact on embedding quality:
- Dimension (100-300): larger = more nuanced vectors but needs more data to fill them correctly. 300 is the standard.
- Context window (5-10): large window (10+) = the model captures thematic relationships (words about the same topic). Small window (2-3) = the model captures syntactic relationships (words that play the same grammatical role).
- Negative words (5-15): more negatives = better discrimination but slower training. 5 for large corpora, 15 for small ones.
- Subsampling of frequent words: "the", "of", "and" appear everywhere and provide no contextual information. Randomly ignoring them (with a probability proportional to their frequency) speeds up training and improves the quality of rare word embeddings.
The Limits of Word2Vec
Despite its brilliance, Word2Vec has four fundamental limitations:
- One vector per word (no context): "bank" (the financial institution) and "bank" (the riverbank) have the same embedding. The model makes a kind of "average" of both meanings. Contextual models, BERT first among them, solve this by giving a different vector for each occurrence.
- Closed vocabulary: a word not seen during training simply has no embedding, it is out-of-vocabulary (OOV) and there is no fallback. FastText solves this with subwords (character n-grams, i.e. runs of n consecutive letters).
- Local window only: Word2Vec only looks at the 5-10 words around. GloVe exploits co-occurrence statistics across the entire corpus.
- No composition: Word2Vec gives vectors for words, not for sentences or documents. Combining word vectors into a sentence vector (by averaging, for example) loses a lot of information.
Why This Matters
Word2Vec fundamentally changed the way natural language processing (NLP) thinks about words. Before 2013: words were isolated categories, indexes in a dictionary. After: words are vectors in a continuous space, and you can do math on them. This paradigm shift unlocked everything.
What survives of Word2Vec in today's models is the idea: represent meaning as a dense vector learned from context. That idea is everywhere. Word2Vec's way of doing it, however, has been replaced.
Word2Vec produces static embeddings: one word, one vector, fixed forever. Nobody builds a language-understanding system that way any more. Contextual representations from transformers (BERT, then the embedding models that succeeded it, see text embeddings) give each occurrence of a word its own vector depending on the sentence, and have displaced static embeddings on every task where quality matters. Read this lesson to understand where the idea came from, not to pick a tool. Negative sampling, on the other hand, got a second life: it is still at the heart of contrastive training for modern embedding models.
Without Word2Vec to show that it could work, nobody would have had the idea to try.
1. Why does Skip-gram produce better embeddings than CBOW for rare words?
2. Which computational wall does negative sampling knock down?
3. What should you know before quoting the famous king minus man plus woman equals queen?
4. Avocado the fruit versus advocate the lawyer, in French, one word, avocat. What does Word2Vec do with the two senses?