Vibe Engines
YouTube

Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path

~10 min read2014

Global
vectors.

Meaning lives in company: you know a word by the words it keeps. Count how often every word appears beside every other across a whole corpus and you get a giant table of co-occurrences — the raw distributional fingerprint of a language. GloVe's move is to squeeze that table into short vectors so that a simple dot product reproduces the log of each count. The result is a geometry where "king" minus "man" plus "woman" lands near "queen." Not by prediction over a sliding window like word2vec, but by fitting the global statistics directly. Here's the weighted least-squares objective, the weighting function that keeps "the" from swamping everything, and why the log matters.

The delta

What changes against word2vec: fit the statistics directly

Rung 1 learns by streaming over a corpus and sampling local windows, so it sees the co-occurrence statistics implicitly, a few pairs at a time, and many times over. This rung's change is to compute those statistics once, globally, into a co-occurrence matrix, and then fit vectors to the matrix directly.

The argument for why that is the right target is the rung's actual content. Raw co-occurrence counts are a poor thing to model — "ice" and "steam" both co-occur heavily with "water", which says little. What discriminates is the ratio: "solid" co-occurs far more with "ice" than with "steam", and "gas" the other way round, while a neutral word like "water" has a ratio near one. Meaning lives in ratios of co-occurrence probabilities, and since a ratio is a difference of logarithms, the natural objective is to make a dot product of two vectors recover the log co-occurrence count. That is what turns an intuition into a loss.

Two details matter in practice. The fit is weighted least squares rather than plain, because the matrix spans many orders of magnitude and the very frequent pairs would otherwise dominate everything — the weighting function rises and then flattens, so common pairs stop gaining influence past a threshold and the extremely rare ones, which are mostly noise, are discounted. And because the statistics are gathered first, training is a fit to a fixed object rather than a pass over text, which parallelises differently.

01

Meaning by company

The distributional hypothesis says a word's meaning is revealed by the words it appears near. Make that concrete: scan a huge corpus and build a co-occurrence matrix X, where X_ij is the number of times word j shows up in the context of word i. That matrix is enormous and sparse, but it holds the entire distributional signature of the vocabulary — everything statistics can tell you about how words relate.

GloVe (Global Vectors, Pennington, Socher & Manning, 2014) turns that table into short dense vectors. It learns a vector for each word such that the dot product of two word vectors (plus a couple of bias terms) approximates the logarithm of their co-occurrence count. Fit that across all nonzero entries and you get embeddings where similar words cluster and where vector differences encode relationships. Unlike word2vec, which streams the corpus predicting local windows, GloVe aggregates the whole corpus into X first and then factorizes it — global statistics, used explicitly.

The one-sentence version

Learn word vectors so that w_i · w̃_j + b_i + b̃_j ≈ log(X_ij) across all co-occurring word pairs, minimizing a weighted least-squares loss whose weighting f(X_ij) caps frequent pairs and ignores unseen ones.

02

Ratios carry meaning

