SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2206.07290 · ICML · 2022

Differentiable Top-k Classification Learning

Felix Petersen, Christian Borgelt, Hilde Kuehne, Oliver Deussen

arXiv · PDF · Open in the Atlas

Code that ran

9 of 12 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 1 honoured the contract we drafted, 0 violated it and 5 have no contract verdict; 3 failures of our instrument; 3 no recorded run), measured 2026-11-22; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2206.07290.json · badge: /api/ran/2206.07290.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
felix-petersen/difftopk canonical (classifier label)
classifier basis not recorded on the link
9 ran · 3 no recorded run
FunctionStatusWhere it lives
conv1x1 Ran
ran; our contract draft was wrong, not the code
felix-petersen/difftopk/experiments/utils/resnet_cifar10.py
code served (permissive licence) · get_code("d9def42110729a85")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned Conv2d. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

# The function conv1x1 takes in_planes, out_planes, and stride as parameters
# It returns an nn.Conv2d layer configured for 1x1 convolution
# We need to provide valid integer arguments for these parameters

ARGS = {
    "in_planes": 3,
    "out_planes": 64,
    "stride": 1
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Conv2d — a Conv2d output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a Conv2d output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
conv3x3 Ran
ran; our contract draft was wrong, not the code
felix-petersen/difftopk/experiments/utils/resnet_cifar10.py
code served (permissive licence) · get_code("160bb14bd76201b4")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned Conv2d. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

ARGS = {
    "in_planes": 3,
    "out_planes": 64,
    "stride": 1,
    "groups": 1,
    "dilation": 1,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Conv2d — a Conv2d output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a Conv2d output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
delta Ran
ran on a synthesized input
felix-petersen/difftopk/difftopk/smooth_topk.py
code served (permissive licence) · get_code("2e2b18b4902bdec8")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 2, dtype family float; no output shape is stated. It ran in syntology-harvest-sandbox:v5-deps (sha256:6a292aa1aed1) at 2026-09-27T00:36:13Z. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.autograd as ag

torch.manual_seed(0)

# Create small tensors for testing
# y: predictions/logits, shape (batch_size,)
y = torch.tensor([0, 1], dtype=torch.long)

# labels: ground truth labels, shape (num_classes,)
labels = torch.tensor([0, 1, 2], dtype=torch.long)

# alpha: optional scaling factor
alpha = 0.5

ARGS = {
    "y": y,
    "labels": labels,
    "alpha": alpha,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 2, dtype family float — no output shape is stated: no later run recorded an output shape for this sample (observed_output and metamorphic_properties carry none; shape_contract and output_contract record ndim only)
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image syntology-harvest-sandbox:v5-deps (sha256:6a292aa1aed1); not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_sparse_net Ran
ran on a synthesized input
felix-petersen/difftopk/difftopk/networks.py
code served (permissive licence) · get_code("512081e219515760")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned list. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

torch.manual_seed(0)

# The function expects `net` to be an iterable of lists/tuples
# Each element in net is a list where:
# - First 4 elements (l[:4]) are tensors that get converted to sparse COO tensors
# - Remaining elements (l[4:]) are passed through as-is

# Create small tensors with distinct shapes for different dimensions
tensor1 = torch.randn(4, 3)
tensor2 = torch.randn(5, 2)
tensor3 = torch.randn(3, 4)
tensor4 = torch.randn(6, 3)

# Create some non-sparse elements to pass through (e.g., bias vectors or other params)
other_param1 = torch.randn(3)
other_param2 = torch.randn(2)

# Build a layer: 4 tensors to convert to sparse + 2 other params
layer1 = [tensor1, tensor2, tensor3, tensor4, other_param1, other_param2]

# Build another layer for completeness
tensor5 = torch.randn(4, 5)
tensor6 = torch.randn(3, 3)
tensor7 = torch.randn(2, 4)
tensor8 = torch.randn(5, 2)

other_param3 = torch.randn(4)

layer2 = [tensor5, tensor6, tensor7, tensor8, other_param3]

# Create the net as a list of layers
net = [layer1, layer2]

ARGS = {
    "net": net
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list — a list output has no array shape of its own; none is stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
log Ran
ran; our contract draft was wrong, not the code
felix-petersen/difftopk/difftopk/smooth_topk.py
code served (permissive licence) · get_code("8a24f02d6735ca80")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 2, dtype family float, shape (2, 4) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.autograd as ag

torch.manual_seed(0)

# Create a small tensor to use as the 'like' parameter
like_tensor = torch.randn(2, 4)

# Create a LogTensor object
log_tensor_obj = torch.tensor([[-0.5, -1.0, -0.3, -2.0], [-0.1, -0.8, -1.5, -0.4]])

# Create a Number (scalar value)
number_value = 0.5

ARGS = {
    'x': number_value,
    'like': like_tensor
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 2, dtype family float, shape (2, 4) — shape (2, 4) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
log1mexp Ran
ran on a synthesized input
felix-petersen/difftopk/difftopk/smooth_topk.py
code served (permissive licence) · get_code("b02fd556128a43d3")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 2, dtype family float; no output shape is stated. It ran in syntology-harvest-sandbox:v5-deps (sha256:6a292aa1aed1) at 2026-09-27T00:36:13Z. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

torch.manual_seed(0)

# Create a small tensor U with values <= 0
# The function expects U to contain negative values
U = torch.randn(2, 4)  # Shape (2, 4) - batch of 2, dim 4
U = -torch.abs(U)  # Ensure all values are <= 0

eps = 0.001

ARGS = {
    "U": U,
    "eps": eps,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 2, dtype family float — no output shape is stated: no later run recorded an output shape for this sample (observed_output and metamorphic_properties carry none; shape_contract and output_contract record ndim only)
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image syntology-harvest-sandbox:v5-deps (sha256:6a292aa1aed1); not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
s_best Ran
ran, honoured the contract we drafted
felix-petersen/difftopk/difftopk/functional.py
code served (permissive licence) · get_code("5e1f120cec901868")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 2, dtype family float, shape (2, 4) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

torch.manual_seed(0)

# The function s_best takes a single tensor argument x
# and applies clamping and conditional operations on it.
# We need to provide a small tensor as input.

x = torch.randn(2, 4)

ARGS = {
    "x": x
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 2, dtype family float, shape (2, 4) — shape (2, 4) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
sparse_bitonic_network Ran
ran on a synthesized input
felix-petersen/difftopk/difftopk/networks.py
code served (permissive licence) · get_code("88eb794650370b33")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned list. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import math
import numpy as np

# The function sparse_bitonic_network takes a single parameter 'n'
# which represents the size of the bitonic network.
# Looking at the function body:
# - n is used in math.ceil(np.log2(n))
# - n is used in assertions and loops
# - It must be a positive integer
# The function works with powers of 2, so let's use n=4

ARGS = {
    "n": 4
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list — a list output has no array shape of its own; none is stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
sparse_splitter_selection_network Ran
ran on a synthesized input
felix-petersen/difftopk/difftopk/networks.py
code served (permissive licence) · get_code("f0090ee92df35030")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned list. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import math
import numpy as np

# The function sparse_splitter_selection_network takes two parameters: n and k
# Looking at the function body:
# - n is used as the number of elements/lanes
# - k is the number of top elements to select
# - Both are integers
# - The function validates that k < n (implicitly, since we're selecting top k from n)

ARGS = {
    'n': 8,
    'k': 3
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list — a list output has no array shape of its own; none is stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
execute_sparse_topk Not yet run
unverified (harvested, no recorded run)
felix-petersen/difftopk/difftopk/functional.py
code served (permissive licence) · get_code("11e43cd1e6c797b8")
How it ran

no invocation recorded.

execute_topk Not yet run
unverified (harvested, no recorded run)
felix-petersen/difftopk/difftopk/functional.py
code served (permissive licence) · get_code("1e01148f1f64e131")
How it ran

no invocation recorded.

resnet18 Not yet run
unverified (harvested, no recorded run)
felix-petersen/difftopk/experiments/utils/resnet_cifar10.py
code served (permissive licence) · get_code("2615428ce71ead9f")
How it ran

no invocation recorded.

Also present in other papers' code

Of 12 samples lifted from this paper's linked repositories, 12 carry a function identity and 0 do not. Of the 12 distinct functions with an identity, 7 are also present in other papers whose code we hold (7 with at least one paper dated earlier, 1 the same month, 4 later) and 5 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

FunctionAlso present inEarliest-datedOthers named
conv1x1 431 other papers
192 dated earlier, 1 the same month, 226 later, 11 same year, order not determinable, 1 undated · 38 only as an assembly brick
1409.1556 (2014-09)
Very Deep Convolutional Networks for Large-Scale Image Recognition
1506.01186 (2015-06)
Cyclical Learning Rates for Training Neural Networks
1507.05717 (2015-07)
An End-to-End Trainable Neural Network for Image-based Sequence Recognition and Its Application to Scene Text Recognition
and 428 more not named here
conv3x3 312 other papers
121 dated earlier, 181 later, 9 same year, order not determinable, 1 undated · 31 only as an assembly brick
1409.1556 (2014-09)
Very Deep Convolutional Networks for Large-Scale Image Recognition
1507.05717 (2015-07)
An End-to-End Trainable Neural Network for Image-based Sequence Recognition and Its Application to Scene Text Recognition
1512.03385 (2015-12)
Deep Residual Learning for Image Recognition
and 309 more not named here
resnet18 6 other papers
1 dated earlier, 5 later
1802.10026 (2018-02)
Loss Surfaces, Mode Connectivity, and Fast Ensembling of DNNs
2301.11578 (2023-01)
Learning to Unlearn: Instance-wise Unlearning for Pre-trained Classifiers
2403.01101 (2024-03)
Feature Alignment: Rethinking Efficient Active Learning via Proxy in the Context of Pre-trained Models
and 3 more not named here
s_best 2 other papers
1 dated earlier, 1 later · 1 only as an assembly brick
2105.04019 (2021-05)
Differentiable Sorting Networks for Scalable Sorting and Ranking Supervision
2310.07174 (2023-10)
Generalized Neural Sorting Networks with Error-Free Differentiable Swap Functions
delta 1 other paper
1 dated earlier
1802.07595 (2018-02)
Smooth Loss Functions for Deep Top-k Classification
log 1 other paper
1 dated earlier
1802.07595 (2018-02)
Smooth Loss Functions for Deep Top-k Classification
log1mexp 1 other paper
1 dated earlier
1802.07595 (2018-02)
Smooth Loss Functions for Deep Top-k Classification

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-22.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

The top-k classification accuracy is one of the core metrics in machine learning. Here, k is conventionally a positive integer, such as 1 or 5, leading to top-1 or top-5 training objectives. In this work, we relax this assumption and optimize the model for multiple k simultaneously instead of using a single k. Leveraging recent advances in differentiable sorting and ranking, we propose a differentiable top-k cross-entropy classification loss. This allows training the network while not only considering the top-1 prediction, but also, e.g., the top-2 and top-5 predictions. We evaluate the proposed loss function for fine-tuning on state-of-the-art architectures, as well as for training from scratch. We find that relaxing k does not only produce better top-5 accuracies, but also leads to top-1 accuracy improvements. When finetuning publicly available ImageNet models, we achieve a new state-of-the-art for these models.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2206.07290")
get_code_for_paper("2206.07290")
have("2206.07290")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2206.07290.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2206.07290.svg)](https://syntology.ai/paper/2206.07290)

Connect an agent — have() is free.