Lensa ML
Lensa ML

Skip-gram

Step 1 of 6

Center → Context

Predicting the neighbors

Center word position2
Skip-gram: predict context from center (window ±2)thecatsatonthematTraining pairs generated:satthesatcatsatonsatthePosition 2 generates 4 pairs. Full sentence of length 6 with window ±2generates ~18 total training pairs.
CENTER
sat
PAIRS
4
WINDOW
±2

"sat" at position 2 produces 4 training pairs. Each pair asks: given "sat", can you predict each context word? Unlike CBOW (which averages context), skip-gram treats each (center, context) pair independently.

Step 1 of 6: Center → Context

Predicting the neighbors

Center word position2
Skip-gram: predict context from center (window ±2)thecatsatonthematTraining pairs generated:satthesatcatsatonsatthePosition 2 generates 4 pairs. Full sentence of length 6 with window ±2generates ~18 total training pairs.
CENTER
sat
PAIRS
4
WINDOW
±2

"sat" at position 2 produces 4 training pairs. Each pair asks: given "sat", can you predict each context word? Unlike CBOW (which averages context), skip-gram treats each (center, context) pair independently.

Step 2 of 6: The Softmax Bottleneck

Why full softmax is too expensive

Vocabulary size12
P(context | center) = exp(score) / Σ exp(all scores)Denominator: sum over ALL 12 wordstheacatdogsatranonindowmatbedbigComputation cost:144 ops/pairCost = O(V × d) per training pair — V=12, d=6Real Word2Vec: V = 100,000+. That's 1,200,000 ops × millions of pairs!→ This is why negative sampling was invented.
VOCAB SIZE
12
OPS/PAIR
144
BOTTLENECK
Severe

At 12 words, cost is 144 operations per training pair. Now imagine V = 100,000 — that's 1,200,000 ops per pair, times millions of pairs. The full softmax becomes the dominant cost. This is why the original Word2Vec paper proposed negative sampling.

Step 3 of 6: Negative Sampling

Binary classification instead of softmax

Negative samples (k)5
Negative Sampling: binary classification instead of softmax✓ Positive pair (real context):satcatσ = 0.542 → want ≈ 1✗ Negative samples (random non-context): k = 5satmatσ = 0.462 → want ≈ 0sattheσ = 0.567 → want ≈ 0satdownσ = 0.525 → want ≈ 0satonσ = 0.494 → want ≈ 0satdogσ = 0.523 → want ≈ 0Objective: log σ(pos) + Σ log σ(−neg) = -4.236Cost: O(k × d) per pair — only 6 dot products instead of 12 (full softmax)
k
5
σ(POS)
0.542
OBJECTIVE
-4.24
SPEEDUP

k=5: the model trains to push σ(positive) toward 1 and σ(negatives) toward 0. Each step requires only 6 dot products instead of 12. The negatives are sampled proportional to word frequency^0.75 — common words are more likely to be negatives.

Step 4 of 6: Subsampling Frequent Words

Discarding 'the' to learn better

Subsampling threshold t = 1.0e-3-3.00
P(discard) = 1 − √(t / f(w))higher frequency → more likely discardedthef=0.282 P(drop)=0.94af=0.200 P(drop)=0.93onf=0.141 P(drop)=0.92inf=0.106 P(drop)=0.90catf=0.059 P(drop)=0.87dogf=0.052 P(drop)=0.86satf=0.042 P(drop)=0.85ranf=0.035 P(drop)=0.83matf=0.028 P(drop)=0.81bigf=0.023 P(drop)=0.79downf=0.019 P(drop)=0.77bedf=0.014 P(drop)=0.73Kept: 12/12 words — frequent words discarded, rare words preserved
THRESHOLD
1.0e-3
KEPT
12/12
DROPPED
0

t=1.0e-3: "the" and "a" are frequently discarded (94%), giving rare content words more relative weight. This dramatically improves embedding quality for words like "cat" and "dog" — they get more meaningful training signal.

Step 5 of 6: Training Dynamics

Watching embeddings cluster

Training step0
Learning rate0.10
Embedding spacetheacatdogsatranonindownmatbedbigLoss (lr=0.10)functionanimalsverbsprepositionsother
STEP
0
LOSS
3.20
LR
0.10

Before training: words are randomly scattered. No semantic structure. The skip-gram objective will pull co-occurring words together and push non-co-occurring words apart.

Step 6 of 6: Embedding Quality

Analogy tests and nearest neighbors

Query word2
Nearest neighbors by cosine similaritythe (-0.04)a (0.04)catdog (1.00)sat (0.09)ran (-0.04)onindownmatbedbig
QUERY
cat
#1 NEAREST
dog
SIM
0.998
#2
sat

"cat" is nearest to "dog" (sim=1.00) — both are animals! Skip-gram learned that "cat" and "dog" appear in similar contexts ("the ___ sat", "a ___ ran"), so their embeddings cluster together.