SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 1906.07413 · 2019

Learning Imbalanced Datasets with Label-Distribution-Aware Margin Loss

Adrien Gaidon, Colin Wei, Tengyu Ma, Kaidi Cao, Nikos Arechiga

arXiv · PDF · Open in the Atlas

Code that ran

6 of 11 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (1 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 2 have no contract verdict; 4 failures of our instrument; 5 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/1906.07413.json · badge: /api/ran/1906.07413.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
ihaeyong/maximum-margin-ldam community (classifier label)
classifier basis not recorded on the link
5 ran · 3 no recorded run
karurb92/ldam_str_bn community
Papers with Code archive
1 ran · 0 no recorded run
orparask/VS-Loss community
Papers with Code archive
0 ran · 1 no recorded run
jackhck/subclass-balancing-contrastive-learning community
Papers with Code archive
0 ran · 1 no recorded run
FunctionStatusWhere it lives
LDAMLoss Ran
ran on a synthesized input · constructed an object; no result was computed
karurb92/ldam_str_bn/losses.py
pointer only (licence: NONE) · get_code("62c8aa90e3fb2973")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, karurb92/ldam_str_bn 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.

focal_loss Ran
ran; our contract draft was wrong, not the code
ihaeyong/maximum-margin-ldam/losses.py
pointer only (licence: MIT); the stored copy get_code serves, from tmlr-group/atol, is pointer only (licence: NONE) · get_code("4dcf06ba28983266")
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 tmlr-group/atol, 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.

obj_margins Ran
ran on a synthesized input
ihaeyong/maximum-margin-ldam/cifar_train.py
code served (permissive licence) · get_code("26d27ecdc945d123")
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, 1) 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)

# Analyzing the function:
# - rm_obj_dists: used with F.softmax(dim=1), so 2D tensor (batch_size, num_classes)
# - labels: used with labels.data.cpu().numpy()[0] to index into obj_dists_, so 1D tensor
# - index_float: multiplied with obj_dists_ (element-wise), so same shape as obj_dists_
# - max_m: scalar used in arithmetic operations
# - gamma: scalar with default 10.0

batch_size = 2
num_classes = 4

# rm_obj_dists: (batch_size, num_classes) logits/distances
rm_obj_dists = torch.randn(batch_size, num_classes)

# labels: (batch_size,) with class indices - need at least one valid class index
labels = torch.tensor([1, 2])

# index_float: (batch_size, num_classes) one-hot or soft labels
# Create one-hot encoding matching labels
index_float = torch.zeros(batch_size, num_classes)
index_float[0, labels[0]] = 1.0
index_float[1, labels[1]] = 1.0

# max_m: scalar margin parameter
max_m = torch.tensor(0.5)

# gamma: scalar parameter (has default)
gamma = 10.0

ARGS = {
    "rm_obj_dists": rm_obj_dists,
    "labels": labels,
    "index_float": index_float,
    "max_m": max_m,
    "gamma": gamma
}
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 Tensor, ndim 2, dtype family float, shape (2, 1) — shape (2, 1) 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
plot_confusion_matrix Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
ihaeyong/maximum-margin-ldam/utils.py
code served (permissive licence) · get_code("e5ce72a1e8d9bc22")
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 Axes. 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 matplotlib.pyplot as plt
from sklearn.metrics import confusion_matrix

# Create sample data for a multi-class classification problem
np.random.seed(0)

# True labels: 20 samples with 3 classes (0, 1, 2)
y_true = np.array([0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1])

# Predicted labels: 20 samples with some errors
y_pred = np.array([0, 1, 2, 0, 1, 1, 0, 2, 2, 0, 1, 2, 0, 0, 2, 1, 1, 2, 0, 1])

# Class names
classes = np.array(['Class A', 'Class B', 'Class C'])

