Advanced Machine Learning

22: Word Embedding

Schedule (you are here )

# date topic description
124-Aug-2026Introduction
226-Aug-2026Foundations of learningDrop/Add
331-Aug-2026PAC learnabilityHW1
402-Sep-2026Linear learning models
507-Sep-2026Labor Day HolidayHoliday
609-Sep-2026Principal Component AnalysisProject ideas
714-Sep-2026Curse of DimensionalityHW2, HW1 due
816-Sep-2026Bayesian Decision Theory
921-Sep-2026Parameter estimation: MLE
1023-Sep-2026Parameter estimation: MAP & NBfinalize teams
1128-Sep-2026Logistic RegressionHW3, HW2 due
1230-Sep-2026Kernel Density Estimation
1305-Oct-2026Support Vector Machines
1407-Oct-2026Matrix Factorization
1512-Oct-2026* MidtermExam, HW3 due
1614-Oct-2026k-means clustering
1719-Oct-2026Invited: Intro to Causal Learning I
# date topic description
1821-Oct-2026Invited: Intro to Causal Learning II
1926-Oct-2026* Mid-point projects checkpointHW4, P
2028-Oct-2026Expectation Maximization
2102-Nov-2026Stochastic Gradient Descent
2204-Nov-2026Automatic Differentiation
2309-Nov-2026Nonlinear embedding approachesHW5, HW4 due
2411-Nov-2026Model comparison & calibration
2516-Nov-2026Convolutional Neural Networks
2618-Nov-2026Word Embedding
2723-Nov-2026Thanksgiving BreakHoliday
2825-Nov-2026Thanksgiving BreakHoliday
2930-Nov-2026* Final ExamExam
3002-Dec-2026Project Final PresentationsHW5 due, P
3107-Dec-2026No classClasses End
3216-Dec-2026Project Reportsdue
3317-Dec-2026Grades due 5 p.m.PAWS

Outline for the lecture

  • From Symbols to Distributional Meaning
  • Sparse Text Representations: BoW, TF-IDF & $n$-Grams
  • Semantic Matrices: Co-Occurrence, PPMI, SVD & GloVe
  • Step-by-Step Word2Vec: CBOW, Skip-Gram & Negative Sampling
  • Geometry of Meaning: Analogies, Semantic Drift & Creativity
  • Subwords (BPE), Contextual LLMs & Frontier AI (2016–2026)

Connecting the Dots: Symbols to Semantic Vectors

1. Curse of Dimensionality & Orthogonal One-Hots
One-hot vectors in $\RR^{|V|}$ ($|V| \sim 10^5$) have $\vec{w}_i^\top \vec{w}_j = 0$, and in $d > 20$ cosine normalization rescues similarity!
2. MLE Counts, Laplace Smoothing & Logistic Regression
MLE + Add-1 smoothing power PMI, while binary logistic regression $\sigma(\vec{v}_t^\top \vec{u}_c)$ turns softmax into Negative Sampling!
3. PCA, Matrix Factorization & Low-Rank Subspaces
Linear autoencoders and truncated SVD ($\bm{M} \approx \bm{U}_k \bm{\Sigma}_k \bm{V}_k^\top$) extract dense semantic coordinates from co-occurrences.
4. SGD & Sparse Reverse-Mode AD Updates
One-hot lookup $\bm{W}_e^\top \vec{w}_t$ takes $O(1)$, and SGNS backprop updates only $K+1$ vectors instead of millions!
5. Today: Word Embedding & Modern Token Spaces
Sliding 1D context windows link PPMI/SVD, Word2Vec, analogies, BPE subwords, contextual attention & LLM retrieval!
# date topic
402-Sep-2026Linear learning models
609-Sep-2026Principal Component Analysis
714-Sep-2026Curse of Dimensionality
9–10Sep 2026MLE, MAP & Naive Bayes
1128-Sep-2026Logistic Regression
1407-Oct-2026Matrix Factorization
2102-Nov-2026Stochastic Gradient Descent
2204-Nov-2026Automatic Differentiation
2309-Nov-2026Nonlinear embedding approaches
2516-Nov-2026Convolutional Neural Networks
2618-Nov-2026Word Embedding

What Is Meaning?

Before we embed words as vectors, how do humans and linguists define what a word means?
Herman Chernoff
Herman Chernoff

