{"id":19401124,"url":"https://github.com/google-research/fast-soft-sort","last_synced_at":"2025-04-04T16:14:40.711Z","repository":{"id":45775533,"uuid":"270845191","full_name":"google-research/fast-soft-sort","owner":"google-research","description":"Fast Differentiable Sorting and Ranking","archived":false,"fork":false,"pushed_at":"2024-02-15T03:26:44.000Z","size":36,"stargazers_count":592,"open_issues_count":16,"forks_count":48,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-03-28T15:06:51.257Z","etag":null,"topics":["differentiable","jax","pytorch","ranking","sorting","tensorflow"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/google-research.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-06-08T22:28:01.000Z","updated_at":"2025-03-16T02:20:50.000Z","dependencies_parsed_at":"2024-11-24T13:02:03.550Z","dependency_job_id":null,"html_url":"https://github.com/google-research/fast-soft-sort","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google-research%2Ffast-soft-sort","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google-research%2Ffast-soft-sort/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google-research%2Ffast-soft-sort/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google-research%2Ffast-soft-sort/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/google-research","download_url":"https://codeload.github.com/google-research/fast-soft-sort/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247208150,"owners_count":20901570,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["differentiable","jax","pytorch","ranking","sorting","tensorflow"],"created_at":"2024-11-10T11:17:17.724Z","updated_at":"2025-04-04T16:14:40.673Z","avatar_url":"https://github.com/google-research.png","language":"Python","readme":"\nFast Differentiable Sorting and Ranking\n=======================================\n\nDifferentiable sorting and ranking operations in O(n log n).\n\nDependencies\n------------\n\n* NumPy\n* SciPy\n* Numba\n* Tensorflow (optional)\n* PyTorch (optional)\n\nTensorFlow Example\n-------------------\n\n```python\n\u003e\u003e\u003e import tensorflow as tf\n\u003e\u003e\u003e from fast_soft_sort.tf_ops import soft_rank, soft_sort\n\u003e\u003e\u003e values = tf.convert_to_tensor([[5., 1., 2.], [2., 1., 5.]], dtype=tf.float64)\n\u003e\u003e\u003e soft_sort(values, regularization_strength=1.0)\n\u003ctf.Tensor: shape=(2, 3), dtype=float64, numpy= array([[1.66666667, 2.66666667, 3.66666667], [1.66666667, 2.66666667, 3.66666667]])\u003e\n\u003e\u003e\u003e soft_sort(values, regularization_strength=0.1)\n\u003ctf.Tensor: shape=(2, 3), dtype=float64, numpy= array([[1., 2., 5.], [1., 2., 5.]])\u003e\n\u003e\u003e\u003e soft_rank(values, regularization_strength=2.0)\n\u003ctf.Tensor: shape=(2, 3), dtype=float64, numpy= array([[3. , 1.25, 1.75], [1.75, 1.25, 3. ]])\u003e\n\u003e\u003e\u003e soft_rank(values, regularization_strength=1.0)\n\u003ctf.Tensor: shape=(2, 3), dtype=float64, numpy= array([[3., 1., 2.], [2., 1., 3.]])\u003e\n```\n\nJAX Example\n-----------\n\n```python\n\u003e\u003e\u003e import jax.numpy as jnp\n\u003e\u003e\u003e from fast_soft_sort.jax_ops import soft_rank, soft_sort\n\u003e\u003e\u003e values = jnp.array([[5., 1., 2.], [2., 1., 5.]], dtype=jnp.float64)\n\u003e\u003e\u003e soft_sort(values, regularization_strength=1.0)\n[[1.66666667 2.66666667 3.66666667]\n [1.66666667 2.66666667 3.66666667]]\n\u003e\u003e\u003e soft_sort(values, regularization_strength=0.1)\n[[1. 2. 5.]\n [1. 2. 5.]]\n\u003e\u003e\u003e soft_rank(values, regularization_strength=2.0)\n[[3.   1.25 1.75]\n [1.75 1.25 3.  ]]\n\u003e\u003e\u003e soft_rank(values, regularization_strength=1.0)\n[[3. 1. 2.]\n [2. 1. 3.]]\n```\n\nPyTorch Example\n---------------\n\n```python\n\u003e\u003e\u003e import torch\n\u003e\u003e\u003e from pytorch_ops import soft_rank, soft_sort\n\u003e\u003e\u003e values = fast_soft_sort.torch.tensor([[5., 1., 2.], [2., 1., 5.]], dtype=torch.float64)\n\u003e\u003e\u003e soft_sort(values, regularization_strength=1.0)\ntensor([[1.6667, 2.6667, 3.6667]\n        [1.6667, 2.6667, 3.6667]], dtype=torch.float64)\n\u003e\u003e\u003e soft_sort(values, regularization_strength=0.1)\ntensor([[1., 2., 5.]\n        [1., 2., 5.]], dtype=torch.float64)\n\u003e\u003e\u003e soft_rank(values, regularization_strength=2.0)\ntensor([[3.0000, 1.2500, 1.7500],\n        [1.7500, 1.2500, 3.0000]], dtype=torch.float64)\n\u003e\u003e\u003e soft_rank(values, regularization_strength=1.0)\ntensor([[3., 1., 2.]\n        [2., 1., 3.]], dtype=torch.float64)\n```\n\n\nInstall\n--------\n\nRun `python setup.py install` or copy the `fast_soft_sort/` folder to your\nproject.\n\n\nReference\n------------\n\n\u003e Fast Differentiable Sorting and Ranking\n\u003e Mathieu Blondel, Olivier Teboul, Quentin Berthet, Josip Djolonga\n\u003e In proceedings of ICML 2020\n\u003e [arXiv:2002.08871](https://arxiv.org/abs/2002.08871)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoogle-research%2Ffast-soft-sort","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoogle-research%2Ffast-soft-sort","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoogle-research%2Ffast-soft-sort/lists"}