ARGS = {
    'y_true': y_true,
    'y_pred': y_pred,
    'classes': classes,
    'normalize': False,
    'title': 'Test Confusion Matrix',
    'cmap': plt.cm.Blues
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
matplotlib, numpy, sklearn — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Axes — a Axes output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a Axes 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
resnet32 Ran
ran; our contract draft was wrong, not the code
ihaeyong/maximum-margin-ldam/models/resnet_cifar.py
code served (permissive licence) · get_code("11d038f53d77a8d2")
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 ResNet_s. 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 = {
    'num_classes': 10,
    'use_norm': 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 ResNet_s — a ResNet_s output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a ResNet_s 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
to_onehot Ran
ran; our contract draft was wrong, not the code
ihaeyong/maximum-margin-ldam/utils.py
code served (permissive licence) · get_code("83b8128b16e83cfc")
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 (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

torch.manual_seed(0)

# Create a 1D tensor with class indices
# vec should contain values in range [0, num_classes)
vec = torch.tensor([0, 2, 1, 3], dtype=torch.long)

# Number of classes
num_classes = 4

# Fill value for one-hot encoding
fill = 1000

ARGS = {
    "vec": vec,
    "num_classes": num_classes,
    "fill": fill,
}
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 (4, 4) — shape (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
LDAMLoss Not yet run
unverified (harvested, no recorded run)
orparask/VS-Loss/class_imbalance/losses.py
pointer only (licence: NONE) · get_code("6683ac6a76084b68")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, orparask/VS-Loss 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. No invocation recorded.

LDAMLoss Not yet run
unverified (harvested, no recorded run)
jackhck/subclass-balancing-contrastive-learning/SimCLR/loss.py
pointer only (licence: NONE) · get_code("a3ce423c36d71133")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, jackhck/subclass-balancing-contrastive-learning 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. No invocation recorded.

accuracy Not yet run
unverified (harvested, no recorded run)
ihaeyong/maximum-margin-ldam/utils.py
pointer only (licence: MIT); the stored copy get_code serves, from francisanokye/Audio-Signal-Processing, is pointer only (licence: NONE) · get_code("688c38ac8517471a")
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 francisanokye/Audio-Signal-Processing, 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. No invocation recorded.

ldam_loss Not yet run
unverified (harvested, no recorded run)
ihaeyong/maximum-margin-ldam/cifar_train.py
code served (permissive licence) · get_code("6feb1ddb1872cd29")
How it ran

no invocation recorded.

weight Not yet run
unverified (harvested, no recorded run)
ihaeyong/maximum-margin-ldam/cifar_train.py
code served (permissive licence) · get_code("75d3d8bc39a6d61b")
How it ran

no invocation recorded.

Also present in other papers' code

Of 11 samples lifted from this paper's linked repositories, 11 carry a function identity and 0 do not. Of the 10 distinct functions with an identity, 5 are also present in other papers whose code we hold (1 with at least one paper dated earlier, 1 the same month, 5 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
accuracy 80 other papers
21 dated earlier, 1 the same month, 58 later
1307.0414 (2013-07)
Challenges in Representation Learning: A report on three machine learning contests
1412.6553 (2014-12)
Speeding-up Convolutional Neural Networks Using Fine-tuned CP-Decomposition
1503.02531 (2015-03)
Distilling the Knowledge in a Neural Network
and 77 more not named here
focal_loss 14 other papers
14 later
2107.09249 (2021-07)
Self-Supervised Aggregation of Diverse Experts for Test-Agnostic Long-Tailed Recognition
2304.09426 (2023-04)
Decoupled Training for Long-Tailed Classification With Stochastic Representations
and 11 more not named here
resnet32 9 other papers
9 later
2104.00466 (2021-04)
Improving Calibration for Long-Tailed Recognition
2106.10891 (2021-06)
Open-set Label Noise Can Improve Robustness Against Inherent Label Noise
2111.03874 (2021-11)
Towards Calibrated Model for Long-Tailed Visual Recognition from Prior Perspective
and 6 more not named here
plot_confusion_matrix 3 other papers
3 later
2111.03874 (2021-11)
Towards Calibrated Model for Long-Tailed Visual Recognition from Prior Perspective
2304.09426 (2023-04)
Decoupled Training for Long-Tailed Classification With Stochastic Representations
to_onehot 2 other papers
2 later · 1 only as an assembly brick
2205.01297 (2022-05)
RU-Net: Regularized Unrolling Network for Scene Graph Generation
2205.01316 (2022-05)
HL-Net: Heterophily Learning Network for Scene Graph Generation

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

Deep learning algorithms can fare poorly when the training dataset suffers from heavy class-imbalance but the testing criterion requires good generalization on less frequent classes. We design two novel methods to improve performance in such scenarios. First, we propose a theoretically-principled label-distribution-aware margin (LDAM) loss motivated by minimizing a margin-based generalization bound. This loss replaces the standard cross-entropy objective during training and can be applied with prior strategies for training with class-imbalance such as re-weighting or re-sampling. Second, we propose a simple, yet effective, training schedule that defers re-weighting until after the initial stage, allowing the model to learn an initial representation while avoiding some of the complications associated with re-weighting or re-sampling. We test our methods on several benchmark vision tasks including the real-world imbalanced dataset iNaturalist 2018. Our experiments show that either of these methods alone can already improve over existing techniques and their combination achieves even better performance gains 1 .

For agents

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

get_harvested_code_for_paper("1906.07413")
get_code_for_paper("1906.07413")
have("1906.07413")

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

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

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

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

Connect an agent — have() is free.