Vectors Whose Coordinates Carry Meaning

  • Sensor readings naturally stack into feature vectors $\vec{x} \in \RR^d$ (height, weight, blood pressure).
  • Chernoff Faces (1973): map multivariate vectors back into cartoon facial parameters so humans spot anomalies in $\sim 100\text{ ms}$!
  • Today's question: can we map discrete words into continuous coordinates where geometry encodes meaning?
William Labov
William Labov

What Does a Word Mean? Asking Humans

  • William Labov (1973): Can we write an exact, logical rule defining everyday words like "cup" vs. "bowl"?
  • Asked human subjects to label each vessel on the right as either a cup or a bowl.
  • Then attempted to formalize a strict mathematical definition from their responses.
Labov cup stimuli

Category Boundaries Are Fuzzy & Context-Sensitive

Where does cup end
Without context: gradual crossover as diameter widens
Food context shift
With food context: mashed potatoes shift the boundary!
Even a simple physical vessel has probabilistic, graded boundaries that shift immediately with surrounding context!

When Normative Rules Lose Human Meaning

Cup formal definition Trying to prescribe an exact technical formula for "cup" explodes in rules — and loses our human sense of meaning!

Wittgenstein: Family Resemblances Beyond Rigid Rules

Ludwig Wittgenstein
Ludwig Wittgenstein (1889–1951)
Misusing context breaks meaning:
“A man loses his dog, so he puts an ad in the paper. And the ad says, ‘Here, boy!’”
66. Consider for example the proceedings that we call "games". I mean board-games, card-games, ball-games, Olympic games, and so on. What is common to them all? -- Don't say: "There must be something common, or they would not be called 'games'" -- but look and see whether there is anything common to all. -- For if you look at them you will not see something that is common to all, but similarities, relationships, and a whole series of them at that. To repeat: don't think, but look! -- Look for example at board-games, with their multifarious relationships. Now pass to card-games; here you find many correspondences with the first group, but many common features drop out, and others appear. When we pass next to ball-games, much that is common is retained, but much is lost. -- Are they all 'amusing'? Compare chess with noughts and crosses. Or is there always winning and losing, or competition between players? Think of patience. In ball games there is winning and losing; but when a child throws his ball at the wall and catches it again, this feature has disappeared. Look at the parts played by skill and luck; and at the difference between skill in chess and skill in tennis. Think now of games like ring-a-ring-a-roses; here is the element of amusement, but how many other characteristic features have disappeared! And we can go through the many, many other groups of games in the same way; can see how similarities crop up and disappear.
And the result of this examination is: we see a complicated network of similarities overlapping and criss-crossing: sometimes overall similarities.
67. I can think of no better expression to characterize these similarities than "family resemblances"; for the various resemblances between members of a family: build, features, colour of eyes, gait, temperament, etc. etc. overlap and criss-cross in the same way. -- And I shall say: 'games' form a family.
And for instance the kinds of number form a family in the same way. Why do we call something a "number"? Well, perhaps because it has a direct relationship with several things that have hitherto been called number; and this can be said to give it an indirect relationship to other things we call the same name. And we extend our concept of number as in spinning a thread we twist fibre on fibre. And the strength of the thread does not reside in the fact that some one fibre runs through its whole length, but in the overlapping of many fibres.
But if someone wished to say: "There is something common to all these constructions -- namely the disjunction of all their common properties" -- I should reply: Now you are only playing with words. One might as well say: "Something runs through the whole thread -- namely the continuous overlapping of those fibres".
Philosophical Investigations §§66–67: What Is a "Game"? Chess Poker Tennis Solitaire Win / Lose Competition Pure Skill Element of Luck Amusement ✓ ✓ ✓ ✓ (Wait — what about tossing a ball at a wall?) ✓ ✓ ✓ ✗ ✓ ✓ ✗ ✓ ✓ Overlapping fibers — no single property runs the whole thread! Wittgenstein: no single shared essence — only overlapping “family resemblances”!

The Distributional Hypothesis: Meaning Is Use

Shift from normative (prescriptive rules) to observational (empirical corpus usage):
“The meaning of a word is its use in the language.” — Ludwig Wittgenstein (1953)
“If $A$ and $B$ have almost identical environments we say that they are synonyms.” — Zellig Harris (1954)
“You shall know a word by the company it keeps.” — J. R. Firth (1957)

Distributional Inference: What Is “Ong Choi”?

Suppose you see these sentences:
  • Ong choi is delicious sautéed with garlic.
  • Ong choi is superb over rice.
  • Ong choi leaves with salty sauces.
