Skip to main content
QUICK REVIEW

[Paper Review] Differentiable Ranks and Sorting using Optimal Transport

Marco Cuturi, Olivier Teboul|arXiv (Cornell University)|May 28, 2019
Machine Learning and AlgorithmsComputer Science39 references11 citations
TL;DR

This paper proposes differentiable proxies for sorting and ranking using optimal transport (OT) with entropic regularization, enabling end-to-end training in deep learning. By formulating sorting as an OT assignment problem and solving it via Sinkhorn iterations, the method produces smooth, differentiable rank and sort operators that outperform non-differentiable baselines in quantile regression and classification tasks.

ABSTRACT

Sorting an array is a fundamental routine in machine learning, one that is used to compute rank-based statistics, cumulative distribution functions (CDFs), quantiles, or to select closest neighbors and labels. The sorting function is however piece-wise constant (the sorting permutation of a vector does not change if the entries of that vector are infinitesimally perturbed) and therefore has no gradient information to back-propagate. We propose a framework to sort elements that is algorithmically differentiable. We leverage the fact that sorting can be seen as a particular instance of the optimal transport (OT) problem on $\mathbb{R}$, from input values to a predefined array of sorted values (e.g. $1,2,\dots,n$ if the input array has $n$ elements). Building upon this link , we propose generalized CDFs and quantile operators by varying the size and weights of the target presorted array. Because this amounts to using the so-called Kantorovich formulation of OT, we call these quantities K-sorts, K-CDFs and K-quantiles. We recover differentiable algorithms by adding to the OT problem an entropic regularization, and approximate it using a few Sinkhorn iterations. We call these operators S-sorts, S-CDFs and S-quantiles, and use them in various learning settings: we benchmark them against the recently proposed neuralsort [Grover et al. 2019], propose applications to quantile regression and introduce differentiable formulations of the top-k accuracy that deliver state-of-the art performance.

Motivation & Objective

  • To address the non-differentiability of standard sorting and ranking operations in deep learning pipelines.
  • To develop smooth, differentiable alternatives to the discrete rank and sort operators that are essential in metrics like top-k accuracy and loss functions such as 0/1 and quantile regression.
  • To leverage optimal transport theory to generalize sorting beyond n-to-n mappings, allowing flexible target measures with m ≠ n points.
  • To enable the use of ranking-based metrics as differentiable training objectives by replacing discrete operations with smooth, gradient-friendly alternatives.
  • To demonstrate practical utility through applications in quantile regression and multiclass classification with smooth approximations of the 0/1 loss.

Proposed method

  • Formulates sorting as an optimal assignment problem between input values and a target measure on m increasing values, generalizing standard n-to-n sorting.
  • Introduces Kantorovich rank and sort operators as convex combinations of ranks and sorted values via optimal transport plans.
  • Regularizes the OT problem with an entropic penalty to enable efficient solution via the Sinkhorn algorithm, achieving O(nmℓ) complexity with ℓ iterations.
  • Uses a differentiable squashing function and cost function to stabilize gradients, with empirical evidence that whitening inputs to [0,1] improves numerical stability.
  • Applies the smoothed operators to define differentiable proxies for the 0/1 loss in classification and the quantile regression loss in regression tasks.
  • Employs mini-batch optimization with soft quantile estimation using the Sinkhorn rank operator, replacing discrete selection of quantile points with differentiable soft selection.

Experimental results

Research questions

  • RQ1Can sorting and ranking be made differentiable while preserving their semantic meaning in machine learning tasks?
  • RQ2How can optimal transport be used to generalize the standard sorting operation beyond n-to-n mappings?
  • RQ3What is the impact of entropic regularization and Sinkhorn iteration on the differentiability and numerical stability of rank and sort operators?
  • RQ4Can differentiable rank and sort operators improve training dynamics in quantile regression and classification?
  • RQ5How do choices in cost function, target vector, and squashing function affect gradient stability in the regularized OT framework?

Key findings

  • The proposed soft quantile operator with ε = 10⁻² achieves better training quantile errors than the non-differentiable baseline (ε = 0), particularly at the 50% and 90% quantiles across multiple datasets.
  • Test set performance, measured by quantile error and MSE, remains comparable between the proposed method and the baseline, indicating no degradation in generalization despite improved training optimization.
  • The method achieves stable training with minimal hyperparameter tuning, and numerical stability is significantly improved when inputs are whitened and squashed to [0,1] prior to processing.
  • The size of the target measure (m) can be reduced to as small as 3 without significant loss in performance, demonstrating the method’s flexibility and efficiency.
  • The differentiable rank and sort operators enable the use of ranking-based metrics like top-k accuracy and 0/1 loss as differentiable training objectives, enabling end-to-end learning.
  • Empirical results show that the smoothed optimization landscape reduces local minima, leading to more consistent convergence in quantile regression tasks.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.