GloVe: Global Vectors for Word Representation
GloVe (Global Vectors for Word Representation) is an unsupervised learning algorithm that produces dense vector embeddings for words by factorizing a global word–word co-occurrence matrix, capturing both local context statistics and corpus-wide semantic structure in a single model. It matters because its embeddings encode geometric analogies — king − man + woman ≈ queen — that downstream NLP models can exploit without task-specific supervision. The counterintuitive fact: GloVe never directly predicts words from contexts; instead it regresses on the logarithm of co-occurrence counts, making it a weighted least-squares problem rather than a language model.
The key insight is that ratios of co-occurrence probabilities carry more semantic signal than raw probabilities. If you compare how often "ice" vs. "steam" co-occurs with "solid", "gas", "water", and "fashion", the ratios cleanly discriminate relevant from irrelevant dimensions — "solid/ice" is large, "solid/steam" is small, "water" is neutral for both, and "fashion" is near 1.0 for both. GloVe trains word vectors so that their dot product equals the log co-occurrence probability, meaning the vector geometry directly encodes these ratios. The "aha moment": corpus-level statistics are fully precomputed into a matrix, and training becomes a surprisingly simple weighted regression on that matrix.
How It Works
Step 1 — Build the Co-occurrence Matrix
For a corpus with vocabulary size , define as the number of times word appears in the context of word (within a symmetric window of size , typically 10). Define:
Explanation: is the empirical probability that word appears in the context of word , computed by normalizing raw co-occurrence counts by the total context count for word .
Symbols: — raw co-occurrence count; — total number of context words for word ; — conditional co-occurrence probability.
Step 2 — The Ratio Motivation
For two probe words (ice) and (steam) and a context word :
Explanation: This ratio is large when is strongly associated with but not , near 1 when is equally associated with both, and small when associates with but not .
Symbols: — probability of context given word ; — the discriminative ratio that the model is designed to encode.
Step 3 — The Dot-Product Objective
The authors argue should be computable from word vectors alone. Requiring leads to:
Explanation: The dot product of a word's target vector and a context vector, plus scalar biases, should reconstruct the log co-occurrence count — this is the fundamental regression equation GloVe trains to satisfy.
Symbols: — target vector for word ; — context vector for context word ; — scalar bias terms; — embedding dimension (typically 50–300).
Step 4 — The Weighted Least-Squares Loss
Not all co-occurrences are equally informative. Rare pairs may be noisy; very frequent pairs (stop-words) dominate. GloVe downweights both extremes with a weighting function:
Explanation: This is the training objective — a weighted sum of squared residuals between predicted and actual log co-occurrences, where controls how much each word pair contributes to the gradient.
Symbols: — scalar loss; — weighting function; the squared term — residual between model prediction and target log count.
Step 5 — The Weighting Function
Explanation: Pairs with fewer than co-occurrences are downweighted polynomially, preventing the loss from being dominated by either very rare or very frequent word pairs.
Symbols: — saturation threshold (default 100); — exponent (default 0.75, empirically chosen); — the weight applied to each word pair's squared error.
Final Embeddings
After training, the final word vector is taken as (sum of target and context vectors), which empirically reduces noise and improves downstream performance. ```python import torch import torch.nn as nn class GloVe(nn.Module): """Minimal GloVe implementation in PyTorch.""" def __init__(self, vocab_size: int, embed_dim: int = 100): super().__init__()
# Target and context embeddings + biases self.W = nn.Embedding(vocab_size, embed_dim) # w_i self.W_tilde = nn.Embedding(vocab_size, embed_dim) # w̃_k self.b = nn.Embedding(vocab_size, 1) # b_i self.b_tilde = nn.Embedding(vocab_size, 1) # b̃_k nn.init.uniform_(self.W.weight, -0.5/embed_dim, 0.5/embed_dim) nn.init.uniform_(self.W_tilde.weight, -0.5/embed_dim, 0.5/embed_dim) nn.init.zeros_(self.b.weight) nn.init.zeros_(self.b_tilde.weight) def forward(self, i_idx, k_idx, log_x_ik, weight): """ i_idx, k_idx : (batch,) word and context indices log_x_ik : (batch,) log co-occurrence counts [target] weight : (batch,) f(X_ik) weighting values """ dot = (self.W(i_idx) self.W_tilde(k_idx)).sum(dim=1) # w_i · w̃_k pred = dot + self.b(i_idx).squeeze() + self.b_tilde(k_idx).squeeze() loss = weight (pred - log_x_ik) ** 2 # Eq. [4] return loss.mean() def get_embedding(self, idx: torch.Tensor) -> torch.Tensor: """Return combined target + context vector (Eq. [3] best practice).""" return self.W(idx) + self.W_tilde(idx)
def weighting_fn(x: torch.Tensor, x_max: float = 100.0, alpha: float = 0.75) -> torch.Tensor: """Implements Eq. [5]: f(x) = min(1, (x/x_max)^alpha).""" return torch.clamp((x / x_max) ** alpha, max=1.0) ```
Jeffrey Pennington is a research scientist at Google Brain with a background in theoretical physics (Stanford PhD), which directly influenced GloVe's analytical, matrix-factorization perspective on word embeddings rather than a purely neural one. He led the 2014 Stanford team that published GloVe, specifically deriving the ratio-based motivation and the weighted least-squares formulation that distinguished it from both pure matrix factorization (LSA) and predictive models (Word2Vec). Surprisingly, Pennington has since moved significantly into studying the theoretical properties of neural networks through random matrix theory, a field quite distant from NLP.
Richard Socher completed his Stanford PhD under Christopher Manning and Andrew Ng, becoming one of the most-cited NLP researchers of his generation through work on recursive neural networks and sentiment analysis. He co-authored the original GloVe paper and contributed the large-scale evaluation framework — the word analogy and similarity benchmarks — that became standard practice for comparing embedding methods. Socher later founded MetaMind, which was acquired by Salesforce in 2016 for a reported $32.8 million, making him one of the wealthiest academic-turned-industry NLP researchers of his era.
Intuition
Imagine you have a massive spreadsheet where every row is a word and every column is also a word. Each cell records how often word and word appeared near each other in a billion-word corpus. The spreadsheet is a fingerprint of the language. GloVe's job is to compress this enormous, sparse table into small, dense vectors — say 300 numbers per word — in a way that preserves the most meaningful patterns. The trick is to focus not on the raw counts but on log ratios: if "ice" co-occurs much more with "solid" than "steam" does, that ratio should be visible as a direction in vector space. Training is just adjusting vectors until each pair's dot product matches the log of their co-occurrence count — like fitting a linear model, but the "features" are the learned vectors themselves. The geometric result is that analogical relationships become parallelograms: the vector offset "king → queen" is approximately the same as "man → woman" because the gender-related co-occurrence ratios shift in exactly the same way.
Historical Development
Origins · 1 minhow this was discovered
Why It Matters
Prerequisites
What This Leads To
See Also
Word2Vec: Skip-Gram and CBOW · Pointwise Mutual Information (PMI) · Latent Semantic Analysis · FastText Word Embeddings · ELMo: Contextual Word Embeddings