SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2006.07682 · 2020

Rethinking Clustering for Robustness

arXiv · PDF · Open in the Atlas

Code that ran

10 of 10 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 9 have no contract verdict; 0 failures of our instrument; 0 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/2006.07682.json · badge: /api/ran/2006.07682.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
clustr-official-account/ClusTR-Clustering-Training-For-Robustness canonical (classifier label)
classifier basis: census
10 ran · 0 no recorded run
FunctionStatusWhere it lives
channelwise_clamp Ran
ran on a synthesized input
clustr-official-account/ClusTR-Clustering-Training-For-Robustness/utils/utils.py
code served (permissive licence) · get_code("361ae40c2d5f192d")
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 4, dtype family float, shape (2, 4, 3, 3) 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)

# Construct arguments for channelwise_clamp
# The function takes images (tensor), minima (tensor), and maxima (tensor)
# and clamps the images between minima and maxima values

images = torch.randn(2, 4, 3, 3)  # batch=2, channels=4, height=3, width=3
minima = torch.tensor(-1.0)  # scalar minimum value
maxima = torch.tensor(1.0)   # scalar maximum value

ARGS = {
    "images": images,
    "minima": minima,
    "maxima": maxima
}
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 4, dtype family float, shape (2, 4, 3, 3) — shape (2, 4, 3, 3) 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
check_best_model Ran
ran on a synthesized input
clustr-official-account/ClusTR-Clustering-Training-For-Robustness/utils/logging.py
code served (permissive licence) · get_code("e5cfb1003e643073")
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 tuple, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. 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 numpy as np

torch.manual_seed(0)

# Analyze the function:
# - best_acc: float, compared with threshold and test_acc
# - test_acc: float, compared with threshold and best_acc
# - best_pgd_acc: float, compared with pgd_acc
# - pgd_acc: float, compared with best_pgd_acc
# - threshold: float, default 80, compared with best_acc and test_acc

# The function takes accuracy values (floats) and performs comparisons.
# Let's construct realistic accuracy values (between 0 and 100)

ARGS = {
    'best_acc': 85.5,
    'test_acc': 87.3,
    'best_pgd_acc': 72.1,
    'pgd_acc': 74.8,
    'threshold': 80
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 1, dtype family float — a tuple output has no array shape of its own; none is stated
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
comparison_mask Ran
ran on a synthesized input
clustr-official-account/ClusTR-Clustering-Training-For-Robustness/utils/magnet_loss.py
code served (permissive licence) · get_code("dcae8a603be2929a")
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, 3) 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)

# Create sample label tensors
# a_labels: batch of 2 samples, each with a label (scalar per sample)
a_labels = torch.tensor([0, 1], dtype=torch.long)

# b_labels: batch of 3 samples, each with a label (scalar per sample)
b_labels = torch.tensor([0, 1, 2], dtype=torch.long)

ARGS = {
    "a_labels": a_labels,
    "b_labels": b_labels,
}
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, 3) — shape (2, 3) 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
compute_reps Ran
ran on a synthesized input
clustr-official-account/ClusTR-Clustering-Training-For-Robustness/utils/utils.py
code served (permissive licence) · get_code("e48868c62548940d")
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 tuple. The image it ran in was not recorded. The code mentions cuda, and the harness aliases cuda to the CPU for every sample; whether this run needed that is 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
from math import ceil

torch.manual_seed(0)

class SimpleModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 3)
    
    def forward(self, x):
        rep = self.linear(x)
        logit = rep.mean(dim=1, keepdim=True)
        return logit, rep

model = SimpleModel()
model.eval()

X = [
    (torch.randn(4), torch.tensor(0)),
    (torch.randn(4), torch.tensor(1)),
]

chunk_size = 2

ARGS = {
    'model': model,
    'X': X,
    'chunk_size': chunk_size,
}
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 tuple — a tuple 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
cross_ent Ran
ran on a synthesized input
clustr-official-account/ClusTR-Clustering-Training-For-Robustness/utils/magnet_training.py
code served (permissive licence) · get_code("077cd44913390626")
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 0, dtype family float, shape () 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.nn.functional as F

torch.manual_seed(0)

# Create small tensors for the function
batch_size = 2
num_classes = 4

# target_distrib: probability distribution over classes (batch_size x num_classes)
# Should sum to 1 along dim=1
target_distrib = torch.tensor([
    [0.1, 0.2, 0.3, 0.4],
    [0.25, 0.25, 0.25, 0.25]
], dtype=torch.float32)

# pred_scores: raw scores/logits (batch_size x num_classes)
pred_scores = torch.tensor([
    [1.0, 2.0, 0.5, 1.5],
    [0.2, 0.8, 1.2, 0.5]
], dtype=torch.float32)

ARGS = {
    "target_distrib": target_distrib,
    "pred_scores": pred_scores
}
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 0, dtype family float, shape () — shape () 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
dynamic_partition Ran
ran on a synthesized input
clustr-official-account/ClusTR-Clustering-Training-For-Robustness/utils/magnet_loss.py
code served (permissive licence) · get_code("be0af940bcd1b3dd")
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 tuple, ndim 3, dtype family float; no output shape is stated. The image it ran in was not recorded. 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 with batch size 2 and dimension 4
X = torch.randn(2, 4)

# Number of clusters to partition into
n_clusters = 2

ARGS = {
    "X": X,
    "n_clusters": n_clusters,
}
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 tuple, ndim 3, dtype family float — a tuple output has no array shape of its own; none is stated
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
expand_dims Ran
ran on a synthesized input
clustr-official-account/ClusTR-Clustering-Training-For-Robustness/utils/magnet_loss.py
code served (permissive licence) · get_code("365499eeb874b2da")
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 3, dtype family float, shape (1, 5, 2) 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)

