GloVe › Deriving the GloVe Objective
Language AI HandbookAll chapters GloVe › Deriving the GloVe ObjectiveOne section · Sections in this chapter3 / 13 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
The derivation starts from the ratios and works backward to a tractable optimization objective. Each step follows necessarily from a design choice, so the final formula is not arbitrary: it is the natural consequence of the ratio insight combined with a small set of reasonable constraints.
Starting from Co-Occurrence Ratios
We want word vectors , , and such that some function of these vectors recovers the ratio:
where:
- : the word vector for word (the first target word)
- : the word vector for word (the second target word we are comparing against)
- : the vector for the probe word
- : the conditional probability of seeing in the context of
We want this function to depend on the difference , because we are comparing two target words and the comparison should be captured as a vector difference. The simplest way to combine a difference vector with a third vector is via a dot product:
Here is a separate vector for word when it is a context word, distinct from when is the target word. This distinction is standard in embedding models: each word plays two roles (as a target and as a context), and the two roles are learned separately. Using separate vectors for the two roles avoids conflating them and is a key part of why the derivation works out cleanly.
Solving for the Functional Form
We need to satisfy the ratio decomposition property. When we expand the ratio , we are taking the ratio of two quantities that each involve a single target word and the probe word . So we need:
This is a functional equation: we need a function such that for all and . The exponential function satisfies this exactly, since:
This is the only continuous function (up to a constant multiplier) that converts subtraction into division. The uniqueness here is reassuring: we are not choosing arbitrarily, it is forced by the design requirement.
Plugging in and setting the result equal to the true ratio gives us, for each individual word pair :
Taking the natural logarithm of both sides:
The term depends only on word , not on the context word . It represents word 's overall frequency as a context center: a word that appears in many contexts has a large . We can absorb this word-frequency effect into a scalar bias learned during training. Similarly, by symmetry, we add a context bias for word 's frequency as a context word:
where:
- : a scalar bias for word that absorbs its context frequency
- : a scalar bias for word in its role as a context word
The context bias is not strictly required by the derivation, but it restores symmetry. Because for symmetric windows, both the target role and the context role of each word should have their own frequency-absorbing bias. Adding makes the formulation symmetric in the roles of target and context.
This equation is the core relationship GloVe trains for. We want, for every word pair , the model's prediction to equal the corpus-derived target .
The Weighted Least Squares Objective
We want our word vectors and biases to satisfy for all pairs. The natural formulation is a least squares objective over all word pairs:
But this treats all co-occurrence pairs equally, and that creates two serious problems. First, rare co-occurrences (small ) are statistically noisy. If "quasar" and "kumquat" appeared together once in a 100-billion-token corpus, that single co-occurrence is almost certainly an accident, not evidence of a semantic relationship. Yet the unweighted objective would treat this pair as equally important as "cat" co-occurring with "dog" 10,000 times. Second, most entries of are zero (words that never co-occurred), and is undefined, so the plain objective is not even computable.
The solution is to weight each term by a function that satisfies four properties:
- Zero co-occurrences get zero weight, so never appears in the sum
- Rare co-occurrences get lower weight, reducing the influence of statistical noise
- Very frequent co-occurrences do not get excessive weight (stop words like "the" co-occur with almost everything, but without a semantic relationship)
- The function is continuous and non-decreasing
This gives the final GloVe objective:
where:
- : the weighting function that scales each term's contribution by the reliability of the co-occurrence count
- : the model's prediction of
- : the target value derived from the corpus
This is the weighted least squares objective that GloVe minimizes. Because , the sum effectively runs only over pairs where . For large vocabularies this is a small fraction of all pairs, making the sum tractable.