Negative Sampling › Negative Sampling
Language AI HandbookAll chapters Negative Sampling › Negative SamplingOne section · Sections in this chapter1 / 15 ↓
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
The Skip-gram model learns powerful word representations, but it has a computational bottleneck: the softmax denominator. Every training step requires computing a sum over the entire vocabulary. Given a center word , the probability of a context word is:
where:
- : probability of context word given center word
- : context embedding vector for word
- : center embedding vector for word
- : vocabulary size
For a vocabulary of 100,000 words, this means 100,000 dot products and exponentials per training step. With billions of training examples, full softmax becomes impractical. Training would take months instead of days.
Negative sampling solves this problem by reformulating the task as binary classification. Instead of predicting the exact probability of a context word, we ask: is this word pair a observed co-occurrence from the corpus, or a fake pair we constructed? This transformation reduces the computational cost from to , where is a small constant (typically 5 to 20), making large-scale training feasible.
This chapter develops negative sampling from first principles. We'll derive the objective function, understand why the sampling distribution matters, implement efficient training, and see how this approximation achieves nearly the same quality as full softmax at a fraction of the cost.