arXiv(opens in a new tab)cs.LGOct 2026Cited by 1 paper on PaperVantage

Manuscript Offprint

arXiv:2610.10483

Two-Level Softmax Sampling Done Right: Correcting Bias from Size Imbalance and Dispersion

Walid Bendada, Guillaume Salha-Galvan

Abstract

Sampling from a softmax distribution is a fundamental operation in machine learning, but its linear complexity in the number of items makes exact sampling impractical at scale. Two-level softmax (2LS) sampling is a popular alternative enabling sublinear-time sampling. Assuming items are partitioned into clusters, 2LS first samples a cluster and then an item within it. In this paper, we show that, despite its advantages, 2LS introduces systematic and undesirable sampling biases, which arise from misweighting clusters by ignoring both cluster size imbalance and intra-cluster similarity dispersion. We propose two sampling methods, Size-Corrected 2LS (S-2LS) and Size- and Dispersion-Corrected 2LS (SD-2LS), which correct these biases and provide provably better softmax approximations with negligible to non-existent computational overhead. In-depth experiments on five large-scale datasets validate the improved sampling properties of our methods. We recommend their consistent use in place of standard 2LS in future work.

1 Introduction

Sampling items according to their similarity to a query vector in a shared embedding space is a fundamental operation in many machine learning applications, ranging from language modeling to information retrieval and recommendation [4, 9, 13, 37]. A standard and widely used approach is to sample from a softmax distribution, where each item is weighted by the exponential of its similarity to the query [15]. However, computing and sampling from the full softmax distribution scales linearly with the number of items and quickly becomes intractable in large-scale settings [2, 12, 20]. As an illustration, consider a recommender system where users and items (e.g., products, videos, or music tracks) are embedded in a shared vector space, and recommendations are generated by sampling items according to their similarity to a query user embedding [13, 18]. Modern recommender systems typically operate over millions of candidate items, making exact softmax sampling impractical [2].

A popular alternative to address this issue is two-level softmax (2LS) sampling [7, 8, 16, 22, 34, 36]. Assuming items are partitioned into clusters, 2LS proceeds in two steps: (1) sampling a cluster according to a softmax over cluster representatives, e.g., centroids, and (2) sampling an item within the selected cluster via a softmax over its items. As detailed in Section 2, 2LS has been widely adopted across applications and offers several advantages. First and foremost, this decomposition enables sublinear-time sampling with respect to the number of items [21, 29]. Second, sampling probabilities still account for item–query similarity, as in standard softmax, unlike other scalable alternatives such as ε\varepsilon-greedy methods [35]. Third, 2LS allows sampling over the full set of items, in contrast to truncated softmax approaches that restrict sampling to a limited subset of items [2].

In this paper, we show that, despite these advantages, 2LS exhibits important and systematic biases that, to our knowledge, have never been formally characterized. Backed by rigorous analysis, we propose corrected 2LS variants with improved properties. Specifically, our contributions are as follows:

40th Conference on Neural Information Processing Systems (NeurIPS 2026).

• We show that 2LS oversamples or undersamples items compared to softmax and, in particular, breaks its invariance: while softmax assigns identical sampling probabilities to items with equal similarity to the query, 2LS can assign substantially different probabilities to such items. This mismatch is undesirable in practice: in the recommendation example above, it implies that items equally relevant to a user may be recommended with different probabilities.

• We prove that 2LS systematically misweights clusters along two complementary axes. First, it ignores cluster size imbalance, oversampling small clusters and undersampling large ones relative to their true softmax mass. Second, it ignores intra-cluster similarity dispersion, undersampling clusters whose items exhibit high variability in their similarity to the query.

• We introduce Size-Corrected 2LS (S-2LS) and Size- and Dispersion-Corrected 2LS (SD-2LS), two novel sampling methods that explicitly aim to address these issues. We demonstrate that these corrections effectively mitigate the systematic biases of standard 2LS while incurring negligible to non-existent additional computational overhead.

• We report experiments on five large-scale datasets, consistently validating the improved sampling properties of our approaches and their higher fidelity to the softmax distribution. Our code is available at: https://github.com/bendadaw/neurips-2ls.

In summary, our theoretical and empirical results show that S-2LS and SD-2LS consistently outperform 2LS in approximating softmax sampling, and we recommend their consistent use in future work. The remainder of this paper is organized as follows. Section 2 introduces softmax and 2LS sampling more formally. Section 3 analyzes the biases of 2LS. Section 4 introduces and studies our proposed S-2LS and SD-2LS corrections. Section 5 presents our experiments, and Section 6 concludes.

References (59)