Negative Sampling
Negative sampling is an efficient approximation that rewrites the multi-class problem of "picking the correct item from a huge number of candidates" into several "true-or-false binary" judgments. It is the common foundation of Word2Vec, graph embeddings and two-tower retrieval training, and one of the most central steps in contemporary vector retrieval training pipelines.
Core Principles
Take Word2Vec's skip-gram as an example: the original objective is to do a softmax over the entire vocabulary for each context word, and the normalization denominator must traverse tens of thousands to millions of words, an unaffordable amount of computation. Negative sampling works like this: treat every actually occurring "center word, context word" pair as a positive sample, then randomly draw several words from a noise distribution as negative samples, and train a logistic-regression-style binary classifier to distinguish the two, thereby bypassing normalization over the full vocabulary. The choice of noise distribution is crucial; practice has found that taking the three-quarters power of word frequency (normalized by frequency to the power of 0.75) works best: compared with raw frequency it lowers the sampling probability of high-frequency function words and raises that of low-frequency content words, balancing training efficiency and representation quality.
In two-tower retrieval and contrastive learning the position of negative sampling changes but its essence does not. The positives of other samples within a batch are treated as in-batch negatives, the most compute-efficient approach, at the cost that popular content is repeatedly treated as a negative, creating popularity bias. Improvements include subtracting a correction term for a popularity prior from the similarity, using a queue to cache historical negatives, and introducing harder negatives. So-called hard negatives are candidates that are highly similar to the query but are not the correct answer; they are usually drawn from high-scoring results retrieved by the current model after human or rule verification and then added to training, which can markedly speed up convergence and improve ranking quality, but false negatives that are too hard damage the decision boundary and actually lower performance.
Key Points
For the number of negatives, small-scale word-vector training commonly uses five to fifteen, while two-tower retrieval training naturally has hundreds to thousands of in-batch negatives per batch. The proportion of hard negatives should not be too high; a common practice is to mix hard and random negatives, or to warm up with easy negatives first and gradually increase difficulty, that is, curriculum training. False negatives need dedicated cleaning to remove samples that are actually semantically relevant, otherwise the model learns a wrong boundary. The temperature coefficient in the contrastive loss directly controls the sharpness of the distribution; too small makes training unstable with excessively large gradients. The sampling distribution should approximate the real online exposure distribution as closely as possible, otherwise offline metrics look good while online performance drops. Learning rate and batch size must also be adjusted together: the larger the batch, the more in-batch negatives, and the learning rate usually needs to be raised accordingly.
Common Misconceptions
It is a mistake to assume more negatives are always better; in practice more negatives raise the probability of false negatives and increase compute linearly. Another misconception is to ship with only in-batch negatives, under which long-tail content can hardly be retrieved because of popularity bias. Some use hard negatives produced by a teacher model without verification, effectively freezing the teacher's errors into the student model, which is then hard to correct. Some teams also mistakenly use answers from the evaluation set as training negatives, inflating offline metrics while online performance does not improve at all.
Application Scenarios
Word-vector and graph-embedding training, dense retrieval two-tower training, recommendation recall and ranking, contrastive learning, image-text cross-modal alignment, knowledge graph representation learning, candidate screening for large-scale classification.