Papers
Topics
Authors
Recent
Search
2000 character limit reached

LapSum-Based Soft Top-K

Updated 16 March 2026
  • LapSum-based Soft Top-K is a differentiable approximation method that smoothens the hard top-k operator using the Laplace CDF to produce soft weights.
  • It employs closed-form inversion and log-space computations to ensure efficient, stable gradient propagation and robust performance in classification tasks.
  • Empirical results show that this method improves accuracy and convergence in scenarios with noisy labels and limited data compared to traditional losses.

LapSum-based Soft Top-K refers to a class of smooth, differentiable relaxations of the top-kk selection operator, constructed via summing the cumulative distribution functions (CDFs) of Laplace distributions and inverting this sum to obtain soft top-kk weights or losses. The LapSum method underlies both differentiable top-kk selection functions and smoothed loss functions optimized for top-kk metrics in machine learning. These relaxations address the challenge that hard top-kk operators and their associated losses are non-differentiable and provide poor gradient signals for optimization with stochastic gradient descent, particularly in deep learning contexts. Recent developments have established two main LapSum-based frameworks: the Soft Top-K SVM loss for classification tasks and the more general LapSum-based soft ranking, selection, and permutation operators.

1. Mathematical Formulation and Definition

The LapSum function is defined using the Laplace CDF as follows. Let r=(r0,,rn1)Rnr = (r_0, \ldots, r_{n-1}) \in \mathbb{R}^n represent the centers (e.g., scores), and α0\alpha \ne 0 be the temperature or smoothing parameter. The scaled CDF of the standard Laplace distribution is

