SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2110.05025 · 2021

Self-supervised Learning is More Robust to Dataset Imbalance

arXiv · PDF · Open in the Atlas

Code that ran

3 of 4 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 0 have no contract verdict; 2 failures of our instrument; 1 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/2110.05025.json · badge: /api/ran/2110.05025.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
Liuhong99/Imbalanced-SSL canonical (classifier label)
classifier basis: classifier_2025
2 ran · 1 no recorded run
copy not recorded community
not in the paper's declared repositories
1 ran · 0 no recorded run
FunctionStatusWhere it lives
CrossEntropyLoss1 Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
Liuhong99/Imbalanced-SSL/imagenet/pretrain_moco_sam_rare.py
code served (permissive licence) · get_code("b58f7b3f0347a073")
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 as nn
import torch.nn.functional as F

torch.manual_seed(0)

# Small batch size (2 samples), 4 classes
batch_size = 2
num_classes = 4

# label: tensor of class indices, shape (batch_size,)
label = torch.tensor([0, 2], dtype=torch.long)

# predict_prob: raw logits before softmax, shape (batch_size, num_classes)
predict_prob = torch.randn(batch_size, num_classes)

# class_level_weight: optional weight per class, shape (1, num_classes)
class_level_weight = torch.ones(1, num_classes)

# instance_level_weight: optional weight per instance, shape (batch_size, 1)
instance_level_weight = torch.ones(batch_size, 1)

# epsilon: small constant for numerical stability
epsilon = 1e-12

ARGS = {
    'label': label,
    'predict_prob': predict_prob,
    'class_level_weight': class_level_weight,
    'instance_level_weight': instance_level_weight,
    'epsilon': epsilon
}
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
accuracy Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
this paper's copy was not recorded; identical code first harvested from joshr17/IFM
pointer only · get_code("983576fa67f4f01e")
How it ran

The body of this sample is withheld: this paper's copy of the code was not recorded (its link names no repository or source path), so no licence was read for it. 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.

train Ran
ran, honoured the contract we drafted
Liuhong99/Imbalanced-SSL/cifar/main_sam_exp.py
code served (permissive licence) · get_code("ee45897c218040d1")
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 float, ndim 0, dtype family float, shape () as a later run recorded it. 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, 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

torch.manual_seed(0)

# Define a mock model that returns the required outputs
class MockModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.fc = nn.Linear(4, 4)
    
    def forward(self, im_aug1, im_aug2):
        # Return dict with required keys
        z1 = self.fc(im_aug1)
        z2 = self.fc(im_aug2)
        p1 = self.fc(im_aug1)
        p2 = self.fc(im_aug2)
        return {
            'z1': z1,
            'z2': z2,
            'p1': p1,
            'p2': p2
        }

# Define a mock criterion that accepts the required arguments
class MockCriterion(nn.Module):
    def __init__(self):
        super().__init__()
    
    def forward(self, z1, z2, p1, p2, weight):
        # Return a scalar loss
        return (z1.mean() + z2.mean() + p1.mean() + p2.mean()) * 0.25

# Define a mock optimizer with first_step and second_step methods
class MockOptimizer:
    def __init__(self, model):
        self.model = model
    
    def first_step(self, zero_grad=False):
        if zero_grad:
            for param in self.model.parameters():
                if param.grad is not None:
                    param.grad.zero_()
    
    def second_step(self, zero_grad=False):
        if zero_grad:
            for param in self.model.parameters():
                if param.grad is not None:
                    param.grad.zero_()

# Create train_loader with 2 batches of 2 samples each
# Each sample is a tuple of (images, targets)
# images is a list of 2 augmented views, targets is a tensor
train_loader = [
    (
        [torch.randn(2, 4), torch.randn(2, 4)],  # images: 2 views of shape [batch_size, 4]
        torch.randint(0, 5, (2,))  # targets: shape [batch_size]
    ),
    (
        [torch.randn(2, 4), torch.randn(2, 4)],
        torch.randint(0, 5, (2,))
    )
]

# Create mock args object
class Args:
    def __init__(self):
        self.gpu = None  # CPU only
        self.print_freq = 1

args = Args()

# Create model, criterion, optimizer
model = MockModel()
criterion = MockCriterion()
optimizer = MockOptimizer(model)
epoch = 0

# Define ARGS dict with all parameters for the train function
ARGS = {
    'train_loader': train_loader,
    'model': model,
    'criterion': criterion,
    'optimizer': optimizer,
    'epoch': epoch,
    'args': args
}
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 float, 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
load_checkpoint Not yet run
unverified (harvested, no recorded run)
Liuhong99/Imbalanced-SSL/cifar/main_sam_exp.py
code served (permissive licence) · get_code("715aadc8b870f357")
How it ran

no invocation recorded.

Also present in other papers' code

Of 4 samples lifted from this paper's linked repositories, 4 carry a function identity and 0 do not. Of the 4 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 3 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
accuracy 17 other papers
5 dated earlier, 12 later
1805.03438 (2018-05)
Robust Classification with Convolutional Prototype Learning
1905.11926 (2019-05)
Network Deconvolution
2003.04297 (2020-03)
Improved Baselines with Momentum Contrastive Learning
and 14 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

Self-supervised learning (SSL) is a scalable way to learn general visual representations since it learns without labels. However, large-scale unlabeled datasets in the wild often have long-tailed label distributions, where we know little about the behavior of SSL. In this work, we systematically investigate self-supervised learning under dataset imbalance. First, we find out via extensive experiments that off-the-shelf self-supervised representations are already more robust to class imbalance than supervised representations. The performance gap between balanced and imbalanced pre-training with SSL is significantly smaller than the gap with supervised learning, across sample sizes, for both in-domain and, especially, out-of-domain evaluation. Second, towards understanding the robustness of SSL, we hypothesize that SSL learns richer features from frequent data: it may learn label-irrelevant-but-transferable features that help classify the rare classes and downstream tasks. In contrast, supervised learning has no incentive to learn features irrelevant to the labels from frequent examples. We validate this hypothesis with semi-synthetic experiments and theoretical analyses on a simplified setting. Third, inspired by the theoretical insights, we devise a re-weighted regularization technique that consistently improves the SSL representation quality on imbalanced datasets with several evaluation criteria, closing the small gap between balanced and imbalanced datasets with the same number of examples.

For agents

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

get_harvested_code_for_paper("2110.05025")
get_code_for_paper("2110.05025")
have("2110.05025")

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

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

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

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

Connect an agent — have() is free.