Why fit the log of the counts, rather than the counts themselves? GloVe's central observation is that the useful information isn't in a single co-occurrence probability but in the ratio of two. Take the words ice and steam. Both co-occur with water (they're both about H₂O), and both co-occur rarely with fashion. Neither raw count distinguishes them. But probe with solid: it appears much more with ice than with steam. Probe with gas: the reverse. The ratio P(solid | ice) / P(solid | steam) is large; P(gas | ice) / P(gas | steam) is small. Those ratios are where the meaning lives.

Ratios are multiplicative, and a vector space is additive — dot products add and subtract, they don't divide. Taking logs bridges the two: a ratio of probabilities becomes a difference of logs, and a difference of logs can be modeled by a difference of dot products. So fitting w_i · w̃_j ≈ log(X_ij) is precisely the design that lets vector arithmetic capture co-occurrence ratios — and, as a bonus, the linear analogies (king − man + woman ≈ queen) that made word embeddings famous. The log isn't cosmetic; it's the hinge that turns statistics into geometry.

03

The weighting function

A plain least-squares fit on log(X_ij) has two problems, and one weighting function f(x) fixes both:

f(x) = (x/x_max)^α for x < x_max, else 1
x = 0f(0) = 0 — unseen pairs contribute nothing; the sum skips the vast empty matrix.
small xRare pairs are downweighted — noisy, unreliable counts don't dominate.
x ≥ x_maxFrequent pairs are capped at weight 1 — "the" doesn't swamp the loss.
α = 0.75The exponent shapes the ramp; the paper used α = 0.75, x_max = 100.

Without weighting, the two extremes wreck the fit. Extremely common pairs — every content word with the, of, and — would contribute overwhelming error and pull all the vectors toward modeling function words. Meanwhile rare pairs, whose counts are just noise, would be treated as equally important as reliable ones. The weighting f(x) ramps up for rarer-but-real pairs, saturates to 1 above a cap so hyper-frequent pairs can't dominate, and — the quietly crucial part — is exactly zero at x = 0, so the loss only ever sums over the small fraction of word pairs that actually co-occur. That's what makes fitting a vocabulary-squared matrix tractable.

04

The objective

GloVe minimizes a single weighted least-squares loss over all word pairs:

Each term pulls the dot-product-plus-biases toward the log co-occurrence, weighted by f(X_ij). w_i and w̃_j are the "word" and "context" vectors (the final embedding is usually their sum); b_i, b̃_j are learned biases that absorb per-word frequency.

Read it as a regression: the target is log X_ij, the prediction is w_i·w̃_j + b_i + b̃_j, the residual is squared, and each residual is scaled by f(X_ij). Two learned bias terms per word soak up the fact that some words are just more frequent than others, so the dot product is free to capture the interesting relational structure. Training is stochastic gradient descent with the AdaGrad step-size rule over only the nonzero entries. The runnable version below computes the weighting, the prediction, and a single weighted loss term — the whole objective in miniature.

How it works

How GloVe builds its matrix and fits it

GloVe (Pennington, Socher and Manning, EMNLP 2014) runs in two phases that never overlap: one pass over the corpus to count, then many passes over the counts to fit. The fitting phase never looks at text again, which is the practical difference from word2vec, a method that keeps re-reading the corpus window by window.

probe word k P(k|ice) ÷ P(k|steam) solid ≫ 1, large gas ≪ 1, small water ≈ 1 fashion ≈ 1 w̃ water, fashion: dot ≈ 0 w̃ solid: dot positive w̃ gas: dot negative w(ice) − w(steam) fit: (w(ice) − w(steam)) · w̃(k) ≈ log P(k|ice) − log P(k|steam)
The ratio that GloVe is built to reproduce: a probe word that prefers ice points along w(ice) − w(steam), one that prefers steam points against it, and a neutral word is perpendicular, so the dot product carries the log ratio.
  1. Tokenise and fix the vocabulary. The paper lowercased and tokenised each corpus with the Stanford tokenizer and kept the 400,000 most frequent words. Corpora ranged from a one-billion-token 2010 Wikipedia dump to 42 billion tokens of Common Crawl (an 840-billion-token corpus was trained too, without lowercasing), and a six-billion-token combination of Wikipedia 2014 and Gigaword 5 was used for most comparisons.
  2. Count with a distance-weighted window. A symmetric window of ten words on each side slides over the text, and a pair d words apart adds 1/d to Xij rather than 1, so neighbours count fully and words at the edge of the window count a tenth. Left-only windows were also tested. Because counting is symmetric, X is symmetric.
  3. Keep only the non-zeros. Most of the 400,000 × 400,000 possible pairs never co-occur, and the weighting function gives them zero weight, so they are never stored or visited. Modelling counts as a power law in the rank of the pair, the paper estimates that the number of non-zero entries grows like |C|^0.8 for a corpus of |C| tokens: sublinear, so for a large corpus an iteration over the counts is cheaper than an epoch over the text.
  4. Initialise two tables. Every word gets a word vector wi, a context vector w̃i and a scalar bias for each, all random. Since X is symmetric the two tables play identical roles and differ only by where they start.
  5. Fit with AdaGrad. Sample non-zero entries in random order and take an AdaGrad step on each weighted squared residual, starting from a learning rate of 0.05, with xmax = 100 and α = 3/4 in the weighting function. The paper ran 50 iterations for vectors under 300 dimensions and 100 otherwise.
  6. Sum the tables. The released vectors are W + W̃. The paper reports that the sum typically gives a small boost — largest on the semantic analogies — and likens it to combining several trained networks to reduce noise.
  7. Evaluate like word2vec. The test bed was word2vec's 19,544-question analogy set, answered by vector offset and cosine, plus five word-similarity datasets and named-entity recognition with the vectors as features.

Why this objective rather than word2vec's

The paper's most useful derivation connects the two methods. Sum skip-gram's softmax log-likelihood over a whole corpus and group identical pairs, and the objective becomes Σi Xi H(Pi, Qi): a cross-entropy between each word's empirical context distribution Pi and the model's Qi, weighted by the word's total count Xi. The authors object to two things in it. Cross-entropy on a long-tailed distribution gives too much weight to unlikely events, and Q has to be normalised over the whole vocabulary. Replace it with a least-squares fit on unnormalised log values, swap the fixed weight Xi for a tunable f(Xij), and the result is exactly GloVe's loss.

The math

Deriving the GloVe loss from a probability ratio

F((wi − wj) · w̃k) = Pik / Pjk
F = exp ⟹ wi · w̃k = log Pik = log Xik − log Xi
wi · w̃k + bi + b̃k = log Xik
  • Pik = Xik / Xi — the probability that word k appears in the context of word i, where Xi is the row total.
  • (wi − wj) · w̃k — the ratio compares two words, so the model is asked to use their vector difference; taking a dot product with the probe's context vector keeps the result a scalar without mixing dimensions.
  • F = exp — the authors require F to turn a difference of dot products into a quotient of probabilities, F(a − b) = F(a)/F(b), and the exponential is the function that does that.
  • bi, b̃k — log Xi does not depend on k, so it is absorbed into a per-word bias, and the second bias restores the symmetry between words and contexts.

The last line is asked of every pair at once and cannot hold exactly, so it is fitted by weighted least squares over the non-zero Xik, which is the objective J shown earlier on this page. At the extremes: where Xik = 0 the target log 0 is undefined, one reason the weight must vanish there; weighting every pair equally would hand the fit to the huge number of rare, noisy pairs, and weighting by raw counts would hand it to pairs involving "the" and "of".

The evidence

What GloVe measured against word2vec and SVD

The authors evaluated on three kinds of task: word2vec's analogy set, five word-similarity datasets (WordSim-353, MC, RG, SCWS and Rare Words), and CoNLL-2003 named-entity recognition with the vectors as features. Baselines included SVD on the same counts, raw and with log or square-root scaling, and word2vec's CBOW and skip-gram, which the authors retrained themselves on the same six-billion-token corpus with the same vocabulary and window so that only the method differed.

Model, 300 dimensionsTokensSemantic %Syntactic %Total %
SVD on log counts6B56.663.060.1
CBOW, retrained by the authors6B63.667.465.7
Skip-gram, retrained by the authors6B73.066.069.1
GloVe6B77.467.071.7
SVD on log counts42B38.458.249.2
GloVe42B81.969.375.0

The two 42-billion-token rows are the scaling result: plain SVD got worse with seven times more data while GloVe kept improving. The ablations were informative too. Accuracy rose with dimension but showed diminishing returns beyond about 200. Small, left-only windows helped syntactic questions and wider windows helped semantic ones, since meaning is often non-local. And the smaller Wikipedia corpora beat the larger Gigaword corpus on semantic questions, which the authors attribute to Wikipedia's coverage of the places those questions ask about.

Plotted against training time, GloVe beat the retrained word2vec at every budget, and in the authors' runs adding negative samples beyond about ten made word2vec worse. That comparison did not settle the matter. Levy, Goldberg and Dagan later matched hyperparameters across count-based and prediction-based methods and found mostly local or insignificant differences, with no method ahead across the board.

Since then

What the authors admit, and what happened next

The cost is stated: the co-occurrence matrix must be built and held, which is memory proportional to the number of observed pairs rather than to the vocabulary, and is substantial for a large corpus. Rung 1 needs no such structure.

The comparison between the two was contested and the resolution is the useful part. Levy and Goldberg showed that rung 1's objective is implicitly factorising a shifted pointwise-mutual-information matrix — so the two methods are doing much the same thing, one explicitly and one implicitly — and Levy, Goldberg and Dagan later found that reported quality differences owed more to hyperparameters and preprocessing than to the objectives. That finding generalises well beyond word vectors, and it is the same lesson the PPO reproducibility studies teach on another ladder: two methods compared as published are often two configurations compared.

How it held up: the released vectors were the default text representation for several years, which is a long time, and then contextual embeddings made static per-word vectors obsolete for nearly everything. What survives is the framing — state what quantity your representation should recover, then fit it — and the sharpest way to see this rung's contribution is that it made the target explicit where rung 1 left it implicit.

SOLVE IT YOURSELF

The GloVe objective, from scratch

GloVe fits word vectors so a dot product recovers the log co-occurrence, under a weighting that caps frequent pairs and ignores unseen ones. Here are the pieces: the weighting f(x) = (x/xmax)^α (0 at x=0, capped at 1 above xmax), the model's prediction (dot product plus two biases), and one weighted-loss term. A perfect fit — prediction equal to log X — contributes zero. Change the counts and the vectors and watch the loss move.

YOUR TASK

Write the body of weighting. Everything else in the file is already written; this is the function the paper is about. Press ▶ Run to check it against the 5 assertions below — they start red.

WHAT IT HAS TO SATISFY — 5 ASSERTIONS
  1. The weighting caps at 1 for any pair at or above xmax (frequent pairs don't dominate)
  2. An unseen pair (count 0) gets weight 0 -- GloVe sums only over nonzero co-occurrences
  3. Below xmax the weight ramps as (x/xmax)^0.75 -- (50/100)^0.75 ~ 0.5946
  4. The model predicts a dot product plus two biases: 1*3 + 2*1 + 0.5 + 0.5 = 6
  5. A perfect fit (prediction == log co-occurrence) contributes zero loss
CPython · WebAssembly
06

From counts to geometry

For several years, GloVe and word2vec were the way to represent words, and pretrained GloVe vectors were a default first layer in a huge fraction of NLP models — sentiment classifiers, taggers, early question-answering systems. They proved that meaning could be distilled from raw co-occurrence statistics into a compact geometry, cheaply and reusably, and they popularized the analogy demonstrations that made embeddings intuitive to a wide audience.

The field then moved to contextual embeddings, where a word's vector depends on the sentence it's in — ELMo, then BERT and the Transformer, which resolve "bank" differently in "river bank" and "bank account." Those largely superseded static vectors for high-accuracy tasks. But GloVe's lesson endures inside them: the input embedding tables of every modern language model still map tokens to dense vectors learned from distributional statistics — the same idea, now trained end-to-end and made context-dependent. GloVe remains one of the clearest on-ramps to understanding how text becomes numbers a network can reason over.

Worth knowing

GloVe learns two vectors per word — a "target" vector w and a "context" vector w̃ — because a word plays both roles in co-occurrence. They're initialized differently but are largely symmetric by the end. The standard trick is to use their sum (w + w̃) as the final embedding rather than either alone; averaging the two acts as a small ensemble and reliably gives a modest quality bump over picking just one.

Questions

Questions people ask about GloVe

How is the GloVe loss function derived?

Pennington, Socher and Manning start from the observation that ratios of co-occurrence probabilities, not raw probabilities, separate related words: solid co-occurs far more with ice than with steam, gas the reverse, and water about equally with both. They ask for a function F with F((w_i − w_j) · w̃_k) = P_ik / P_jk, require it to turn a difference of dot products into a quotient of probabilities, and conclude that F is the exponential. That gives w_i · w̃_k = log X_ik − log X_i. The log X_i term does not depend on k, so it becomes a bias b_i, and a second bias b̃_k keeps words and contexts symmetric. Because that equation cannot hold exactly for every pair, they fit it by least squares over the non-zero counts, weighted by f(X_ik). That weighted least-squares fit is the GloVe objective.

Is GloVe better than word2vec?

In the GloVe paper, modestly yes: with 300-dimensional vectors trained on the same six-billion-token corpus, GloVe scored 71.7% on the word analogy test against 69.1% for skip-gram and 65.7% for CBOW retrained by the authors, and it was ahead at equal training time. Later work narrowed that gap. Levy and Goldberg showed that skip-gram with negative sampling implicitly factorises a shifted pointwise mutual information matrix, so the two methods target closely related statistics, and Levy, Goldberg and Dagan found that once hyperparameters such as context weighting and the use of context vectors were matched, no method was consistently ahead. In practice the choice came down to which pretrained vectors were available and to memory: GloVe has to hold its co-occurrence matrix, word2vec only streams text.

What do x_max = 100 and alpha = 0.75 do in GloVe's weighting function?

The weight f(x) = (x / x_max)^α for x below x_max, and 1 above it, decides how hard each co-occurrence count pulls on the fit. x_max = 100 is the count at which a pair reaches full weight; anything more frequent, such as a content word next to 'the', gains no further influence. α = 0.75 shapes the ramp below the cap: a pair seen 25 times gets a weight of about 0.35 and one seen 10 times about 0.18, so rare pairs still count, just less than reliable ones. The authors report that α = 3/4 gave a modest improvement over the linear α = 1, that results depend only weakly on x_max, and that the same 3/4 power had worked best in word2vec's noise distribution. Because f(0) = 0, the empty cells of the matrix are never visited.

Why does GloVe learn two vectors per word and add them?

Each word plays two roles in the co-occurrence matrix: as the row word i and as the context word k. GloVe gives it a word vector w and a context vector w̃, each with its own bias. Because the counting window is symmetric, the matrix is symmetric and the two vectors are equivalent in principle; they differ only because they start from different random initialisations. The paper uses their sum, W + W̃, as the final embedding and reports that this typically gives a small boost, largest on the semantic analogy questions, likening it to combining several trained networks to reduce noise. The same trick helps word2vec-style models, which is why Levy, Goldberg and Dagan treated adding context vectors as one of the settings to equalise when they compared the methods.

How does GloVe's training cost grow with corpus size?

Counting is one linear pass over the text. After that, training touches only the non-zero entries of the co-occurrence matrix and never the text. The paper models co-occurrence counts as a power law in the rank of the word pair and, fitting the exponent to its corpora, estimates that the number of non-zero entries grows like |C|^0.8 for a corpus of |C| tokens. That is far below the worst case of vocabulary squared, and somewhat better than window-based methods such as word2vec, whose cost grows linearly with the corpus because every epoch revisits every window. The price is memory: the matrix has to be built and held while training, which for billions of tokens and a 400,000-word vocabulary is a large, if one-time, object.

Check yourself

4 questions to test what you just read

Work each one out before you open it — a number, a prediction or a reason, not a definition. Producing the answer is what makes it stick. Your progress is kept on this device.

With x_max = 100 and alpha = 0.75, what weights do pairs seen 1, 25 and 400 times get, and how much harder does the 400-count pair pull than the 25-count one?

Show answer

f(1) = 0.01^0.75 ≈ 0.032; f(25) = 0.25^0.75 ≈ 0.35; f(400) = 1, because it is past the cap. A pair 16 times more frequent pulls only about 2.8× harder, which is the point: frequent pairs cannot buy influence in proportion to their counts.

In a ten-word window with 1/d weighting, how much does one co-occurrence add to X when the words are adjacent, two apart and ten apart?

Show answer

1, 0.5 and 0.1. So Xij is a distance-weighted count rather than an integer, and a word at the edge of the window counts a tenth as much as a neighbour — GloVe’s version of the near-words-matter-more weighting that word2vec gets by sampling its window width.

If you dropped the bias terms and fitted w_i · w̃_k ≈ log X_ik directly, what would the vectors be forced to encode, and why is that bad?

Show answer

log Xik = log Pik + log Xi, and log Xi is the word’s overall frequency, identical for every context k. Without a bias to absorb it, the dot products would have to carry each word’s frequency, spending dimensions on how common a word is instead of on how it relates to others. The bias bi soaks that up so the vectors can model ratios.

If a corpus grows ten times, roughly how much does the number of non-zero co-occurrence entries grow under the paper's estimate, and how does that compare with a window-based method?

Show answer

10^0.8 ≈ 6.3×, so each GloVe iteration does about 6.3 times the work, while each epoch of a window-based method does the full 10× because it revisits every window. The counting pass is still linear in the corpus, but it happens once.

Where this sits

From a word vector to RAG

The longest ladder here, and the most linear: nine papers that carry one idea — text as geometry — from a 2013 word embedding to a graph-structured retrieval system.

  1. 1Word2Vec2013
  2. 2GloVe2014
  3. 3Sentence-BERT2019
  4. 4Product Quantization2011
  5. 5HNSW2016
  6. 6Dense Passage Retrieval2020
  7. 7ColBERT2020
  8. 8Retrieval-Augmented Generation2020
  9. 9GraphRAG2024

All 110 papers, in 19 ladders →

GloVe: Global Vectors for Word Representation · Jeffrey Pennington, Richard Socher, Christopher D. Manning · Stanford · 2014 · read the original paper → · Vibe Engines · 2026
Finished this one? 0 / 110 Paper Breakdowns done
NextSentence-BERT Next on the “From a word vector to RAG” ladder · rung 3 of 9

Explore the topic

See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.

More Paper Breakdowns