SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 1901.05555 · 2019

Class-Balanced Loss Based on Effective Number of Samples

Yang Song, Serge Belongie, Tsung-Yi Lin, Yin Cui, Menglin Jia

arXiv · PDF · Open in the Atlas

Code that ran

15 of 27 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (2 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 13 have no contract verdict; 2 failures of our instrument; 12 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/1901.05555.json · badge: /api/ran/1901.05555.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
richardaecn/class-balanced-loss canonical (classifier label)
classifier basis: census
8 ran · 11 no recorded run
lijian16/fcc community
Papers with Code archive
2 ran · 0 no recorded run
bazinga699/ncl community
Papers with Code archive
2 ran · 0 no recorded run
vandit15/Class-balanced-loss-pytorch community
Papers with Code archive
1 ran · 1 no recorded run
frgfm/Holocron community
Papers with Code archive
1 ran · 0 no recorded run
statsu1990/yoto_class_balanced_loss community
Papers with Code archive
1 ran · 0 no recorded run
FunctionStatusWhere it lives
CB_loss Ran
ran; our contract draft was wrong, not the code
vandit15/Class-balanced-loss-pytorch/class_balanced_loss.py
code served (permissive licence) · get_code("213dab5ee3c9a730")
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 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
import numpy as np

torch.manual_seed(0)

# Set up parameters for CB_loss function
batch_size = 2
no_of_classes = 4

# labels: A int tensor of size [batch]
labels = torch.tensor([0, 2], dtype=torch.long)

# logits: A float tensor of size [batch, no_of_classes]
logits = torch.randn(batch_size, no_of_classes, dtype=torch.float32)

# samples_per_cls: A python list of size [no_of_classes]
samples_per_cls = [10, 20, 15, 25]

# loss_type: string. One of "sigmoid", "focal", "softmax"
loss_type = "focal"

# beta: float. Hyperparameter for Class balanced loss
beta = 0.9999

# gamma: float. Hyperparameter for Focal loss
gamma = 2.0

ARGS = {
    "labels": labels,
    "logits": logits,
    "samples_per_cls": samples_per_cls,
    "no_of_classes": no_of_classes,
    "loss_type": loss_type,
    "beta": beta,
    "gamma": gamma,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
numpy, 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
ClassBalanceCE Ran
ran on a synthesized input · constructed an object; no result was computed
lijian16/fcc/lib/loss/loss_impl/class_balanced_loss.py
code served (permissive licence) · get_code("749ae093d1002dc8")
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 an instance of its own class, ClassBalanceCE: the run constructed the object and did not call it, so no result was computed. 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 numpy as np
import torch.nn as nn

torch.manual_seed(0)

class Config:
    class TRAIN:
        class TWO_STAGE:
            DRW = False
            START_EPOCH = 1
    
    class LOSS:
        class ClassBalanceCE:
            BETA = 0.9999

# Create configuration object
cfg = Config()

# Setup parameters for ClassBalanceCE
num_classes = 4
num_class_list = [100, 80, 60, 50]  # number of samples per class
device = 'cpu'

para_dict = {
    'num_classes': num_classes,
    'num_class_list': num_class_list,
    'device': device,
    'cfg': cfg
}

ARGS = {
    'para_dict': para_dict
}
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 ClassBalanceCE — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a ClassBalanceCE 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
ClassBalancedWrapper Ran
ran on a synthesized input
frgfm/Holocron/holocron/nn/modules/loss.py
code served (permissive licence) · get_code("fa48de5142876479")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) 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
from torch import nn, Tensor

# Create a simple loss criterion
criterion = nn.CrossEntropyLoss()

# Define number of samples per class (3 classes)
num_samples = torch.tensor([10, 20, 30], dtype=torch.float32)

# Define INIT_ARGS for ClassBalancedWrapper.__init__
INIT_ARGS = {
    'criterion': criterion,
    'num_samples': num_samples,
    'beta': 0.99
}

# Define ARGS for ClassBalancedWrapper.forward
# Batch size 2, 3 classes (logits), 3 class targets
ARGS = {
    'x': torch.randn(2, 3),
    'target': torch.tensor([0, 2], dtype=torch.long)
}

# Import and construct the class
from typing import Any, cast

class ClassBalancedWrapper(nn.Module):
    """Implementation of the class-balanced loss as described in ["Class-Balanced Loss Based on Effective Number
    of Samples"](https://arxiv.org/pdf/1901.05555.pdf).

    Given a loss function $\\mathcal{L}$, the class-balanced loss is described by:

    $$
    CB(p, y) = \\frac{1 - \\beta}{1 - \\beta^{n_y}} \\mathcal{L}(p, y)
    $$

    where $p$ is the predicted probability for class $y$, $n_y$ is the number of training
    samples for class $y$, and $\\beta$ is exponential factor.

    Args:
        criterion: loss module
        num_samples: number of samples for each class
        beta: rebalancing exponent
    """

    def __init__(self, criterion: nn.Module, num_samples: Tensor, beta: float=0.99) -> None:
        super().__init__()
        self.criterion = criterion
        self.beta: float = beta
        cb_weights = (1 - beta) / (1 - beta ** num_samples)
        if self.criterion.weight is None:
            self.criterion.weight: Tensor | None = cb_weights
        else:
            self.criterion.weight *= cb_weights.to(device=self.criterion.weight.device)

    def forward(self, x: Tensor, target: Tensor) -> Tensor:
        return cast(Tensor, self.criterion.forward(x, target))

    def __repr__(self) -> str:
        return f'{self.__class__.__name__}({self.criterion.__repr__()}, beta={self.beta})'


# Construct and call the class
instance = ClassBalancedWrapper(**INIT_ARGS)
output = instance(**ARGS)
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
ClassBalanced_CELoss Ran
ran on a synthesized input · constructed an object; no result was computed
statsu1990/yoto_class_balanced_loss/src/model/cb_loss.py
code served (permissive licence) · get_code("68d1f62eac95f880")
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 an instance of its own class, ClassBalanced_CELoss: the run constructed the object and did not call it, so no result was computed. 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
import numpy as np

torch.manual_seed(0)

# Create reference labels for class balancing
# We need labels that span multiple classes for the loss to work
reference_labels = np.array([0, 0, 1, 1, 2, 2, 3])

# Number of classes
num_class = 4

# Beta parameter for class balancing
beta = 0.999

ARGS = {
    'reference_labels': reference_labels,
    'num_class': num_class,
    'beta': beta
}
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 ClassBalanced_CELoss — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a ClassBalanced_CELoss 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
CrossEntropy Ran
ran on a synthesized input
lijian16/fcc/lib/loss/loss_impl/class_balanced_loss.py
code served (permissive licence) · get_code("03ec3d933bc9e286")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned Tensor, ndim 0, 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 torch.nn as nn

class MockConfig:
    class TRAIN:
        class TWO_STAGE:
            DRW = True
            START_EPOCH = 5
    
cfg = MockConfig()

num_classes = 5
num_class_list = [100, 80, 60, 40, 20]  # per-class sample counts
batch_size = 2

para_dict = {
    'num_classes': num_classes,
    'num_class_list': num_class_list,
    'device': 'cpu',
    'cfg': cfg
}

INIT_ARGS = {
    'para_dict': para_dict
}

inputs = torch.randn(batch_size, num_classes)
targets = torch.randint(0, num_classes, (batch_size,))

ARGS = {
    'inputs': inputs,
    'targets': targets
}
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
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 — no output shape is stated: observe_signature.py observed this class with its constructor sizes canonicalised where it could, which the node does not record, so its shape is not stated as this setup block's
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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
NBOD Ran
ran; our contract draft was wrong, not the code
bazinga699/ncl/lib/loss/loss.py
code served (permissive licence) · get_code("e4d180e212ea7092")
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 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
from torch.nn import functional as F

torch.manual_seed(0)

# The function expects:
# - inputs: a list of tensors (logits from multiple classifiers)
# - factor: a scalar (weighting factor for the loss)

# Create a list of logit tensors
# Each tensor should have shape (batch_size, num_classes)
# Using batch_size=2 and num_classes=4 as specified
batch_size = 2
num_classes = 4

# Create 3 classifier outputs (logits)
logits_1 = torch.randn(batch_size, num_classes)
logits_2 = torch.randn(batch_size, num_classes)
logits_3 = torch.randn(batch_size, num_classes)

inputs = [logits_1, logits_2, logits_3]
factor = 0.5

ARGS = {
    "inputs": inputs,
    "factor": factor
}
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 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
NIL_NBOD Ran
ran on a synthesized input
bazinga699/ncl/lib/loss/loss.py
code served (permissive licence) · get_code("49b09b16b775ec58")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned Tensor, ndim 0, 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 torch.nn as nn

# Create a minimal config object
class Config:
    class LOSS:
        class MULTI_CLASIIFIER_LOSS:
            DIVERSITY_FACTOR = 0.5
            DIVERSITY_FACTOR_HCM = 0.3
        HCM_N = 3
        HCM_RATIO = 0.7
        CE_RATIO = 1.0

cfg = Config()

# Number of classes
num_classes = 5
# Number of classifiers
classifier_num = 3
# Batch size
batch_size = 2

# Create num_class_list (class distribution for balancing)
num_class_list = [10, 20, 15, 25, 30]  # Example class counts

INIT_ARGS = {
    'para_dict': {
        'num_class_list': num_class_list,
        'device': 'cpu',
        'cfg': cfg
    }
}

# Create inputs: list of logits from multiple classifiers
# Shape: (classifier_num, batch_size, num_classes)
inputs = [torch.randn(batch_size, num_classes) for _ in range(classifier_num)]

# Create targets: ground truth labels
# Shape: (classifier_num, batch_size)
targets = [torch.randint(0, num_classes, (batch_size,)) for _ in range(classifier_num)]

ARGS = {
    'inputs': inputs,
    'targets': targets
}
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
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 — no output shape is stated: observe_signature.py observed this class with its constructor sizes canonicalised where it could, which the node does not record, so its shape is not stated as this setup block's
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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
convert_array_to_image Ran
ran on a synthesized input
richardaecn/class-balanced-loss/tpu/models/experimental/dcgan/cifar_input.py
code served (permissive licence) · get_code("44a9936773ea082c")
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 Image. 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 numpy as np
import torch

# The function expects a numpy array that will be:
# 1. Added to 1.0
# 2. Divided by 2.0
# 3. Multiplied by 255
# 4. Converted to uint8
# 5. Passed to Image.fromarray with mode='RGB'

# For mode='RGB', the array needs to have shape (height, width, 3)
# The input array is expected to be in range [-1, 1] based on the rescaling formula

# Create a small test array in the expected range [-1, 1]
# Shape: (4, 3, 3) for height=4, width=3, channels=3
test_array = np.array([
    [[0.5, -0.5, 0.0], [0.2, -0.8, 0.9], [-0.3, 0.7, -0.1]],
    [[0.1, -0.2, 0.4], [-0.5, 0.6, -0.9], [0.8, -0.4, 0.3]],
    [[-0.1, 0.9, -0.5], [0.2, -0.3, 0.7], [-0.8, 0.1, 0.5]],
    [[0.6, -0.7, 0.2], [-0.4, 0.8, -0.2], [0.3, -0.6, 0.9]]
], dtype=np.float32)

ARGS = {
    'array': test_array
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
PIL, numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Image — a Image output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a Image output the recorded ndim 3 and dtype family int 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
dir2version Ran
ran on a synthesized input
richardaecn/class-balanced-loss/src/cifar_main.py
code served (permissive licence) · get_code("90a8002ad4ce5c44")
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 str. 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

# The function splits a directory path by '/' and takes the last element,
# then splits that by '-' and takes the second element (index 1)
# So we need a path like: "some/path/prefix-version"

data_dir = "models/experiment-v1.0"

ARGS = {
    "data_dir": data_dir
}
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 str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str 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
get_imbalanced_data Ran
ran on a synthesized input
richardaecn/class-balanced-loss/src/generate_cifar_tfrecords_im.py
code served (permissive licence) · get_code("ea12a62c609bc291")
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 dict. 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 random

# Set seed for reproducibility
random.seed(0)

# Construct training_data: dict mapping class indices to lists of image IDs
training_data = {
    0: [f"img_{i}" for i in range(10)],
    1: [f"img_{i}" for i in range(10, 20)],
    2: [f"img_{i}" for i in range(20, 30)],
}

# Construct img_num_per_cls: dict mapping class indices to number of images per class
img_num_per_cls = {
    0: 5,
    1: 3,
    2: 7,
}

ARGS = {
    "training_data": training_data,
    "img_num_per_cls": img_num_per_cls,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict 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
img_num Ran
ran on a synthesized input
richardaecn/class-balanced-loss/src/data_utils.py
code served (permissive licence) · get_code("4f59b56fcbea8270")
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 int, ndim 0, dtype family int, 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

torch.manual_seed(0)

ARGS = {
    'cifar_version': '10'
}
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 int, ndim 0, dtype family int, 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
learning_rate_schedule Ran
ran on a synthesized input
richardaecn/class-balanced-loss/src/cifar_main.py
code served (permissive licence) · get_code("10fc348fea580bf2")
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 EagerTensor, 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 tensorflow as tf

# Set up the arguments for learning_rate_schedule function
current_epoch = tf.constant(3, dtype=tf.float32)
base_learning_rate = 0.1
lr_boundaries = [5, 10, 15]
lr_multiplier = [0.5, 0.1, 0.01]

ARGS = {
    "current_epoch": current_epoch,
    "base_learning_rate": base_learning_rate,
    "lr_boundaries": lr_boundaries,
    "lr_multiplier": lr_multiplier,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
tensorflow — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type EagerTensor, 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
local_device_setter Ran
ran on a synthesized input
richardaecn/class-balanced-loss/src/cifar_utils.py
code served (permissive licence) · get_code("667cea6bb6608b7b")
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 function. 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 six
from tensorflow.core.framework import node_def_pb2
from tensorflow.python.framework import device as pydev
from tensorflow.python.training import device_setter


class MockOp:
    """Mock operation object that mimics TensorFlow op interface."""
    def __init__(self, op_type='MatMul', device=''):
        self.device = device
        self.node_def = node_def_pb2.NodeDef()
        self.node_def.op = op_type
        self.node_def.name = 'test_op'


class MockStrategy:
    """Mock callable strategy for device assignment."""
    def __init__(self, num_devices=1):
        self.num_devices = num_devices
        self.counter = 0
    
    def __call__(self, op):
        result = self.counter % self.num_devices
        self.counter += 1
        return result


ARGS = {
    'num_devices': 2,
    'ps_device_type': 'cpu',
    'worker_device': '/cpu:0',
    'ps_ops': ['Variable', 'VariableV2', 'VarHandleOp'],
    'ps_strategy': MockStrategy(num_devices=2)
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
six, tensorflow — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type function — a function output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a function 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
read_json Ran
ran on a synthesized input
richardaecn/class-balanced-loss/src/data_utils.py
code served (permissive licence) · get_code("35ae8c0dce858108")
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 dict. 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 json
import tempfile
import os

# Create a temporary directory and a temporary JSON file
temp_dir = tempfile.mkdtemp()
json_file_path = os.path.join(temp_dir, "test.json")

# Create a valid JSON file with sample data
test_data = {
    "key1": "value1",
    "key2": [1, 2, 3],
    "key3": {"nested": "object"}
}

with open(json_file_path, 'w') as f:
    json.dump(test_data, f)

# Define ARGS with the path to the JSON file
ARGS = {
    "data_dir": json_file_path
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict 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
sort_input Ran
ran on a synthesized input
richardaecn/class-balanced-loss/src/generate_cifar_tfrecords_im.py
code served (permissive licence) · get_code("c20afab5ec1e1d08")
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 dict. 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 numpy as np

torch.manual_seed(0)

# Analyzing the function:
# - im_data: a dict where keys are class indices and values are lists of image id strings
#   The strings are formatted as 'batch_name/image_number' (e.g., 'data_batch_1/5')
# - cifar_version: either '10' or '100' (a string)

# Constructing im_data with proper format
im_data = {
    0: ['data_batch_1/5', 'data_batch_1/10'],
    1: ['data_batch_2/3', 'data_batch_3/7'],
    2: ['data_batch_4/1', 'data_batch_5/2']
}

cifar_version = '10'

ARGS = {
    'im_data': im_data,
    'cifar_version': cifar_version
}
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 dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict 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
discriminator Not yet run
unverified (harvested, no recorded run)
richardaecn/class-balanced-loss/tpu/models/experimental/dcgan/cifar_model.py
code served (permissive licence) · get_code("59ec4e09ac2ce079")
How it ran

no invocation recorded.

focal_loss Not yet run
unverified (harvested, no recorded run)
vandit15/Class-balanced-loss-pytorch/class_balanced_loss.py
code served (permissive licence) · get_code("c32ccdb4e101c470")
How it ran

no invocation recorded.

generate_input_fn Not yet run
unverified (harvested, no recorded run)
richardaecn/class-balanced-loss/tpu/models/experimental/dcgan/dcgan_main.py
code served (permissive licence) · get_code("787ada018be76773")
How it ran

no invocation recorded.

generator Not yet run
unverified (harvested, no recorded run)
richardaecn/class-balanced-loss/tpu/models/experimental/dcgan/cifar_model.py
code served (permissive licence) · get_code("6bfcb692805e9db9")
How it ran

no invocation recorded.

get_traindata_list Not yet run
unverified (harvested, no recorded run)
richardaecn/class-balanced-loss/src/generate_cifar_tfrecords_im.py
code served (permissive licence) · get_code("306ffaa84f8da0c6")
How it ran

no invocation recorded.

input_fn Not yet run
unverified (harvested, no recorded run)
richardaecn/class-balanced-loss/tpu/models/experimental/cifar_keras/cifar_keras.py
code served (permissive licence) · get_code("57184f395fe4ff8f")
How it ran

no invocation recorded.

model_fn Not yet run
unverified (harvested, no recorded run)
richardaecn/class-balanced-loss/tpu/models/experimental/cifar_keras/cifar_keras.py
code served (permissive licence) · get_code("a8d0a5e19105636a")
How it ran

no invocation recorded.

model_fn Not yet run
unverified (harvested, no recorded run)
richardaecn/class-balanced-loss/tpu/models/experimental/dcgan/dcgan_main.py
code served (permissive licence) · get_code("7634c2c31837e3f5")
How it ran

no invocation recorded.

noise_input_fn Not yet run
unverified (harvested, no recorded run)
richardaecn/class-balanced-loss/tpu/models/experimental/dcgan/dcgan_main.py
code served (permissive licence) · get_code("f3d3946d06874d2a")
How it ran

no invocation recorded.

parser Not yet run
unverified (harvested, no recorded run)
richardaecn/class-balanced-loss/tpu/models/experimental/dcgan/cifar_input.py
code served (permissive licence) · get_code("1863a653dad9ca35")
How it ran

no invocation recorded.

read_pickle_from_file Not yet run
unverified (harvested, no recorded run)
richardaecn/class-balanced-loss/src/data_utils.py
code served (permissive licence) · get_code("162b6ba3306530cc")
How it ran

no invocation recorded.

read_pickle_from_file Not yet run
unverified (harvested, no recorded run)
richardaecn/class-balanced-loss/src/generate_cifar_tfrecords.py
code served (permissive licence) · get_code("7137e8ae47a966ce")
How it ran

no invocation recorded.

Also present in other papers' code

Of 27 samples lifted from this paper's linked repositories, 27 carry a function identity and 0 do not. Of the 26 distinct functions with an identity, 6 are also present in other papers whose code we hold (3 with at least one paper dated earlier, 0 the same month, 3 later) and 20 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
focal_loss
brick of this paper's assembly: loss
3 other papers
3 later
2210.11065 (2022-10)
MovieCLIP: Visual Scene Recognition in Movies
2302.08872 (2023-02)
Revisiting adversarial training for the worst-performing class
2310.02861 (2023-10)
Rayleigh Quotient Graph Neural Networks for Graph-level Anomaly Detection
CB_loss
brick of this paper's assembly: entry
1 other paper
1 later
2302.08872 (2023-02)
Revisiting adversarial training for the worst-performing class
generate_input_fn 1 other paper
1 dated earlier
1809.10636 (2018-09)
Conditional WaveGAN
local_device_setter 1 other paper
1 later
1910.13598 (2019-10)
Local SGD with Periodic Averaging: Tighter Analysis and Adaptive Synchronization
noise_input_fn 1 other paper
1 dated earlier
1809.10636 (2018-09)
Conditional WaveGAN
read_pickle_from_file 1 other paper
1 dated earlier
1803.10228 (2018-03)
Demystifying Differentiable Programming: Shift/Reset the Penultimate Backpropagator

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

With the rapid increase of large-scale, real-world datasets, it becomes critical to address the problem of longtailed data distribution (i.e., a few classes account for most of the data, while most classes are under-represented). Existing solutions typically adopt class re-balancing strategies such as re-sampling and re-weighting based on the number of observations for each class. In this work, we argue that as the number of samples increases, the additional benefit of a newly added data point will diminish. We introduce a novel theoretical framework to measure data overlap by associating with each sample a small neighboring region rather than a single point. The effective number of samples is defined as the volume of samples and can be calculated by a simple formula (1-β n )/(1-β), where n is the number of samples and β ∈ [0, 1) is a hyperparameter. We design a re-weighting scheme that uses the effective number of samples for each class to re-balance the loss, thereby yielding a class-balanced loss. Comprehensive experiments are conducted on artificially induced long-tailed CIFAR datasets and large-scale datasets including ImageNet and iNaturalist. Our results show that when trained with the proposed class-balanced loss, the network is able to achieve significant performance gains on long-tailed datasets. * The work was performed while Yin Cui and Yang Song worked at Google (a subsidiary of Alphabet Inc.).

For agents

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

get_harvested_code_for_paper("1901.05555")
get_code_for_paper("1901.05555")
have("1901.05555")

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

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

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

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

Connect an agent — have() is free.