Sub topic 13
word2vec versus GloVe
Prerequisites and the central difference
This chapter assumes you know vectors, dot products, norms, conditional probability, loss functions, gradient descent, and basic tokenization. You should also know that an embedding is a dense vector learned for each word.
Both word2vec and GloVe place words with similar usage near one another. They use different training signals:
- word2vec learns by predicting local context words from target words, or target words from context words.
- GloVe learns by fitting the global counts of how often words appear together across a corpus.
The distinction is useful when choosing a model, interpreting its behavior, or explaining why two pretrained embeddings differ.
How the training signals differ
In word2vec, a sliding window creates training examples. For the sentence “the cat sits on the mat” with a small window, the pair (cat, the) may be positive because the words occur nearby. Skip-gram predicts context words from the center word. CBOW predicts the center word from several context words.
GloVe first builds a word-context matrix. An entry X[i, j] records how often word j appears near word i, often giving closer words larger weights. It then learns vectors whose dot products approximate the logarithm of these counts.
# Conceptual comparison of the learned signals
word2vec_example = ("cat", "the") # a local prediction pair
glove_example = ("cat", "the", 12.5) # a global weighted count
print(word2vec_example)
print(glove_example)Cost and practical behavior
| Aspect | word2vec | GloVe |
|---|---|---|
| Main signal | Local prediction events | Global co-occurrence counts |
| Common optimization | Negative sampling or hierarchical softmax | Weighted least squares |
| Data structure | Stream of training pairs | Co-occurrence matrix |
| Strength | Efficient online training and useful local relationships | Direct use of global corpus statistics |
| Typical concern | Results depend on windows, negatives, and random seed | Matrix construction can require substantial memory |
Negative sampling makes word2vec cheaper than calculating a full softmax over every vocabulary word. For one positive pair, it trains against a small number of randomly selected negative words. GloVe avoids repeated prediction over the full vocabulary, but constructing and storing the co-occurrence matrix can be expensive for a large vocabulary.
Neither method is universally better. Window size, corpus size, vocabulary filtering, subsampling, vector dimension, and evaluation task often matter more than the algorithm name. Both usually produce similar broad relationships when trained on comparable data.
Choosing and evaluating an embedding
Use word2vec when simple streaming training, local context, or an established implementation is important. Use GloVe when explicit global co-occurrence statistics are useful or when you want to inspect the count-based training signal. Compare models with the same vocabulary and dimension when possible.
Intrinsic tests measure the vectors directly, such as word similarity correlations or analogy accuracy. Extrinsic tests insert the vectors into a downstream classifier or sequence model. A model can perform well on analogies yet fail on your application because of domain mismatch, polysemy, or social bias.
Exercise
Why can word2vec and GloVe produce similar neighbours even though their objectives differ?
Show answer
Both learn from distributional evidence: words used in similar contexts receive similar vector representations, even though word2vec predicts local events and GloVe fits global co-occurrence counts.