And you have already seen these:
  • …spinach sautéed with garlic over rice.
  • Chard stems and leaves are delicious.
  • Collard greens and other salty leafy greens.
Ong choi water spinach
Conclusion: Ong choi (water spinach) is a leafy green — so its vector should sit right next to spinach, chard, and collard greens!

Bag of Words

Sparse discrete encodings of words and documents

One-Hot Encoding & The Orthogonality Trap

Vocabulary V = [ apricot, cat, jam, kitten, ..., truck ] (|V| ≈ 100,000) cat = 0 1 0 0 ... 0 kitten = 0 0 0 1 ... 0 truck = 0 0 0 0 ... 1 w_cat w_kitten w_truck Every word pair is strictly orthogonal! cat · kitten = 0 cat · truck = 0 All distances = √2
$\vec{w}_i \in \{0,1\}^{|V|}$ gives $O(|V|)$ sparse vectors where $\vec{w}_i^\top \vec{w}_j = \delta_{ij}$ and $\|\vec{w}_{\text{cat}} - \vec{w}_{\text{kitten}}\|_2 = \|\vec{w}_{\text{cat}} - \vec{w}_{\text{truck}}\|_2 = \sqrt{2}$!

Bag of Words: Document Count Vectors

Represent document $d$ as the sum of its one-hot word tokens:
$\displaystyle \vec{c}_d = \sum_{t \in d} \vec{w}_t \in \NN^{|V|}, \qquad \cos(\vec{c}_a, \vec{c}_b) = \frac{\vec{c}_a^\top \vec{c}_b}{\|\vec{c}_a\|_2 \|\vec{c}_b\|_2}$
  • Order Blindness: "dog bites man" and "man bites dog" yield identical count vectors!
  • Zipfian Stop-Word Dominance: the, of, and flood inner products without signaling topic.
Term–Document Count Matrix X ∈ ℕ^(|V|×D) word \ doc d₁ (Recipe) d₂ (Recipe) d₃ (ML) the 42 39 51 garlic 4 3 0 spinach 3 2 0 gradient 0 0 6 Raw dot product c₁·c₃ is dominated by "the" (42 × 51 = 2,142)! How do we downweight words that appear everywhere?

TF-IDF: Downweighting Ubiquitous Words

  • $w_{i,j} = \text{tf}_{i,j}$ — Term Frequency: occurrences of word $i$ in document $j$
  • $\displaystyle \text{idf}_i = -\log \prob{P}{w_i \mid D} = \log \frac{1}{\prob{P}{w_i \mid D}} = \log\!\left(\frac{N}{\text{df}_i}\right)$
    $\text{df}_i =$ documents containing word $i$, $\quad N =$ total documents
  • $\displaystyle w_{i,j} = \text{tf}_{i,j} \times \log\!\left(\frac{N}{\text{df}_i}\right)$
A word in every document ($\text{df}_i = N$) gets $\log(N/N) = 0$ — automatically suppressing stop words and domain boilerplate!

Capturing Local Order with $n$-Grams

Replace single-word tokens with sliding windows of $n$ consecutive tokens: $P(w_t \mid w_{t-n+1}, \dots, w_{t-1})$
Input Phrase: "not good at all" vs. "good at not all" 1-grams (Unigrams): |V| dims {"not", "good", "at", "all"} Exact tie! Loses negation scope Vocab: O(|V|) ≈ 10⁵ 2-grams (Bigrams): |V|² dims {"not good", "good at", "at all"} Distinguishes "not good" from "good" Vocab: O(|V|²) ≈ 10¹⁰ n-grams: |V|ⁿ Curse! {"not good at", "good at all"} Most phrases appear 0 times (sparse) 3-gram: |V|³ ≈ 10¹⁵! Beware of the exponent $|V|^n$: longer $n$-grams hit the Curse of Dimensionality immediately!

Sparse Vectorization: Strengths & Limits

  1. ML models require numeric vectors; one-hot encoding (1-in-|V|) is the discrete starting point.
  2. Bag-of-Words counts and TF-IDF encode documents while downweighting stop words.
  3. $n$-grams recover short-range order, at an exponential $O(|V|^n)$ sparsity cost.
  4. Still missing: semantic similarity between individual words (cat vs. kitten)!

Semantic Matrix Factorization

Turning distributional co-occurrence tables into dense vectors

Constructing the Co-Occurrence Matrix

