SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2106.03632 · NeurIPS · 2021

Quantifying and Improving Transferability in Domain Generalization

Han Zhao, Yaoliang Yu, Guojun Zhang, Pascal Poupart

arXiv · PDF · Open in the Atlas

Code that ran

3 of 5 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; 2 honoured the contract we drafted, 0 violated it and 0 have no contract verdict; 1 failure of our instrument; 2 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/2106.03632.json · badge: /api/ran/2106.03632.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
gordon-guojun-zhang/transferability-neurips2021 canonical (classifier label)
classifier basis: classifier_2025
3 ran · 1 no recorded run
facebookresearch/domainbed canonical (classifier label)
classifier basis: classifier_2025
0 ran · 1 no recorded run
FunctionStatusWhere it lives
distance Ran
ran, honoured the contract we drafted
gordon-guojun-zhang/transferability-neurips2021/domainbed/algorithms.py
code served (permissive licence) · get_code("fbb8c05a0a7696ec")
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

torch.manual_seed(0)

class SimpleClassifier(nn.Module):
    def __init__(self, input_dim=4, hidden_dim=3, output_dim=2):
        super().__init__()
        self.fc1 = nn.Linear(input_dim, hidden_dim)
        self.fc2 = nn.Linear(hidden_dim, output_dim)
    
    def forward(self, x):
        x = torch.relu(self.fc1(x))
        x = self.fc2(x)
        return x

h1 = SimpleClassifier(input_dim=4, hidden_dim=3, output_dim=2)
h2 = SimpleClassifier(input_dim=4, hidden_dim=3, output_dim=2)

ARGS = {
    "h1": h1,
    "h2": h2,
}
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
loss_gap Ran
ran, honoured the contract we drafted
gordon-guojun-zhang/transferability-neurips2021/domainbed/algorithms.py
code served (permissive licence) · get_code("937fa99d26cc548a")
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)

# Define a minimal model with the required structure
class SimpleModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.featurizer = nn.Linear(4, 8)
        self.adv_classifier = nn.Linear(8, 3)
    
    def forward(self, x):
        features = self.featurizer(x)
        return self.adv_classifier(features)

# Create model instance
model = SimpleModel()

# Create minibatches as list of (x, y) tuples
# Each x is a tensor of shape (2, 4), each y is a tensor of shape (2,)
minibatches = [
    (torch.randn(2, 4), torch.randint(0, 3, (2,))),
    (torch.randn(2, 4), torch.randint(0, 3, (2,))),
    (torch.randn(2, 4), torch.randint(0, 3, (2,)))
]

# Set device to CPU
device = 'cpu'

ARGS = {
    'minibatches': minibatches,
    'model': model,
    'device': device
}
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
proj Ran
ran; our contract draft was wrong, not the code
gordon-guojun-zhang/transferability-neurips2021/domainbed/algorithms.py
code served (permissive licence) · get_code("17202e0de9779f70")
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 SimpleClassifier. 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)

class SimpleClassifier(nn.Module):
    def __init__(self, input_dim=4, hidden_dim=3, output_dim=2):
        super().__init__()
        self.fc1 = nn.Linear(input_dim, hidden_dim)
        self.fc2 = nn.Linear(hidden_dim, output_dim)
    
    def forward(self, x):
        x = torch.relu(self.fc1(x))
        x = self.fc2(x)
        return x

# Create two classifier networks
h = SimpleClassifier(input_dim=4, hidden_dim=3, output_dim=2)
adv_h = SimpleClassifier(input_dim=4, hidden_dim=3, output_dim=2)

# Initialize adv_h with slightly different weights from h
with torch.no_grad():
    for param_adv, param_h in zip(adv_h.parameters(), h.parameters()):
        param_adv.copy_(param_h + torch.randn_like(param_h) * 0.1)

# delta is the radius of the ball for projection
delta = 0.5

ARGS = {
    'delta': delta,
    'adv_h': adv_h,
    'h': h
}
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 SimpleClassifier — a SimpleClassifier output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a SimpleClassifier 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
Transfer Not yet run
unverified (harvested, no recorded run)
gordon-guojun-zhang/transferability-neurips2021/domainbed/algorithms.py
code served (permissive licence) · get_code("408144eb3d7988bd")
How it ran

no invocation recorded.

get_algorithm_class Not yet run
unverified (harvested, no recorded run)
facebookresearch/domainbed/domainbed/algorithms.py
code served (permissive licence) · get_code("b0bc80b1655a6802")
How it ran

no invocation recorded.

Also present in other papers' code

Of 5 samples lifted from this paper's linked repositories, 5 carry a function identity and 0 do not. Of the 5 distinct functions with an identity, 3 are also present in other papers whose code we hold (1 with at least one paper dated earlier, 3 the same month, 3 later) and 2 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_algorithm_class 39 other papers
4 dated earlier, 2 the same month, 33 later
1907.02893 (2019-07)
Invariant Risk Minimization
2007.01434 (2020-07)
In Search of Lost Domain Generalization
2007.02931 (2020-07)
Adaptive Risk Minimization: Learning to Adapt to Domain Shift
and 36 more not named here
distance
brick of this paper's assembly: helper
4 other papers
1 the same month, 3 later · 1 only as an assembly brick
2106.07847 (2021-06)
Learning Stable Classifiers by Transferring Unstable Features
2307.12502 (2023-07)
Cross Contrasting Feature Perturbation for Domain Generalization
2401.14846 (2024-01)
Understanding Domain Generalization: A Noise Robustness Perspective
and 1 more not named here
proj
brick of this paper's assembly: helper
4 other papers
1 the same month, 3 later · 1 only as an assembly brick
2106.07847 (2021-06)
Learning Stable Classifiers by Transferring Unstable Features
2307.12502 (2023-07)
Cross Contrasting Feature Perturbation for Domain Generalization
2401.14846 (2024-01)
Understanding Domain Generalization: A Noise Robustness Perspective
and 1 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

Out-of-distribution generalization is one of the key challenges when transferring a model from the lab to the real world. Existing efforts mostly focus on building invariant features among source and target domains. Based on invariant features, a high-performing classifier on source domains could hopefully behave equally well on a target domain. In other words, we hope the invariant features to be transferable. However, in practice, there are no perfectly transferable features, and some algorithms seem to learn "more transferable" features than others. How can we understand and quantify such transferability? In this paper, we formally define transferability that one can quantify and compute in domain generalization. We point out the difference and connection with common discrepancy measures between domains, such as total variation and Wasserstein distance. We then prove that our transferability can be estimated with enough samples and give a new upper bound for the target error based on our transferability. Empirically, we evaluate the transferability of the feature embeddings learned by existing algorithms for domain generalization. Surprisingly, we find that many algorithms are not quite learning transferable features, although few could still survive. In light of this, we propose a new algorithm for learning transferable features and test it over various benchmark datasets, including RotatedMNIST, PACS, Office-Home and WILDS-FMoW. Experimental results show that the proposed algorithm achieves consistent improvement over many state-of-the-art algorithms, corroborating our theoretical findings. 1

For agents

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

get_harvested_code_for_paper("2106.03632")
get_code_for_paper("2106.03632")
have("2106.03632")

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

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

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

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

Connect an agent — have() is free.