Notes

Negative Sampling

Training a word embedding by asking “which word out of the entire vocabulary appears next to this one?” means normalising over a million possibilities for every single training example. Negative sampling replaces that question with one a computer can answer almost for free.

What it changes
Instead of predicting a distribution over the vocabulary, the model is handed pairs and asked a yes-or-no question: did this word and this context word really occur together, or did I invent the pairing? Each real pair from the corpus is accompanied by k fabricated ones — the same target word with randomly drawn context words — and the model learns to score the real pair high and the fakes low with simple logistic regression. One update touches k+1 word vectors rather than the whole vocabulary. This is the objective people mean by skip-gram with negative sampling, the default in Word2Vec.

Choosing the negatives
The sampling distribution is not uniform, and the details earn their keep:

  • Words are drawn from the unigram frequency distribution raised to the power 3/4, which damps “the” and “of” while giving rare words a realistic chance of appearing as a negative.
  • k sits around 5–20 for small corpora and 2–5 for large ones; more negatives means a sharper decision boundary and slower training.
  • The same idea trains modern retrieval: a bi-encoder learns from in-batch negatives, and deliberately mined hard negatives are what separate a usable dense retriever from a weak one.

Why it matters
Negative sampling is why Word2Vec trained on billions of words on one machine in hours, and the trick transfers anywhere a softmax over a huge output space is the bottleneck. It also sets a quality ceiling: negatives that are too easy teach the model nothing beyond telling real language from noise.

Negative sampling is a training shortcut that replaces a softmax over the whole vocabulary with a binary decision: score a genuine word-context pair against k randomly drawn fake ones. Each update touches only those few vectors, so Word2Vec can train on billions of words cheaply. Negatives are drawn from the unigram distribution raised to the power 3/4, and the same technique now trains dense retrieval encoders, where the difficulty of the negatives sets the quality of the result.

Suppose you are learning to recognise a friend's handwriting. You do not compare it against every handwriting sample in the world. You look at a few of theirs and a few random ones, and learn to tell them apart. That is enough.

Negative sampling is that shortcut, used to teach software the meanings of words. Instead of asking “out of a million words, which one goes here?”, it asks a far cheaper question: “do these two words really appear together, or did I pair them up at random?” Answering that over and over, with a handful of fake pairings each time, is what let computers learn word meanings from billions of sentences in hours rather than weeks.