1. Word $\times$ Document ($\bm{X} \in \RR^{|V| \times K}$)
Asymmetric table counting how often word $i$ occurs inside document $j$ (captures broad document topics).
2. Word $\times$ Word ($\bm{C} \in \RR^{|V| \times |V|}$)
Slide a floating window of width $w \in \{4, 5, 6\}$ across text: $C_{ij}$ counts times words $i$ and $j$ appear in the same context!
Two traps: stop words (the, and) AND frequent domain boilerplate (unknown in advance!) dominate raw counts!
Symmetric Word × Word Counts C (Window w = ±2) w \ c the garlic spinach queen the 190 310 295 440 garlic 310 2 48 0 spinach 295 48 0 0 queen 440 0 0 4 Option A: Normalize context columns with TF-IDF Option B (Cleaner): Compare against independence via PMI!

Pointwise Mutual Information (PMI)

Do focus word $w$ and context word $c$ co-occur more than if independent?
$$\prob{PMI}{w, c} = \log_2 \frac{\prob{p}{c, w}}{\underbrace{\prob{p}{w}\,\prob{p}{c}}_{\text{independence baseline}}}$$
Zero Test: When $w$ and $c$ are statistically independent ($\prob{p}{c,w} = \prob{p}{w}\prob{p}{c}$), the ratio is $1$ so $\prob{PMI}{w,c} = \log_2(1) = 0$!
  • $\displaystyle \prob{PMI}{w, c} = \log_2 \frac{\prob{p}{c \mid w}}{\prob{p}{c}}$
  • MLE plug-ins (Lectures 9–10): $\;\prob{p}{c} = \frac{\prob{count}{c}}{N}$
  • $\displaystyle \prob{p}{c, w} = \frac{\prob{count}{c, w}}{N}, \qquad \prob{p}{w} = \frac{\prob{count}{w}}{N}$
  • $\displaystyle \prob{PMI}{w, c} = \log_2 \frac{\prob{count}{c, w} \times N}{\prob{count}{c} \times \prob{count}{w}}$

Positive PMI (PPMI) & Rare-Word Bias

Why Negative PMI Fails ($-\infty \text{ to } 0$)
  • $\text{PMI} < 0$ means words co-occur less than chance — unreliable without astronomical corpora!
  • If $p(w_1)=10^{-6}$ and $p(w_2)=10^{-6}$, telling if $p(w_1,w_2)$ differs from $10^{-12}$ is hopeless.
  • Plus humans aren't good at quantifying degrees of "unrelatedness".
$\prob{PPMI}{w, c} = \max\!\big(\prob{PMI}{w, c},\; 0\big)$
No Free Lunch: Rare-Word Amplification
Stop words are normalized away in PPMI — but rare events explode!
  • A word appearing once alongside one neighbor gets a huge $\frac{N}{\text{count}(c)\,\text{count}(w)}$ spike.
  • Fix 1 (Context Smoothing): raise rare context probs via $P_\alpha(c) = \frac{\text{count}(c)^\alpha}{\sum_{c'}\text{count}(c')^\alpha}$ ($\alpha = 0.75$).
  • Fix 2 (Add-1 / Laplace Smoothing): add $+1$ to cell counts (Lecture 10!).

Probability Ratios Encode Semantic Axes

GloVe ice vs steam probability ratio table
Individual conditionals $P(k \mid \text{ice}) \sim 10^{-4}$ look tiny — yet the ratio $\frac{P(k \mid \text{ice})}{P(k \mid \text{steam})}$ cancels shared noise (water $\approx 1.36$, fashion $\approx 0.96$) while recovering the physics of solid ($8.9$) vs. gas ($0.085$)!

GloVe: Global Vectors from Log-Ratios (2014)

Require vector differences $\vec{w}_i - \vec{w}_j$ to encode probability ratios $P_{ik} / P_{jk}$:
$F\!\big((\vec{w}_i - \vec{w}_j)^\top \tilde{\bm{w}}_k\big) = \frac{P_{ik}}{P_{jk}} \;\xrightarrow{F = \exp,\; X_{ik}=X_{ki}}\; \vec{w}_i^\top \tilde{\bm{w}}_k + b_i + \tilde{b}_k = \log X_{ik}$
$\displaystyle {\cal J}_{\text{GloVe}} = \sum_{i,j=1}^{|V|} f(X_{ij})\Big(\underbrace{\vec{w}_i^\top \tilde{\bm{w}}_j + b_i + \tilde{b}_j}_{\text{bilateral linear fit}} - \log X_{ij}\Big)^2, \qquad f(x) = \min\!\left(1, \left(\frac{x}{x_{\max}}\right)^{3/4}\right)$
Trains only on non-zero co-occurrence pairs $(i,j)$ while downweighting stop-word saturation via $f(X_{ij})$!

