GloVe Embeddings
How can we learn word embeddings that effectively combine local context with global co-occurrence statistics? GloVe embeddings address this by integrating both local window-based information and overall corpus statistics. Traditional methods like Word2Vec excel at capturing local context through skip-gram or CBOW models, while techniques such as Latent Semantic Analysis (LSA) focus on global patterns. GloVe synthesizes these two perspectives, aiming for richer semantic representations that leverage the strengths of both.
The Power of Co-occurrence Counts
The core intuition behind GloVe is that ratios of co-occurrence probabilities carry more semantic meaning than the probabilities themselves. Consider two words, 'ice' and 'steam,' and a set of probe words like 'solid,' 'gas,' and 'water.' The raw probability might be high, and also high. However, comparing to reveals a stark difference.
This ratio, , would be very large, indicating 'solid' is strongly associated with 'ice' but not 'steam.' Conversely, would be very small. For a word like 'water,' which relates to both, the ratio would be close to 1. These ratios effectively encode the semantic relationships between words.
| Probe Word (k) | Ratio | ||
|---|---|---|---|
| solid | 0.85 | 0.03 | 28.33 |
| gas | 0.02 | 0.78 | 0.03 |
| water | 0.60 | 0.55 | 1.09 |
| fashion | 0.01 | 0.01 | 1.00 |
The GloVe Objective Function
The GloVe model minimizes the following cost function:
Where:
- is the size of the vocabulary.
- is the number of times word and word co-occur.
- and are the word vectors for word and context word , respectively.
- and are the bias terms for word and context word .
- is a weighting function that gives less weight to very rare or very frequent co-occurrences.
The GloVe objective function is designed to learn word vectors such that their dot product effectively predicts the logarithm of their co-occurrence probability. The term represents the dot product between the word vector and the context word vector . This dot product is intended to approximate , which is related to .
Bias terms, and , are included to account for inherent biases of words, independent of their specific context. For instance, some words might be generally more frequent or appear in more diverse contexts. The weighting function is crucial; it assigns higher weights to meaningful co-occurrences while down-weighting very rare pairs (which might be noise) and very frequent pairs (which might not carry much specific information, like stop words). This function typically increases monotonically but saturates for large values.
GloVe vs. Word2Vec: A Head-to-Head
| Feature | Word2Vec | GloVe |
|---|---|---|
| Input/Data Source | Local context windows (sentences) | Global co-occurrence matrix |
| Model Type | Predictive (neural network based) | Count-based (matrix factorization) |
| Information Captured | Local syntactic and semantic relationships | Global semantic relationships via co-occurrence ratios |
| Training Mechanism | Trains on individual word pairs/windows using SGD | Trains on non-zero entries of co-occurrence matrix using AdaGrad |
| Strengths | Captures nuanced local context, computationally efficient for large corpora | Leverages global statistics, often better for analogy tasks, faster training on smaller corpora |
| Weaknesses | Does not explicitly use global statistics, can be slower for very large vocabularies | Requires building a co-occurrence matrix first, which can be memory-intensive for huge vocabularies |
Putting GloVe to Work
GloVe learns word embeddings by leveraging global word-word co-occurrence statistics.
The core idea is that ratios of co-occurrence probabilities encode semantic relationships more effectively than raw probabilities.
The GloVe objective function minimizes the squared difference between the dot product of word vectors and the logarithm of their co-occurrence count, incorporating bias terms and a weighting function.
GloVe combines the benefits of local context (like Word2Vec) with global statistical information (like LSA) into a single model.
Compared to Word2Vec, GloVe is a count-based model that can be more efficient for certain tasks and often performs well on analogy tasks.
Pre-trained GloVe embeddings are readily available and can be used to find word similarities and perform semantic analogies, directly addressing how to combine local context with global co-occurrence statistics for rich word representations.