Introduction
In modern machine learning, multi-class classification problems often involve massive label spaces, such as video recommendation systems with millions of items. The standard tool for these tasks is the softmax model, which calculates the probability of a label by comparing its score against the sum of scores for all possible labels (the partition function). However, when the vocabulary size ($V$) reaches $10^6$ or $10^9$, calculating this sum at every training step becomes a significant computational bottleneck.
Researchers typically address this by "sampling"—selecting a small subset of labels to approximate the total sum. While standard methods like random or popularity-based sampling are efficient, they often miss "hard negatives": labels that are very similar to the ground truth and provide the most informative gradients for the model to learn from.
The TAPAS Method
To address the limitations of standard sampling, we propose TAPAS (Two-pass Approximate Adaptive Sampling). TAPAS employs a two-pass strategy to intelligently select hard negatives without incurring prohibitive computational costs:
- Non-adaptive Pass: The algorithm first selects a relatively large subset of labels ($S'$) from the entire vocabulary using a pre-determined distribution, such as "squashed" popularity. This provides a broad initial pool.
- Adaptive Pass: From this initial subset, TAPAS selects a smaller, "harder" subset ($S$) based on the current model’s state. It prioritizes labels that the model currently assigns high dot-product scores, forcing the model to better distinguish them from the true label.
Distributed Implementation
To ensure high performance, TAPAS is implemented using "sampling at the parameter server." Instead of transmitting all label data to worker nodes, worker nodes send context embeddings to the parameter servers. The servers perform the adaptive selection locally on their GPUs and return only the final, small subset to the worker, minimizing network congestion.
Experimental Evaluation
TAPAS was evaluated across three distinct scenarios: synthetic linear classifiers, synthetic neural networks with overlapping clusters, and a real-world video recommendation dataset consisting of 200 million user consumption sequences with a vocabulary of 500,000 items.
Key Results
TAPAS demonstrates significant improvements in ranking metrics. On the real-world video dataset, TAPAS improved the Mean Average Precision (MAP@20) by 30% (from 0.050 to 0.068) compared to standard sampled softmax when using 1,000 samples.
Furthermore, TAPAS exhibits high sample efficiency. As shown in the evaluation, TAPAS with a small number of samples (e.g., $n=1000$) and a high pre-sample factor ($r=8$) often outperforms standard methods using significantly larger sample sizes. This efficiency comes with minimal overhead; the distributed implementation adds only about 10% to the computational time per training step.
Insights and Limitations
The core advantage of TAPAS is its focus on rank loss. By prioritizing hard negatives, the model becomes exceptionally good at distinguishing the correct answer from "almost right" alternatives, which is critical for top-K recommendation tasks.
However, this focus introduces a trade-off. Adaptive sampling intentionally skews the distribution, which can lead to higher cross-entropy loss because the gradient estimation becomes biased. Additionally, the effectiveness of the method is sensitive to hyperparameters like the pre-sample factor ($r$) and the sampling temperature ($ au$), which controls the aggressiveness of the adaptive pass. Future work aims to provide a formal theoretical connection between this adaptive strategy and the optimization of rank loss.
Summary updated