Latent Semantic Analysis & Low-Rank Structure

Block-Diagonal Topics Emerge Without Labels (LSA) immigration, amnesty aliens, border air, pollution environmental, power space, launch orbit, boosters Permuted Documents → Latent Concept Blocks Low-rank matrix factorization
Assuming $|V| \times |V|$ counts live near a $k$-dimensional manifold ($k \approx 100 \ll 10^5$), low-rank factorization yields dense vectors where $\vec{v}_i^\top \vec{v}_j \approx M_{ij}$.

Truncated SVD & Cosine Similarity

Truncated SVD
$\bm{M} \approx \bm{U}_k \bm{\Sigma}_k \bm{V}_k^\top \implies \bm{W}_{\text{words}} = \bm{U}_k \bm{\Sigma}_k \in \RR^{|V| \times k}$ (dropping small singular values turns sparse counts dense!)
Curse of Dimensionality (Lecture 7): in $d > 20$, raw vector lengths distort distances — normalize onto the unit sphere and use cosine similarity $\cos(\vec{v}_i, \vec{v}_j)$!
Scaling Wall: Exact SVD on a $|V| \times |V|$ table ($|V| \sim 10^5$) costs $O(|V|^3)$ (or $O(|V|^2 k)$ truncated) and must recompute on new corpora!

Co-Occurrence, PPMI & Truncated SVD Explorer

Switch weighting from Raw Counts → TF-IDF → PMI → PPMI → Smoothed PPMI and click any word to inspect its 2D SVD coordinates & nearest neighbors.
Focus: spinach Top Neighbors: chard, garlic, rice

Word2Vec

Predictive dense embeddings in streaming $O((K+1)d)$ time
Tomas Mikolov
Tomas Mikolov

Word2Vec: A Context-Predicting Linear Autoencoder

1. Linear Autoencoder (PCA) wₜ ℝ^|V| Wₑᵀ vₜ ℝ^d W_dᵀ wₜ Reconstructing wₜ ignores context! 2. CBOW (Context → Target) w(t-2) w(t-1) w(t+1) w(t+2) v_ctx w(t) Linear sum of context rows → softmax 3. Skip-Gram (Target → Context) w(t) vₜ w(t-2) w(t-1) w(t+1) w(t+2) No hidden nonlinearity — pure linear bottleneck!
Remember PCA & linear autoencoders (Lectures 6 & 14): drop the nonlinearity and train $\bm{W}_e \in \RR^{|V| \times d}, \bm{W}_d \in \RR^{d \times |V|}$ to predict neighboring words instead of self-identity!

Step 1: Sparse Encoder Lookup vs. Dense Decoder

Encoder: Wₑᵀ wᵢ = O(1) Column Lookup! vᵢ Wₑᵀ ∈ ℝ^(d × |V|) × 0 1 0 wᵢ = vᵢ Zeros skip |V|−1 cols! No matrix multiply — just index row i of Wₑ! Decoder: W_dᵀ vᵢ = O(|V|·d) Dense Bottleneck! u_jᵀ (target j) W_dᵀ ∈ ℝ^(|V| × d) × vᵢ = ≈ 1 ≈ 0 Must score ALL |V| columns for softmax! Separate Wₑ & W_d avoids high vᵢᵀvᵢ self-repeat bias Dense vector × dense matrix costs O(|V|·d)!
Key insight: $\vec{v}_i = \bm{W}_e^\top \vec{w}_i$ is trivial ($O(1)$), whereas scoring every word $\bm{W}_d^\top \vec{v}_i$ for Softmax requires $O(|V|\cdot d)$ operations!

Step 2: Continuous Bag of Words (CBOW)