# Create a small tensor with shape (5, 2)
var = torch.range(0, 9).view(-1, 2)

# The function takes two parameters: var and dim
# dim defaults to 0 but we can specify it
ARGS = {
    "var": var,
    "dim": 0
}
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 3, dtype family float, shape (1, 5, 2) — shape (1, 5, 2) 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
external_attack_pgd Ran
ran on a synthesized input
clustr-official-account/ClusTR-Clustering-Training-For-Robustness/utils/attacks.py
code served (permissive licence) · get_code("6fb401fb70224807")
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 4, dtype family float, shape (2, 3, 4, 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.nn as nn
import torch.nn.functional as F

torch.manual_seed(0)

# Build a minimal model that takes input and produces classification output
class SimpleClassifier(nn.Module):
    def __init__(self, num_classes=10):
        super().__init__()
        self.conv1 = nn.Conv2d(3, 8, kernel_size=3, padding=1)
        self.fc = nn.Linear(8 * 4 * 4, num_classes)
    
    def forward(self, x):
        x = F.relu(self.conv1(x))
        x = F.adaptive_avg_pool2d(x, (4, 4))
        x = x.view(x.size(0), -1)
        x = self.fc(x)
        return x

model = SimpleClassifier(num_classes=10)
model.eval()

# Create tiny batch: batch_size=2, channels=3, height=4, width=4
batch_size = 2
X = torch.randn(batch_size, 3, 4, 4)
y = torch.tensor([3, 7], dtype=torch.long)

# Epsilon per channel as nested tensor structure [[val]]
epsilon = torch.tensor([[[0.03]]], dtype=torch.float32)
epsilon = torch.cat([epsilon, epsilon, epsilon], dim=0)

# Attack parameters
alpha = 0.01
attack_iters = 2
restarts = 1
lower_limit = 0.0
upper_limit = 1.0
device = 'cpu'
chnls = 3
return_iters = False

ARGS = {
    'model': model,
    'X': X,
    'y': y,
    'epsilon': epsilon,
    'alpha': alpha,
    'attack_iters': attack_iters,
    'restarts': restarts,
    'lower_limit': lower_limit,
    'upper_limit': upper_limit,
    'device': device,
    'chnls': chnls,
    'return_iters': return_iters,
}
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 4, dtype family float, shape (2, 3, 4, 4) — shape (2, 3, 4, 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
get_lr Ran
ran, honoured the contract we drafted
clustr-official-account/ClusTR-Clustering-Training-For-Robustness/utils/logging.py
pointer only (licence: MIT); the stored copy get_code serves, from yjzhang96/UTI-VFI, is pointer only (licence: NONE) · get_code("7337f1f5ff01dcd0")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from yjzhang96/UTI-VFI, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

get_softmax_probs Ran
ran on a synthesized input
clustr-official-account/ClusTR-Clustering-Training-For-Robustness/utils/utils.py
code served (permissive licence) · get_code("52128432a5263eb8")
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, 3) 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.nn.functional as F

torch.manual_seed(0)

# Build magnet_data dict with all required keys
batch_size = 2
num_classes = 3
K = 2
L = 4
num_clusters = num_classes * K  # 6 clusters

# Create cluster centers: (num_clusters, embedding_dim)
cluster_centers = torch.randn(num_clusters, 4)

# Create variance: (num_clusters,)
variance = torch.ones(num_clusters) * 0.5

# Create cluster_classes: (num_clusters,) mapping each cluster to a class
cluster_classes = torch.tensor([0, 0, 1, 1, 2, 2])

# Create embeddings: (batch_size, embedding_dim)
embeddings = torch.randn(batch_size, 4)

magnet_data = {
    'cluster_centers': cluster_centers,
    'variance': variance,
    'cluster_classes': cluster_classes,
    'K': K,
    'L': L,
    'normalize_probs': True,
}

ARGS = {
    'embeddings': embeddings,
    'magnet_data': magnet_data,
    'return_scores': False,
}
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, 3) — shape (2, 3) 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

Also present in other papers' code

Of 10 samples lifted from this paper's linked repositories, 10 carry a function identity and 0 do not. Of the 10 distinct functions with an identity, 1 are also present in other papers whose code we hold (1 with at least one paper dated earlier, 0 the same month, 1 later) and 9 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
get_lr 25 other papers
5 dated earlier, 20 later · 2 only as an assembly brick
1605.07148 (2016-05)
Backprop KF: Learning Discriminative Deterministic State Estimators
1606.00915 (2016-06)
DeepLab: Semantic Image Segmentation with Deep Convolutional Nets, Atrous Convolution, and Fully Connected CRFs
1904.01355 (2019-04)
FCOS: Fully Convolutional One-Stage Object Detection
and 22 more not named here

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

This paper studies how encouraging semantically-aligned features during deep neural network training can increase network robustness. Recent works observed that Adversarial Training leads to robust models, whose learnt features appear to correlate with human perception. Inspired by this connection from robustness to semantics, we study the complementary connection: from semantics to robustness. To do so, we provide a robustness certificate for distance-based classification models (clustering-based classifiers). Moreover, we show that this certificate is tight, and we leverage it to propose ClusTR (Clustering Training for Robustness), a clustering-based and adversary-free training framework to learn robust models. Interestingly, \textit{ClusTR} outperforms adversarially-trained networks by up to $4\%$ under strong PGD attacks.

For agents

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

get_harvested_code_for_paper("2006.07682")
get_code_for_paper("2006.07682")
have("2006.07682")

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

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

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

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

Connect an agent — have() is free.