Adaptive Sampled Softmax with Inverted Multi-Index: Methods, Theory and Applications

Jin Chen, Jin Zhang, Xu huang, Yi Yang, Defu Lian, Enhong ChenarXiv 2025 · DOI · arXiv

Abstract

The softmax function is a cornerstone of multi-class classification but suffers from linear computational complexity relative to the number of classes, creating a bottleneck in large-scale applications. We present the MIDX Sampler, an adaptive sampling method that utilizes an inverted multi-index to approximate class probabilities. By decomposing the softmax into efficient sub-steps and leveraging learnable residual quantization, MIDX achieves sub-linear time complexity and provides high-fidelity gradient estimates. Experimental results across language modeling, recommendation, and extreme classification tasks demonstrate that MIDX significantly outperforms traditional sampling strategies in both accuracy and scalability.

Introduction

In modern machine learning, the number of classes ($N$) in tasks like language modeling or global recommendation can reach millions or billions. The standard softmax function requires computing scores for all $N$ classes, making it prohibitively expensive. While "Sampled Softmax" techniques exist to estimate gradients using a subset of classes, they often face a trade-off: simple samplers (e.g., Uniform) are fast but biased, while complex adaptive samplers (e.g., LSH) can be computationally heavy or inaccurate in high-dimensional spaces.

The MIDX Sampler aims to bridge this gap, offering the speed of simple methods with the accuracy of full softmax by leveraging structures typically reserved for Maximum Inner Product Search (MIPS).

Methodology: The MIDX Sampler

The core of the MIDX approach is the decomposition of the softmax probability $P(i|z)$ into a product of multinomial probabilities.

The MIDX sampling process: codewords are sampled from sequential codebooks to identify a candidate class set.

Probability Decomposition and Residual Quantization

Instead of evaluating all $N$ classes, the sampler follows a hierarchical path:

  1. Codeword Sampling: A "codeword" $k_1$ is sampled from a primary codebook.
  2. Sequential Sampling: A second codeword $k_2$ is sampled from a secondary codebook.
  3. Class Selection: A class $i$ is selected from the resulting small group (union set $\Omega$).

To optimize this, the authors utilize Residual Quantization (RQ), where the second codebook models the error of the first. This approach proved superior to standard Product Quantization. Furthermore, the codebooks are not static; they are learnable, optimized by minimizing the Kullback-Leibler (KL) divergence between the sampled and true distributions.

Efficiency Gains

To achieve sub-linear complexity, the "Faster MIDX" trick replaces the final query-specific scoring stage with a uniform distribution within the selected group. This reduces the complexity from $O(N)$ to $O(K)$, where $K$ is the number of codewords, allowing for nearly flat time costs even as the class count scales into the millions.

Theoretical Insights

The paper establishes a rigorous link between the generalization error of the model and the KL-divergence between the sampling proposal and the true softmax distribution. This theoretical foundation justifies why more accurate sampling leads to better model convergence. By treating class embeddings as points in space and using an inverted index, the sampler effectively summarizes the distribution, providing a tighter bound on gradient bias.

Experimental Results

The MIDX Sampler was evaluated across language modeling (PTB, Wikitext-2), sequential recommendation (MovieLens, Gowalla), and extreme classification (WikiLSHTC-325K).

  • Accuracy: On Penn Treebank, MIDX-rq achieved a perplexity of 117.8, far outperforming Uniform (159.9) and approaching the Full Softmax baseline (109.1).
  • Scalability: Timing tests showed that as classes increased from 100k to 2.4 million, MIDX's computational cost remained stable, whereas kernel-based methods scaled poorly.
  • Recommendation: On the Gowalla dataset, MIDX-rq improved Recall@50 by 14.8% over uniform sampling.
  • Learnability: The learnable codebook strategy provided a 14% performance boost over static K-means initialization.

Conclusion

The MIDX Sampler addresses the softmax bottleneck by combining the efficiency of inverted multi-indexes with the accuracy of adaptive sampling. By providing a sub-linear, low-bias gradient estimate, it enables the training of high-performance models on massive datasets. Future work may explore non-linear similarity functions and further GPU-specific optimizations for inverted list structures.

Summary updated

Abstract

The softmax function is a cornerstone of multi-class classification, integral to a wide range of machine learning applications, from large-scale retrieval and ranking models to advanced large language models. However, its computational cost grows linearly with the number of classes, which becomes prohibitively expensive in scenarios with millions or even billions of classes. The sampled softmax, which relies on self-normalized importance sampling, has emerged as a powerful alternative, significantly reducing computational complexity. Yet, its estimator remains unbiased only when the sampling distribution matches the true softmax distribution. To improve both approximation accuracy and sampling efficiency, we propose the MIDX Sampler, a novel adaptive sampling strategy based on an inverted multi-index approach. Concretely, we decompose the softmax probability into several multinomial probabilities, each associated with a specific set of codewords and the last associated with the residual score of queries, thus reducing time complexity to the number of codewords instead of the number of classes. To further boost efficiency, we replace the query-specific residual probability with a simple uniform distribution, simplifying the computation while retaining high performance. Our method is backed by rigorous theoretical analysis, addressing key concerns such as sampling bias, gradient bias, convergence rates, and generalization error bounds. The results demonstrate that a smaller divergence from the ideal softmax distribution leads to faster convergence and improved generalization. Extensive experiments on large-scale language models, sequential recommenders, and extreme multi-class classification tasks confirm that the MIDX-Sampler delivers superior effectiveness and efficiency compared to existing approaches.
BibTeX
@misc{chen2025adaptive,
  author = {Jin Chen and Jin Zhang and Xu huang and Yi Yang and Defu Lian and Enhong Chen},
  title = {{Adaptive Sampled Softmax with Inverted Multi-Index: Methods, Theory and Applications}},
  year = {2025},
  eprint = {2501.08563},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2501.08563},
}

Loading related content...

Figure