Window of $5$: given context $(w_{t-2}, w_{t-1}, w_{t+1}, w_{t+2})$, predict center word $w_t$ (index $j$):
Distributive Multi-Hot Trick:
$\vec{v}_{\text{ctx}} = \bm{W}_e^\top \vec{w}_{t-2} + \bm{W}_e^\top \vec{w}_{t-1} + \bm{W}_e^\top \vec{w}_{t+1} + \bm{W}_e^\top \vec{w}_{t+2} = \bm{W}_e^\top \underbrace{(\vec{w}_{t-2} + \vec{w}_{t-1} + \vec{w}_{t+1} + \vec{w}_{t+2})}_{\text{single binary vector } \Rightarrow \text{ sum 4 rows of } \bm{W}_e!}$
$\displaystyle \hat{y}_j = \frac{\exp\!\big(\vec{v}_{\text{ctx}}^\top \vec{u}_j\big)}{\sum_{k=1}^{|V|} \exp\!\big(\vec{v}_{\text{ctx}}^\top \vec{u}_k\big)}, \qquad {\cal L}_{\text{CE}} = -\log \hat{y}_j, \qquad \vec{u}_k = (\bm{W}_d)_{:,k}$
Where is the embedding dictionary? After SGD, row $i$ of $\bm{W}_e \in \RR^{|V| \times d}$ is the dense vector for word $i$!
CBOW works as well as Skip-Gram! A silly gradient/averaging bug in the original word2vec.c made CBOW look weaker — kōan (2020) fixed it and matched Skip-Gram!

Step 3: Skip-Gram & The Softmax Bottleneck

Flip the direction: from a single target $\vec{w}_t \xrightarrow{\bm{W}_e^\top} \vec{v}_t$, predict every context word $w_c \in {\cal C}(t)$:
$\displaystyle P(w_c \mid w_t) = \frac{\exp\!\big(\vec{v}_t^\top \vec{u}_c\big)}{\underbrace{\sum_{k=1}^{|V|} \exp\!\big(\vec{v}_t^\top \vec{u}_k\big)}_{\mathbf{O(|V|\cdot d)} \text{ over } |V| \sim 10^6 \text{ words!}}}, \qquad {\cal L}_{\text{SG}} = -\sum_{t=1}^{T}\sum_{\substack{-m \le j \le m \\ j \neq 0}} \log P(w_{t+j} \mid w_t)$
Reverse-Mode AD Gradient (Lecture 18): $\quad \displaystyle \frac{\partial {\cal L}_{\text{SG}}}{\partial \vec{v}_t} = -\underbrace{\vec{u}_c}_{\text{pull positive}} + \underbrace{\sum_{k=1}^{|V|} P(w_k \mid w_t)\,\vec{u}_k}_{\text{push ALL } |V| \text{ words!}}$
In both CBOW and Skip-Gram, full Softmax forward pass AND backward AD touch all $10^6$ rows of $\bm{W}_d$ on every token!

Step 4: Skip-Gram with Negative Sampling (SGNS)

Example window: "... a teaspoon of apricot jam ..." — turn $|V|$-way softmax into binary Logistic Regression (Lecture 11)!
Positives ($D=1$, real context):
(apricot, teaspoon), (apricot, jam), (apricot, of), (apricot, a)
$K$ Noise Negatives ($D=0$, $n_k \sim P_{0.75}$):
(apricot, pizza), (apricot, yummy), (apricot, freeze)
$P(D=1 \mid w_t, w_c) = \sigma(\vec{v}_t^\top \vec{u}_c) = \dfrac{1}{1 + e^{-\vec{v}_t^\top \vec{u}_c}}$
$P(D=0 \mid w_t, w_n) = 1 - \sigma(\vec{v}_t^\top \vec{u}_n) = \dfrac{e^{-\vec{v}_t^\top \vec{u}_n}}{1 + e^{-\vec{v}_t^\top \vec{u}_n}} = \sigma(-\vec{v}_t^\top \vec{u}_n)$
$\displaystyle \ell_{\text{SGNS}} = \log \sigma(\vec{v}_t^\top \vec{u}_c) + \sum_{k=1}^K \log \sigma(-\vec{v}_t^\top \vec{u}_{n_k})$
Per-pair work drops from $O(|V|\cdot d)$ ($\sim 10^6 d$) to just $\mathbf{O((K+1)d)}$ vector-vector dot products ($K \approx 5\text{–}20$)!

Why SGNS Works: Self-Supervision & Implicit PMI

Metric & Self-Supervised Learning
  • Contrastive Pull vs. Push: positives pull $\vec{v}_t, \vec{u}_c$ together; negatives push random words apart so representations don't collapse!
  • Zero Human Labels: raw sentence windows manufacture their own supervised pairs — self-supervised learning!
  • Warm-Start Tip: initializes downstream project classifiers instead of training from sparse BoW.
