Distributional Semantics
Suppose a computer must decide whether "tejano" and "conjunto" are related words, without a dictionary. Neither appears in any thesaurus the system has memorized. No rule of grammar links them either. Yet if the system reads enough Texan newspaper archives, it notices something. Both words keep appearing near "music," "band," "accordion," and "dance hall." That shared company of neighbors is a signal. Distributional semantics is the theory that turns this signal into a rigorous notion of meaning. The idea matters because it converts an unsolvable problem into a solvable one. Defining what a word "means" is replaced by counting and comparing contexts. Modern NLP systems do not consult definitions. Instead, they build vector representations of words from co-occurrence statistics. They measure meaning similarity as geometric similarity. This is the conceptual bedrock underneath Word Embeddings and Dense Vectors, Word2Vec Skip-gram, and ultimately the contextual representations inside transformer language models. The big picture is a chain of ideas. First, a linguistic hypothesis about how meaning correlates with usage. Second, a mathematical object (a co-occurrence matrix) that operationalizes the hypothesis. Third, a geometric space where distance or angle between vectors approximates semantic distance between words. Everything descends from this chain. This includes term-document matrices used in information retrieval and the dense embeddings inside GPT-style models. This article builds the theory from scratch. It covers the distributional hypothesis itself, and how to construct co-occurrence-based word vectors. It also explains how to weight and compare them. Then it shows why the resulting geometry captures real semantic structure. It closes with pitfalls, history, and the bridge to dense neural embeddings.
- The distributional hypothesis: words with similar contexts tend to have similar meanings.
- Word meaning is operationalized as a vector of context statistics, not a symbolic definition.
- Co-occurrence matrices (word-word or word-document) are the raw material of these vectors.
- Raw counts are noisy; weighting schemes like PPMI and TF-IDF sharpen the signal.
- Cosine similarity between vectors is the standard proxy for semantic similarity.
- This framework is the direct ancestor of learned embeddings like Word2Vec Skip-gram.
Meaning can be measured, not just defined, by comparing the statistical company a word keeps.
The idea
The distributional hypothesis states that words occurring in similar linguistic contexts tend to have similar meanings. This is often summarized by the slogan "you shall know a word by the company it keeps." It is not a claim that context is meaning in some philosophical sense; it is a working hypothesis that context is a reliable, measurable proxy for meaning, precise enough to build algorithms on. To operationalize this, define a context for a target word as the set of words (or documents) that surround it, within some window or unit of text. A co-occurrence matrix records how often each target word appears near each context word. If is the vocabulary, is a matrix (word-word) or matrix for documents (word-document, as in classic term-document matrices from information retrieval). Row , the vector of counts for word across all contexts, is called the distributional vector or count vector of . The central geometric claim is: if two words and have similar rows and , they are used in similar ways and hence tend to be semantically related — synonyms ("happy"/"joyful"), co-hyponyms ("cat"/"dog"), or words in the same domain ("goalkeeper"/"referee"). This turns semantics into linear algebra: similarity of meaning becomes similarity of vectors, typically measured by cosine similarity,
Cosine similarity is preferred over raw dot product or Euclidean distance because it is insensitive to vector length, and vector length in raw count vectors mostly reflects word frequency rather than meaning.
How it works
Building a distributional model has four steps: choose the context definition, build the co-occurrence matrix, reweight the raw counts, and optionally reduce dimensionality. Each step is a design decision with consequences for what "similarity" ends up capturing.
Step 1 — Context definition. Two families dominate. In the document context model, the context of a word is the document it appears in; this yields the classic term-document matrix used for topic and document similarity (information retrieval, latent semantic analysis). In the window context model, the context of a word is the set of words within positions to its left and right in running text; this yields a term-term matrix and captures finer-grained, more syntactic/semantic similarity than topic-level similarity. Small windows (1–3 words) tend to capture syntactic and functional similarity; large windows (10+ words) tend to capture topical similarity.
Step 2 — Counting. Slide the window across a corpus and increment matrix entries for every (target, context) pair observed.
Step 3 — Reweighting. Raw counts are dominated by high-frequency function words ("the", "of", "a") that co-occur with everything and carry little discriminative meaning. Reweighting schemes discount this. The two classic schemes are:
- TF-IDF (term frequency–inverse document frequency), historically used for word-document matrices in IR.
- PPMI (positive pointwise mutual information), the standard choice for word-word matrices, defined below.
Step 4 — Dimensionality reduction (optional). Raw co-occurrence matrices are huge (, often tens of thousands squared) and sparse. Singular Value Decomposition (SVD) can compress each row into a dense, low-dimensional vector (e.g. 300 dimensions) that retains most of the distributional signal while being cheaper to store and compare. This step is the direct mathematical precursor to the dense embeddings produced by neural models.
Pointwise Mutual Information (PMI) and PPMI
PMI measures whether a target word and context word co-occur more or less often than chance, given their individual frequencies:
Here is the empirical probability of and co-occurring (count divided by total co-occurrence count), and , are their marginal probabilities. PMI is positive when and co-occur more than independence would predict, negative when they co-occur less. Negative PMI values are statistically unreliable for rare pairs (a single unseen co-occurrence swings the estimate wildly), so in practice we clip at zero:
This single design choice — throw away unreliable negative signal, keep reliable positive signal — is the single most impactful reweighting decision in classic distributional semantics.
Full pipeline pseudocode
``` function BUILD_DISTRIBUTIONAL_VECTORS(corpus, window_size, vocab):
# Step 1-2: build raw co-occurrence counts C = zero matrix of size |vocab| x |vocab| for each position i in corpus: w = corpus[i] if w not in vocab: continue for j in range(max(0, i - window_size), min(len(corpus), i + window_size + 1)): if j == i: continue c = corpus[j] if c not in vocab: continue C[index(w)][index(c)] += 1
# Marginal counts total = sum of all entries in C row_sum[w] = sum over c of C[w][c] # how often w occurs as target col_sum[c] = sum over w of C[w][c] # how often c occurs as context
# Step 3: convert counts to PPMI PPMI = zero matrix of size |vocab| x |vocab| for w in vocab: for c in vocab: if C[w][c] == 0: continue P_wc = C[w][c] / total P_w = row_sum[w] / total P_c = col_sum[c] / total pmi = log2( P_wc / (P_w * P_c) ) PPMI[w][c] = max(pmi, 0)
# Step 4 (optional): dimensionality reduction via truncated SVD U, Sigma, V_T = TRUNCATED_SVD(PPMI, k = target_dim) embeddings = U * Sigma # each row is a dense k-dim word vector return embeddings # or return PPMI rows directly if no reduction desired
function COSINE_SIMILARITY(u, v): dot = sum(u[i] v[i] for i in range(len(u))) norm_u = sqrt(sum(u[i]^2 for i in range(len(u)))) norm_v = sqrt(sum(v[i]^2 for i in range(len(v)))) if norm_u == 0 or norm_v == 0: return 0 # guard against zero vectors return dot / (norm_u norm_v) ``` Edge cases handled explicitly: words outside the fixed vocabulary are skipped (`if w not in vocab`), zero counts are skipped before taking a logarithm (avoiding ), and cosine similarity guards against division by zero for all-zero rows (which occur for words absent from the corpus window entirely).
Complexity & correctness
Time complexity of construction. Building the raw co-occurrence matrix requires one pass over the corpus of length tokens, with constant work per token per window position, giving time for window size . This is linear in corpus size and window width — the dominant cost in practice for large corpora.
Space complexity. The naive dense matrix is for word-word co-occurrence, which is prohibitive for realistic vocabularies (– gives – entries). In practice the matrix is extremely sparse — most word pairs never co-occur — so a sparse representation (hash map or coordinate list) stores only nonzero entries, since each token contributes at most new co-occurrence pairs.
PPMI computation cost. Computing PPMI for every nonzero entry is where is the number of nonzero cells, since it requires only the marginal sums (precomputed once in ) and a constant-time computation per cell.
SVD cost. Truncated SVD to rank on a sparse matrix with nonzeros costs roughly per iteration using iterative methods (e.g. Lanczos/randomized SVD), rather than the of a naive dense SVD — this is what makes dimensionality reduction tractable at vocabulary scale.
Why cosine similarity is the right measure — a justification. Consider two words that behave identically in every context except that is twice as frequent overall (a common phenomenon: "big" vs. a rarer synonym "huge" used in the same syntactic slots). Their raw count vectors satisfy elementwise. Euclidean distance can be large simply due to this scale difference, misleadingly suggesting dissimilarity. Cosine similarity is scale-invariant:
correctly identifying such words as maximally similar in direction, which is what distributional theory claims corresponds to meaning — the pattern of contexts, not the absolute frequency of use.
Why PPMI is a principled correction, not an ad hoc trick. Raw co-occurrence count conflates two effects: how informative the pairing is, and how frequent each word is individually. PMI factors these apart by normalizing by the marginals , the count expected under independence. A large driven purely by both words being extremely frequent (e.g. "the" and "of") yields and hence PMI near 0 — correctly signaling "no special association." Clipping to PPMI is justified because for large but finite corpora, PMI estimates for rare pairs have high variance (a single co-occurrence of two rare words produces a large, unreliable PMI spike in either direction), and empirically negative PMI values correlate poorly with any usable semantic signal, while positive PMI values reliably indicate genuine association.
Honesty about tradeoffs. This entire framework is a bag-of-contexts model: it discards word order within the window (except through window boundaries) and cannot represent polysemy — a word like "bank" gets one vector blending "riverbank" and "financial bank" senses, because counts are aggregated over all occurrences. It is also a static representation: the vector for a word never changes based on the sentence it appears in, unlike contextual embeddings from transformer models. Distributional semantics gives a correct and interpretable first-order theory of lexical similarity, but it is not the final word on meaning — it is the foundation that dense, learned, and later contextual embeddings build upon.
Worked example
Consider a toy corpus (typical of how such examples are built for teaching): four short sentences. ``` 1. "tejano band played accordion music" 2. "conjunto band played accordion tunes" 3. "the sky was a clear blue" 4. "clouds filled the blue sky" ``` Use a window size of and restrict the vocabulary to content words {tejano, conjunto, band, accordion, music, sky, blue, cloud}. Raw window co-occurrence counts (word × word, symmetric window):
| target | band | accordion | music | sky | blue |
|---|---|---|---|---|---|
| tejano | 1 | 1 | 0 | 0 | 0 |
| conjunto | 1 | 1 | 0 | 0 | 0 |
| band | 2 | 2 | 1 | 0 | 0 |
| accordion | 2 | 0 | 1 | 0 | 0 |
| sky | 0 | 0 | 0 | 0 | 2 |
| cloud | 0 | 0 | 0 | 1 | 0 |
Marginals (row sums over this small table, total count for illustration):
- ,
- ,
- ,
Compute PMI for (tejano, band): , so .
This is positive: tejano and band co-occur more than chance predicts, so PPMI(tejano, band) . Now compute PMI for (sky, blue): , .
This large PPMI reflects that sky and blue almost always co-occur relative to their (low) individual frequencies — a strong, reliable association from a small sample. After PPMI weighting, compare `tejano` and `conjunto` by cosine similarity over their (mostly identical) PPMI rows — both vectors point almost exactly the same direction in the {band, accordion} subspace, giving cosine similarity near 1.0. Compare `tejano` and `sky` — their nonzero dimensions barely overlap, giving cosine similarity near 0. The distributional model has correctly inferred, purely from co-occurrence statistics and without any dictionary, that tejano and conjunto are semantically close while tejano and sky are not — because tejano and conjunto share almost identical distributional contexts (band, accordion), exactly the signature the distributional hypothesis predicts.
Common pitfalls & traps
| Pitfall | Why it happens | Fix |
|---|---|---|
| Using raw co-occurrence counts directly for similarity | High-frequency function words dominate every row, drowning out signal | Apply PPMI or TF-IDF before comparing vectors |
| Taking when a pair never co-occurs | Forgetting to skip zero entries before the PMI logarithm | Explicitly check and skip, or treat PMI as after clipping |
| Confusing polysemous words as having one meaning | Counts aggregate over all occurrences of a word, blending senses ("bank" = river + finance) | Acknowledge this as a known limitation; move to contextual embeddings for sense disambiguation |
| Choosing window size without considering task | Small windows favor syntactic similarity, large windows favor topical similarity, but this tradeoff is often ignored | Tune window size against a similarity benchmark relevant to the downstream task |
| Using Euclidean distance instead of cosine similarity | Ignoring that vector length reflects raw frequency, not meaning | Normalize vectors or use cosine similarity, which is scale-invariant |
| Comparing vectors built from different corpora/window sizes as if commensurable | Different pipelines produce different geometries; absolute PPMI values are not calibrated across setups | Only compare vectors built under identical vocabulary, window, and weighting choices |
Pioneers & history
Origins · 1 minJohn Rupert Firth and how this was discovered
Firth was a professor of general linguistics who argued that a word's meaning is inseparable from its habitual collocations — the company it keeps in real usage. His 1957 formulation, "you shall know a word by the company it keeps," became the informal motto of the entire distributional semantics research program, even though the mathematical machinery (matrices, PMI, SVD) was developed decades later by others working in information retrieval and computational linguistics.
Where this matters
Distributional semantics underlies the earliest practical vector-space models in information retrieval, where term-document matrices (weighted by TF-IDF) power document similarity, clustering, and search ranking — the same mathematics used in search engines before neural re-ranking existed. Latent Semantic Analysis (LSA), built by applying SVD to term-document matrices, was deployed in essay-grading systems and synonym-detection tools, and its dimensionality-reduction step is the direct mathematical ancestor of dense embeddings. The word-word PPMI-plus-SVD pipeline described here is the classical baseline against which every learned embedding method — Word2Vec Skip-gram, GloVe, and their successors — is measured, and it can be shown that skip-gram with negative sampling implicitly factorizes a shifted PMI matrix, making the connection between counting-based and neural methods mathematically precise rather than merely historical. Modern large language models, whose token representations are learned end-to-end via gradient descent rather than counted explicitly, still rest on the same underlying assumption: that a token's role is determined by, and recoverable from, the contexts in which it appears. Every time a chatbot infers that "furious" is closer to "angry" than to "hungry," it is exploiting the distributional hypothesis, however many layers of transformation now separate the raw text from the final vector. This throughline connects Distributional Semantics directly to Word Embeddings and Dense Vectors and the broader architecture of neural language models.
Ask the tutor: How does skip-gram with negative sampling relate mathematically to the PPMI matrix factorization described here?
Is distributional semantics the same thing as word embeddings?
Not exactly — distributional semantics is the broader theory, while word embeddings (like those from Word2Vec Skip-gram) are one implementation of it. Classic distributional semantics builds explicit co-occurrence matrices and reweights them (PPMI, TF-IDF), optionally compressing with SVD. Neural word embedding methods instead learn dense vectors directly via gradient descent on a prediction objective, without ever materializing a full co-occurrence matrix. Research has shown these are mathematically related: skip-gram with negative sampling implicitly factorizes a shifted PMI matrix. So embeddings are a scalable, learned realization of the same distributional hypothesis, not a separate theory.
Why does window size change what kind of similarity you get?
A narrow window (1–3 words) mostly captures words appearing in the same syntactic slot, since only immediately adjacent words are counted as context — this tends to group words by grammatical function and near-synonymy, like "cat" and "dog" both appearing after "the" and before verbs. A wide window (10+ words) captures topical co-occurrence across a whole passage, grouping words like "goalkeeper," "referee," and "stadium" that share a topic without ever appearing next to each other. Neither choice is universally correct; it depends on whether the downstream task needs fine-grained syntactic similarity or broad topical similarity.
Why clip PMI at zero to get PPMI instead of just using raw PMI?
Negative PMI values arise when two words co-occur less than chance predicts, but for rare word pairs this estimate is statistically unreliable — a corpus of finite size gives noisy estimates of rare joint probabilities, so a single missing co-occurrence can produce a large negative PMI that reflects sampling noise rather than genuine semantic anti-association. Positive PMI values, by contrast, are empirically much more reliable and interpretable as evidence of real association. Clipping at zero (PPMI) discards the unreliable negative signal while preserving the reliable positive signal, which consistently improves downstream similarity and analogy performance in practice.
Can distributional semantics handle words it has never seen before?
No — this is a hard limitation. A word absent from the training corpus has no co-occurrence row at all, so it gets no vector (or an all-zero vector, which the cosine similarity function should treat as undefined/zero similarity to everything). This is the classic out-of-vocabulary problem. Later neural approaches partially address it using subword units (like byte-pair encoding) so that unseen words can still be represented via known subword pieces, but the pure count-based distributional model described here has no built-in mechanism for generalizing beyond its observed vocabulary.
How does this connect to term-document matrices from information retrieval?
Term-document matrices are the word-document special case of a co-occurrence matrix: rows are terms, columns are documents, and entries are counts (or TF-IDF weighted counts) of how often a term appears in a document. Distributional semantics generalizes this by also considering word-word co-occurrence within a sliding window, which captures finer-grained lexical similarity rather than document-level topical similarity. Both are instances of the same underlying idea — represent an item as a vector of its contexts — differing only in what counts as "context" (a whole document versus a local window).
Does distributional semantics explain why word analogies like "king − man + woman ≈ queen" work?
That specific analogy behavior is much more strongly associated with learned dense embeddings (like Word2Vec) than with raw PPMI vectors, though the underlying distributional hypothesis is what makes any such structure possible in the first place. The core idea — that words used in structurally parallel contexts end up with structurally parallel vector relationships — originates in distributional theory. But the clean linear analogy arithmetic requires the specific geometric properties that emerge from training dense, low-dimensional embeddings with an appropriate objective, which is a topic more fully developed under Word2Vec Skip-gram rather than classic count-based vectors.
Why is the co-occurrence matrix so sparse, and why does that matter for implementation?
Most word pairs in a vocabulary never co-occur within any reasonable window across a finite corpus — the vast majority of possible pairs have zero count, especially for rare words. This sparsity means a dense matrix representation wastes enormous memory (a dense matrix needs tens of billions of cells), while a sparse representation (storing only nonzero entries as a hash map or coordinate list) needs space proportional only to the number of observed co-occurrences, which scales with corpus size and window width rather than vocabulary size squared. This is what makes the pipeline tractable in practice.