Introduction
Large-scale recommendation systems often rely on "two-tower" architectures, where separate neural networks encode user and item features into a shared embedding space. Training these models effectively requires distinguishing positive interactions from a vast pool of negative candidates. While in-batch negative sampling is a common, memory-efficient shortcut, its performance is strictly capped by the mini-batch size. Researchers have introduced Cross-Batch Negative Sampling (CBNS) to overcome this limitation, enabling models to learn from thousands of negative examples without the memory overhead of massive batch sizes.
The Challenge of Negative Sampling
In-batch negative sampling treats items liked by other users in the same mini-batch as negatives for the current user. While efficient, this approach is constrained by GPU memory; small batches provide too few negatives, making the learning task trivial and leading to suboptimal recommendations. Increasing batch size to capture more negatives is often computationally prohibitive due to the cost of encoding complex features for every item in every iteration.
Methodology: Cross-Batch Negative Sampling
CBNS decouples the number of negative samples from the mini-batch size by maintaining a First-In-First-Out (FIFO) memory bank of item embeddings from previous training steps.
The training process follows a two-step cycle:
- Training with Cross-Batch Embeddings: The model calculates the loss by comparing current user embeddings against both the current batch's items and the "stale" embeddings stored in the memory bank. Crucially, these stored embeddings are not re-calculated, saving significant computation.
- Memory Bank Update: After the gradient update, the item embeddings from the current batch are enqueued into the memory bank, and the oldest embeddings are dequeued.
Theoretical Foundation: Embedding Stability
The validity of CBNS hinges on the observation that neural network outputs stabilize after an initial warmup phase. The authors define "feature drift" as the change in an item's embedding over time.
As shown in the figure above, feature drift drops sharply after approximately 40,000 iterations. This stability ensures that embeddings stored in the memory bank remain "accurate enough" representations of the item tower's current state, allowing them to serve as effective negative samples.
Experimental Results
The researchers evaluated CBNS on the Amazon-Books dataset using three architectures: YouTube DNN, GRU4REC, and MIND. CBNS consistently outperformed standard in-batch sampling and Mixed Negative Sampling (MNS).
- Ranking Quality: CBNS improved NDCG@50 by 3.23% to 11.51% compared to standard in-batch methods.
- Efficiency: By using a memory bank size of ~2,500 to 5,000 items—far exceeding typical batch sizes—the model achieved higher recall and NDCG in less total wall-clock time.
- Scalability: The method allows for a small, memory-efficient mini-batch (e.g., 128) while providing the model with the gradient signal of a much larger batch.
Conclusion
Cross-Batch Negative Sampling provides a practical and theoretically grounded solution for scaling two-tower recommenders. By exploiting embedding stability, CBNS significantly expands the pool of negative samples available during training, leading to better recommendation quality and faster convergence without requiring additional high-end hardware. Future research may explore integrating hard negative mining within the memory bank to further refine model performance.
Summary updated