Skip-gram Model › Worked Example: Tracing a Single Gradient Update
Language AI HandbookAll chapters Skip-gram Model › Worked Example: Tracing a Single Gradient UpdateOne section · Sections in this chapter11 / 14 ↓
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
To make the mathematics concrete, let us trace through a single gradient update for a specific training pair. Suppose our center word is "cat" (index 0) and the true context word is "dog" (index 3), and we have a toy vocabulary of four words: ["cat", "mat", "mouse", "dog"].
We start with random embeddings. Say the center embedding for "cat" is and the context embeddings for all four words are:
Step 1: Compute raw scores by taking dot products:
Step 2: Apply softmax to get probabilities:
The model assigns roughly equal probability to all four words, which makes sense since the embeddings are random.
Step 3: Compute the prediction error. The true context word is "dog" (index 3), so:
Step 4: Update context embeddings. For "dog" (the true context word), the negative error () means we push its context embedding toward the center embedding. For all other words, positive errors mean we push their context embeddings slightly away from the center embedding.
Step 5: Update the center embedding for "cat" by accumulating the error-weighted context embeddings across all vocabulary words. This is the expensive step that requires iterating over all words.
After this one update, the context embedding for "dog" has moved slightly closer to the center embedding of "cat." After millions of such updates across the full corpus, the alignment between frequently co-occurring words becomes strong, while rarely or never co-occurring words become repelled in the embedding space.