Lapα(x)={12exp(x/α),x0 112exp(x/α),x>0.\mathrm{Lap}_\alpha(x) = \begin{cases} \frac12 \exp(x / \alpha), & x \le 0\ 1 - \frac12 \exp(-x / \alpha), & x > 0. \end{cases}

The LapSum function is then

LapSumα(x;r)=i=0n1Lapα(xri).\mathrm{LapSum}_\alpha(x; r) = \sum_{i=0}^{n-1} \mathrm{Lap}_\alpha(x - r_i).

For a given w(0,n)w \in (0, n), the LapSum-based soft top-kk0 operator is defined by inverting the above sum to find kk1 such that kk2, and then setting

kk3

As kk4 and kk5, the vector kk6 converges to the hard top-kk7 indicator. This construction provides a smooth, differentiable and parameterizable approximation of the hard top-kk8.

In classification loss settings (Berrada et al., 2018), the LapSum formalism is used to define a smooth surrogate loss for top-kk9 error based on log-sum-exp over kk0-tuples, yielding the “Smooth Top-K SVM” (or LapSum-based Soft Top-kk1 loss):

kk2

Here, kk3 is the model score vector, kk4 is the ground-truth class, and kk5, kk6 represent the set of kk7-tuples (possibly including or excluding kk8).

2. Smoothing via Log-Sum-Exp and Laplace CDF

Non-differentiability of the hard top-kk9 operator arises from the use of kk0 and kk1-selection, yielding piecewise linearities and highly sparse subgradients not suitable for deep network training. By replacing the kk2 over kk3-tuples with the softmax or log-sum-exp (temperature kk4 or kk5 as a smoothness parameter), the LapSum construction produces a smooth approximation in which nearly highest scores contribute according to their ranking. This yields dense gradient information, aiding convergence and robustness in stochastic optimization (Berrada et al., 2018).

In the LapSum-based soft selection setting, the smoothness is controlled by kk6. Small kk7 yields a near-hard selection, while large kk8 leads to highly distributed, smooth soft top-kk9 probabilities. A direct benefit is the ability to interpolate between the hard operator and a fully smooth, ranking-weighted output.

3. Efficient Algorithmic Implementation

3.1 Closed-Form Inversion and Piecewise Structure

To compute kk0 such that kk1, sort kk2 and precompute auxiliary sequences kk3 in kk4 time. On each interval kk5, kk6 admits a closed-form representation, and kk7 is obtainable using explicit formulas for boundary and interior segments. The interval kk8 containing kk9 is found by binary search, so total complexity for the inversion is r=(r0,,rn1)Rnr = (r_0, \ldots, r_{n-1}) \in \mathbb{R}^n0 (Struski et al., 8 Mar 2025).

3.2 Forward and Backward Algorithms

Given r=(r0,,rn1)Rnr = (r_0, \ldots, r_{n-1}) \in \mathbb{R}^n1, the soft top-r=(r0,,rn1)Rnr = (r_0, \ldots, r_{n-1}) \in \mathbb{R}^n2 weights r=(r0,,rn1)Rnr = (r_0, \ldots, r_{n-1}) \in \mathbb{R}^n3 are evaluated for all r=(r0,,rn1)Rnr = (r_0, \ldots, r_{n-1}) \in \mathbb{R}^n4 in r=(r0,,rn1)Rnr = (r_0, \ldots, r_{n-1}) \in \mathbb{R}^n5. Gradients with respect to r=(r0,,rn1)Rnr = (r_0, \ldots, r_{n-1}) \in \mathbb{R}^n6, r=(r0,,rn1)Rnr = (r_0, \ldots, r_{n-1}) \in \mathbb{R}^n7, and r=(r0,,rn1)Rnr = (r_0, \ldots, r_{n-1}) \in \mathbb{R}^n8 are obtained by defining a density vector r=(r0,,rn1)Rnr = (r_0, \ldots, r_{n-1}) \in \mathbb{R}^n9 and normalization α0\alpha \ne 00, yielding

α0\alpha \ne 01

where α0\alpha \ne 02. Vector-Jacobian products can be evaluated in α0\alpha \ne 03 time without explicit Jacobian formation (Struski et al., 8 Mar 2025).

For classification loss with polynomial-algebraic structure (elementary symmetric polynomials), the key quantities α0\alpha \ne 04 and α0\alpha \ne 05 can be computed via a divide-and-conquer, degree-truncated polynomial product to compute the relevant symmetric sums in α0\alpha \ne 06 time (Berrada et al., 2018). The backward pass uses recursions for partial symmetric sums, also in α0\alpha \ne 07. This enables efficient computation of loss and gradient for large α0\alpha \ne 08 and moderate α0\alpha \ne 09.

3.3 Numerical Stability

Forward computation is implemented in log-space to prevent overflow, with log-add-exp tricks for summation. Backward recursions are stabilized when Lapα(x)={12exp(x/α),x0 112exp(x/α),x>0.\mathrm{Lap}_\alpha(x) = \begin{cases} \frac12 \exp(x / \alpha), & x \le 0\ 1 - \frac12 \exp(-x / \alpha), & x > 0. \end{cases}0 becomes large using a Lapα(x)={12exp(x/α),x0 112exp(x/α),x>0.\mathrm{Lap}_\alpha(x) = \begin{cases} \frac12 \exp(x / \alpha), & x \le 0\ 1 - \frac12 \exp(-x / \alpha), & x > 0. \end{cases}1-term asymptotic expansion, leading to stable gradients in single-precision arithmetic with only minor computational overhead (Berrada et al., 2018).

4. Empirical Performance and Comparisons

The LapSum-based Soft Top-Lapα(x)={12exp(x/α),x0 112exp(x/α),x>0.\mathrm{Lap}_\alpha(x) = \begin{cases} \frac12 \exp(x / \alpha), & x \le 0\ 1 - \frac12 \exp(-x / \alpha), & x > 0. \end{cases}2 demonstrates advantages under various regimes, particularly for Lapα(x)={12exp(x/α),x0 112exp(x/α),x>0.\mathrm{Lap}_\alpha(x) = \begin{cases} \frac12 \exp(x / \alpha), & x \le 0\ 1 - \frac12 \exp(-x / \alpha), & x > 0. \end{cases}3:

  • On CIFAR-100 with ResNet-18 and noisy labels, top-5 Soft Top-Lapα(x)={12exp(x/α),x0 112exp(x/α),x>0.\mathrm{Lap}_\alpha(x) = \begin{cases} \frac12 \exp(x / \alpha), & x \le 0\ 1 - \frac12 \exp(-x / \alpha), & x > 0. \end{cases}4 SVM loss (LapSum with Lapα(x)={12exp(x/α),x0 112exp(x/α),x>0.\mathrm{Lap}_\alpha(x) = \begin{cases} \frac12 \exp(x / \alpha), & x \le 0\ 1 - \frac12 \exp(-x / \alpha), & x > 0. \end{cases}5) achieves higher robustness than cross-entropy: at Lapα(x)={12exp(x/α),x0 112exp(x/α),x>0.\mathrm{Lap}_\alpha(x) = \begin{cases} \frac12 \exp(x / \alpha), & x \le 0\ 1 - \frac12 \exp(-x / \alpha), & x > 0. \end{cases}6 label noise, Soft Top-5 SVM attains top-5 accuracy Lapα(x)={12exp(x/α),x0 112exp(x/α),x>0.\mathrm{Lap}_\alpha(x) = \begin{cases} \frac12 \exp(x / \alpha), & x \le 0\ 1 - \frac12 \exp(-x / \alpha), & x > 0. \end{cases}7 vs cross-entropy Lapα(x)={12exp(x/α),x0 112exp(x/α),x>0.\mathrm{Lap}_\alpha(x) = \begin{cases} \frac12 \exp(x / \alpha), & x \le 0\ 1 - \frac12 \exp(-x / \alpha), & x > 0. \end{cases}8, and top-1 accuracy Lapα(x)={12exp(x/α),x0 112exp(x/α),x>0.\mathrm{Lap}_\alpha(x) = \begin{cases} \frac12 \exp(x / \alpha), & x \le 0\ 1 - \frac12 \exp(-x / \alpha), & x > 0. \end{cases}9 vs cross-entropy LapSumα(x;r)=i=0n1Lapα(xri).\mathrm{LapSum}_\alpha(x; r) = \sum_{i=0}^{n-1} \mathrm{Lap}_\alpha(x - r_i).0 (Berrada et al., 2018).
  • For ImageNet in low-data settings (5–25% samples), LapSum soft top-5 loss slightly outperforms cross-entropy; gaps close as data increases, aligning with theory that cross-entropy is asymptotically optimal (Berrada et al., 2018).
  • In large-scale differentiable sorting and ranking, LapSum soft top-LapSumα(x;r)=i=0n1Lapα(xri).\mathrm{LapSum}_\alpha(x; r) = \sum_{i=0}^{n-1} \mathrm{Lap}_\alpha(x - r_i).1 achieves top-5 accuracy rates on CIFAR-100 (ResNet-18) and ImageNet-1K (ResNeXt-101) that match or surpass NeuralSort, SoftSort, SinkhornSort, and OT-based approaches, with lower or comparable runtime and memory requirements, especially as LapSumα(x;r)=i=0n1Lapα(xri).\mathrm{LapSum}_\alpha(x; r) = \sum_{i=0}^{n-1} \mathrm{Lap}_\alpha(x - r_i).2 and LapSumα(x;r)=i=0n1Lapα(xri).\mathrm{LapSum}_\alpha(x; r) = \sum_{i=0}^{n-1} \mathrm{Lap}_\alpha(x - r_i).3 grow. On ImageNet-21K-P, LapSum soft top-5 achieves ACC@5 LapSumα(x;r)=i=0n1Lapα(xri).\mathrm{LapSum}_\alpha(x; r) = \sum_{i=0}^{n-1} \mathrm{Lap}_\alpha(x - r_i).4 (Struski et al., 8 Mar 2025).

Runtime for forward+backward is LapSumα(x;r)=i=0n1Lapα(xri).\mathrm{LapSum}_\alpha(x; r) = \sum_{i=0}^{n-1} \mathrm{Lap}_\alpha(x - r_i).5, outperforming alternate schemes for large LapSumα(x;r)=i=0n1Lapα(xri).\mathrm{LapSum}_\alpha(x; r) = \sum_{i=0}^{n-1} \mathrm{Lap}_\alpha(x - r_i).6.

5. Practical Implementation Considerations

Efficient LapSum-based soft top-LapSumα(x;r)=i=0n1Lapα(xri).\mathrm{LapSum}_\alpha(x; r) = \sum_{i=0}^{n-1} \mathrm{Lap}_\alpha(x - r_i).7 solutions are available in vectorized Python/PyTorch as well as in custom CUDA kernels. CPU algorithms exploit prefix scans and binary search for breakpoints, while CUDA implementations use warp-parallel prefix sums for evaluation at scale (Struski et al., 8 Mar 2025). Double precision is standard, but float32 offers similar accuracy after stabilizing exponentials.

The primary hyperparameter is LapSumα(x;r)=i=0n1Lapα(xri).\mathrm{LapSum}_\alpha(x; r) = \sum_{i=0}^{n-1} \mathrm{Lap}_\alpha(x - r_i).8 (or LapSumα(x;r)=i=0n1Lapα(xri).\mathrm{LapSum}_\alpha(x; r) = \sum_{i=0}^{n-1} \mathrm{Lap}_\alpha(x - r_i).9 in the loss), with smaller values approximating hard selection and larger values offering smoother distributions; typically, w(0,n)w \in (0, n)0 is tuned through grid search or end-to-end learning.

For extremely large w(0,n)w \in (0, n)1, sorting can dominate computational cost, suggesting partial sorts or segment-tree approximations for streaming or online scenarios. Numerical stability at breakpoints is maintained by numerically stable square-root formulas and exponent clamping (Struski et al., 8 Mar 2025). Extensions to fractional w(0,n)w \in (0, n)2 ("top-w(0,n)w \in (0, n)3" for real w(0,n)w \in (0, n)4) are immediate, generalizing the selection operator.

6. Limitations and Distinctive Properties

LapSum-based Soft Top-w(0,n)w \in (0, n)5 methods are subject to the following constraints:

  • The scale parameter w(0,n)w \in (0, n)6 cannot be zero. The approximation quality between hard and soft top-w(0,n)w \in (0, n)7 is governed by w(0,n)w \in (0, n)8; incorrect tuning may affect performance or gradient informativeness.
  • For full Jacobian computation, memory requirements are w(0,n)w \in (0, n)9, although vector-Jacobian products for backpropagation only require kk00 (Struski et al., 8 Mar 2025).
  • The sort step is the computational bottleneck for extremely large kk01, with plausible mitigations in streaming or coarse ranking settings.
  • The LapSum formalism naturally extends to "soft" relaxations for ranking, permutation, and sorting operators, maintaining differentiability, monotonicity, and computational tractability.
  • Mathematical convergence to hard top-kk02 is pointwise as kk03 for integer kk04.

7. Relation to Other Differentiable Top-K and Ranking Methods

LapSum-based soft top-kk05 distinguishes itself from alternatives such as NeuralSort, SoftSort, SinkhornSort, and optimal transport-based ranking operators by offering both closed-form inversion and explicit construction for probabilities that preserve rank structure with a direct probabilistic interpretation. Empirical and runtime comparison confirm LapSum is in the top efficiency and accuracy cluster for high-dimensional and large-kk06 tasks (Struski et al., 8 Mar 2025).


References:

Definition Search Book Streamline Icon: https://streamlinehq.com
References (2)

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to LapSum-based Soft Top-K.