Grand Unification (Levy & Goldberg, 2014)
Differentiating expected corpus loss $\mathcal{L}_{\text{SGNS}}$ wrt $s = \vec{v}_t^\top \vec{u}_c$ and setting $\partial\mathcal{L}/\partial s = 0$:
$\#(w_t, w_c)\,\sigma(-s) = K\,\#(w_t)\,P_{0.75}(w_c)\,\sigma(s)$
$\displaystyle \implies \vec{v}_t^\top \vec{u}_c = \log \frac{P(w_t, w_c)}{P(w_t)\,P_{0.75}(w_c)} - \log K$
SGNS implicitly factors a shifted PMI matrix in streaming $O((K+1)d)$ time!

Skip-Gram with Negative Sampling Live Trainer

Step or play SGNS updates on "... a teaspoon of apricot jam ..." — try K = 0 to see vectors collapse without negative samples!
Step: 0 Loss: 2.77

Geometry of Meaning

Linear relational offsets, Procrustes drift alignment & measuring human creativity.

Semantic Vector Algebra & Analogies

$\vec{v}_{\text{king}} - \vec{v}_{\text{man}} + \vec{v}_{\text{woman}} \approx \vec{v}_{\text{queen}} \qquad\qquad \hat{w}^* = \argmax_{w \notin \{a,b,c\}} \cos\!\big(\vec{v}_w,\; \vec{v}_b - \vec{v}_a + \vec{v}_c\big)$
Relational Gender Subspace man woman uncle aunt king queen Syntax (Plural) & Capitals Compose Cleanly king queen kings queens France Paris Italy Rome

Relational Projections & Comparative Degree

Gender and nobility relations
Collinear male/female vectors across family & title pairs
Comparative superlative trajectories
Consistent gamma arcs: base $\to$ comparative $\to$ superlative
Important Caveat: Distributional embeddings inherit — and can amplify — human cultural & gender stereotypes present in training corpora (Bolukbasi et al., NeurIPS 2016).

Tracking Semantic Drift Across Centuries

Diachronic word vector comparison
Why can't we subtract 1920 and 1990 vectors directly? Each SVD/SGNS run has an arbitrary rotation ($\bm{U}\bm{Q}(\bm{V}\bm{Q})^\top = \bm{U}\bm{V}^\top$)!
Orthogonal Procrustes Alignment: $\;\displaystyle \bm{R}^* = \argmin_{\bm{Q}^\top \bm{Q} = \bm{I}} \big\|\bm{W}^{(t)}\bm{Q} - \bm{W}^{(t+1)}\big\|_F = \bm{U}\bm{V}^\top \quad (\text{via SVD of }\bm{W}^{(t+1)\top}\bm{W}^{(t)})$

Statistical Laws of Semantic Change (1850–1990)

Diachronic trajectories gay broadcast awful
Cultural Shift: gay moves from daft / cheerful (1900s) $\to$ witty / bright (1950s) $\to$ modern identity (1990s).
Tech Shift: broadcast shifts from scattering seeds (1850s) $\to$ newspapers $\to$ radio / TV / BBC!
Sentiment Reversal: awful turns from solemn majesty (1850s) $\to$ horrible / terrible (1900s+).

Quantifying Creativity in Embedding Space

Divergent Association Task (DAT): Name $7$ unrelated nouns as semantically far apart as possible!
$\displaystyle \text{DAT}\big(\{w_1, \dots, w_7\}\big) = \frac{100}{\binom{7}{2}} \sum_{1 \le i < j \le 7} \Big(1 - \cos\!\big(\vec{v}_{w_i},\, \vec{v}_{w_j}\big)\Big)$
Validated Psychometric Metric: A 2-minute cosine distance score in GloVe space correlates strongly with classic divergent-thinking creativity tests across ~9,000 participants!
Try it live: datcreativity.com — most humans score around $75\text{–}82$; pure semantic distance beats subjective grading!

Semantic Analogies, Drift & Creativity Explorer

Test vector algebra parallelograms (a : b :: c : ?), inspect Procrustes-aligned historical drift, or play the DAT Creativity Challenge!
Result: queen (cos=0.97)

Modern & Contextual Embeddings

From static word tables to BPE subwords, self-attention, InfoNCE & Matryoshka spaces (2016–2026).

Why Static Word Tables Hit a Ceiling

1. Out-of-Vocabulary (OOV) Blindness
Rare inflections ("unbelievably"), biomedical compounds, typos, and code identifiers fall into a single <UNK> bucket — and static tables ignore shared roots like play / playing / replay.
Biomedical clinical terminology
2. Polysemy Collapse
Static Word2Vec/GloVe assigns one fixed row $\vec{v}_{\text{bank}}$ regardless of sentence context!
River / Nature river, mud Finance loan, cash static "bank" Forced to average both incompatible senses!

