GloVe › The Weighting Function
Language AI HandbookAll chapters GloVe › The Weighting FunctionOne section · Sections in this chapter4 / 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 weighting function must satisfy the properties listed above. The original GloVe paper proposes a specific polynomial form with a plateau:
where:
- : the co-occurrence count for the pair being weighted
- : the saturation threshold at which weight reaches its maximum of 1 (default: 100)
- : the exponent controlling how quickly weight grows with count (default: )
Let us unpack each design choice carefully, because together they handle several failure modes at once.
The saturation threshold : Co-occurrences above receive full weight 1. Below , weight scales polynomially from 0 to 1. This prevents very common co-occurrences, like "the" appearing with essentially every content word, from dominating the objective simply by virtue of their frequency. Without this cap, function words would drown out the signal from semantically rich but less frequent pairs. With the cap, every pair above contributes equally to the objective, and only pairs below the threshold get downweighted.
The exponent : This value is not arbitrary. It is the same exponent used in Word2Vec's negative sampling unigram distribution. Values close to 1 give nearly linear weighting (doubling the count roughly doubles the weight), while values close to 0 give more uniform weighting (the weight barely changes with count). The exponent is a middle ground: it penalizes very rare co-occurrences without being too aggressive. Empirically, it produces better embeddings than either (too linear) or (too flat). The value was tuned in the original paper across multiple downstream tasks.
Zero weight for zero co-occurrences: Because , pairs where never appear in the sum. This elegantly sidesteps the problem. You do not need to add a smoothing constant or handle zeros as a special case; the weighting function simply ignores them. In practice, the sum runs over the nonzero entries of , which is exactly the set of pairs that contain real information.
One subtlety: the choice of means that only pairs co-occurring at least 100 times receive full weight. For smaller corpora, you may need to lower this threshold. If your corpus has fewer than a million tokens, a threshold of 10 or 20 may be more appropriate.
import numpy as np
def glove_weight(x, x_max=100, alpha=0.75):
"""GloVe weighting function f(x)."""
return np.where(x < x_max, (x / x_max) ** alpha, 1.0)
x = np.linspace(0, 200, 500)
w = glove_weight(x)
The weighting function makes GloVe robust to two failure modes: rare co-occurrences that are dominated by noise, and very common co-occurrences that tend to reflect syntactic accidents rather than semantic relationships. The polynomial shape below means the transition from zero weight to full weight is smooth, which helps with gradient-based optimization.