diffsort - Differentiable Sorting Networks
Official implementation for our ICLR 2022 Paper "Monotonic Differentiable Sorting Networks" and our ICML 2021 Paper "Differentiable Sorting Networks for Scalable Sorting and Ranking Supervision". In this work, we leverage classic sorting networks and relax them to propose a new differentiable sorting function: diffsort. This allows propagating gradients through (an approximation of) the sorting / ranking function / operation. Herein, diffsort outperforms existing differentiable sorting functions on the four-digit MNIST and the SVHN sorting tasks. In this repo, we present the PyTorch implementation of differentiable sorting networks.
Video @ Youtube.
💻 Installation
diffsort can be installed via pip from PyPI with
pip install diffsort
Or from source, e.g., in a virtual environment like
virtualenv -p python3 .env1
. .env1/bin/activate
pip install .
👩💻 Usage
import torch
from diffsort import DiffSortNet
vector_length = 2**4
vectors = torch.randperm(vector_length, dtype=torch.float32, device='cpu', requires_grad=True).view(1, -1)
vectors = vectors - 5.
# sort using a bitonic-sorting-network
sorter = DiffSortNet('bitonic', vector_length, steepness=5)
sorted_vectors, permutation_matrices = sorter(vectors)
print(sorted_vectors)
🧪 Experiments
You can find the main experiment in this Colab notebook.
You can run the four-digit MNIST experiment as
python experiments/main.py -n 5 -m odd_even -s 10 -d mnist
or for the bitonic network
python experiments/main.py -n 16 -m bitonic -s 20 -d mnist
or for SVHN
python experiments/main.py -n 5 -m odd_even -s 10 -d svhn
📖 Citing
@inproceedings{petersen2022monotonic,
title={Monotonic Differentiable Sorting Networks},
author={Petersen, Felix and Borgelt, Christian and Kuehne, Hilde and Deussen, Oliver},
booktitle={International Conference on Learning Representations (ICLR)},
year={2022}
}
@inproceedings{petersen2021diffsort,
title={Differentiable Sorting Networks for Scalable Sorting and Ranking Supervision},
author={Petersen, Felix and Borgelt, Christian and Kuehne, Hilde and Deussen, Oliver},
booktitle={International Conference on Machine Learning (ICML)},
year={2021}
}
License
diffsort is released under the MIT license. See LICENSE for additional details about it.
Release files for diffsort 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| diffsort-0.2.0.tar.gz | 6.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| diffsort-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size:13.4 kB
Release files / diffsort-0.2.0.tar.gz
| Download URL | diffsort-0.2.0.tar.gz |
|---|---|
| Size | 6.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9af05f475cd7c5bd307d8489d3fefe1c3ec26d639f7fd2c0f0ecb0ed48d91f98
|
|
BLAKE2b-256 checksum How to use checksums |
dffdcdd10e3e47069a1bfceb50212cb33935388d5939a731bcbb7e76152ffbd5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/29.0 requests/2.24.0 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.48.2 importlib-metadata/4.5.0 keyring/23.0.1 rfc3986/1.5.0 colorama/0.4.3 CPython/3.8.12
|
Release files / diffsort-0.2.0-py3-none-any.whl
| Download URL | diffsort-0.2.0-py3-none-any.whl |
|---|---|
| Size | 7.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
95bd5541ade48919cd926366f83165e07645b6e62fe798343b7f0d0332b8a08b
|
|
BLAKE2b-256 checksum How to use checksums |
b6f3d2b1d966189805bc1074ad056c1d4397363071c08944807270f53ce73191
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/29.0 requests/2.24.0 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.48.2 importlib-metadata/4.5.0 keyring/23.0.1 rfc3986/1.5.0 colorama/0.4.3 CPython/3.8.12
|