Subwords: FastText $n$-Grams & Byte-Pair Encoding

1. FastText: Character $n$-Gram Sums (2017)
$\displaystyle \vec{v}_w = \sum_{g \in {\cal G}(w)} \vec{z}_g$
Represent "apricot" by its character $3\text{–}6$-grams: <ap, apr, pri, ric, ico, cot, ot>.

Shares morphological subwords across words and synthesizes vectors for unseen OOV words!
2. Byte-Pair Encoding / BPE (LLMs)
Start from raw bytes/characters and greedily merge the most frequent adjacent pair until reaching $|V| \approx 32\text{K–}256\text{K}$:

un + believ + ably, token + ization.

Zero <UNK> tokens! Universal input vocabulary of GPT, Llama, Claude & Gemini.

From Static Rows to Contextual Self-Attention

Every modern LLM begins with Word2Vec-style lookup $\vec{x}_i^{(0)} = \bm{W}_e^\top \vec{w}_i + \vec{p}_i$ — then remixes context dynamically!
$\displaystyle \vec{h}_i = \sum_{j=1}^{T} \underbrace{\operatorname{softmax}_j\!\left(\frac{(\bm{W}_Q \vec{x}_i)^\top (\bm{W}_K \vec{x}_j)}{\sqrt{d_k}}\right)}_{\text{context-dependent similarity } \alpha_{ij}} \bm{W}_V \vec{x}_j, \qquad P(w_{\text{next}} \mid \vec{h}_T) = \operatorname{softmax}\!\big(\underbrace{\bm{W}_e}_{\text{weight-tied!}} \vec{h}_T\big)$
Layer 0: x_bank Static Wₑ row (ambiguous) "kayak near the muddy river bank" α(bank, river) = 0.72 → h_bank ∈ Nature "deposit cash at the central bank" α(bank, cash) = 0.68 → h_bank ∈ Finance Full Circle to Word2Vec! • RoPE rotates Q & K by position • Tied unembedding W_d = Wₑᵀ • Predicts next token via cross-entropy

Subword BPE & Contextual Polysemy Studio

Step through Byte-Pair Encoding merges with zero <UNK>, or watch Self-Attention split polysemous words ("bank", "apple", "cell") by context!
State: Split cos=0.22

Embeddings Across Frontier AI (2020–2026)

1. Contrastive & RAG (InfoNCE)
CLIP & dense RAG encoders generalize SGNS softmax to whole sentences & images:
$\log \dfrac{\exp(\text{sim}(\vec{q},\vec{k}^+)/\tau)}{\sum_j \exp(\text{sim}(\vec{q},\vec{k}_j)/\tau)}$

Radford et al. (ICML 2021)
2. Matryoshka Embeddings
Train nested prefix dimensions $d \in \{64, 128, 512, 3072\}$ simultaneously — restoring SVD's coarse-to-fine truncation for $10\times$ faster vector DB search!

Kusupati et al. (NeurIPS 2022)
3. Multimodal & Bio Tokens
ViT patch stems (Lecture 21), discrete audio RVQ codes, and protein embeddings (ESM-2/3) where amino-acid context recovers 3D structure!

Lin et al. (Science 2023)
Every modern foundation model — text, vision, audio, or biology — begins by embedding discrete tokens into geometry!

Take Home Points

  • Distributional Semantics: Rigid rule definitions break on real categories (Labov, Wittgenstein); empirical meaning emerges from context co-occurrence ("meaning is use").
  • From Orthogonal One-Hots to PPMI & SVD: TF-IDF and PPMI suppress stop-word & boilerplate dominance; truncated SVD and GloVe compress ratios into unit-normalized cosine spaces.
  • Word2Vec & SGNS: A context-predicting linear autoencoder ($\bm{W}_e, \bm{W}_d$) with $K$ logistic negative samples cuts $O(|V|\cdot d)$ softmax to $O((K+1)d)$ while implicitly factoring shifted PMI!
  • Rich Emergent Geometry: Self-supervised vectors support linear analogies, Procrustes-aligned semantic drift, creativity scoring (DAT), and strong warm-starts over BoW.
  • Modern Token Spaces: BPE eliminates OOVs, self-attention disambiguates polysemy, and InfoNCE + Matryoshka embeddings power LLMs, RAG, CLIP, and scientific foundation models.