SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2103.03230 · ICML · 2021

Barlow Twins: Self-Supervised Learning via Redundancy Reduction

Ishan Misra, Jure Zbontar, Li Jing, Yann Lecun, Stéphane Deny

arXiv · PDF · Open in the Atlas

Code that ran

21 of 26 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (6 of them constructed an object rather than computing a result; 2 honoured the contract we drafted, 1 violated it and 12 have no contract verdict; 6 failures of our instrument; 5 no recorded run), measured 2026-11-21; 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/2103.03230.json · badge: /api/ran/2103.03230.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
facebookresearch/barlowtwins canonical (classifier label)
classifier basis: classifier_2025
1 ran · 0 no recorded run
jeffwiroj/robust_tutorial community
Papers with Code archive
3 ran · 0 no recorded run
lightly-ai/lightly community
Papers with Code archive
3 ran · 0 no recorded run
gaborvecsei/Barlow-Twins community
Papers with Code archive
3 ran · 0 no recorded run
Pangoraw/GeoSSL community
Papers with Code archive
2 ran · 1 no recorded run
FloCF/SSL_pytorch community
Papers with Code archive
2 ran · 0 no recorded run
MaxLikesMath/Barlow-Twins-Pytorch community
Papers with Code archive
2 ran · 0 no recorded run
leot13/BarlowTwins community
Papers with Code archive
1 ran · 0 no recorded run
naver/tldr community
Papers with Code archive
1 ran · 0 no recorded run
IgorSusmelj/barlowtwins reimplementation (classifier label)
classifier basis: classifier_2025
1 ran · 0 no recorded run
zcao0420/moformer community
Papers with Code archive
1 ran · 0 no recorded run
pbielak/graph-barlow-twins extension (classifier label)
classifier basis: classifier_2025
1 ran · 0 no recorded run
facebookresearch/clip-rocket community
Papers with Code archive
0 ran · 1 no recorded run
beresandras/contrastive-classification-keras community
Papers with Code archive
0 ran · 1 no recorded run
kalelpark/FG-SSL community
Papers with Code archive
0 ran · 1 no recorded run
yaohungt/Barlow-Twins-HSIC reimplementation (classifier label)
classifier basis: classifier_2025
0 ran · 1 no recorded run
FunctionStatusWhere it lives
BarlowTwin Ran
ran on a synthesized input · constructed an object; no result was computed
jeffwiroj/robust_tutorial/bt_exp/barlow_twin/bt.py
pointer only (licence: NONE) · get_code("c7572ab85515d03b")
How it ran

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

BarlowTwins Ran
ran on a synthesized input · constructed an object; no result was computed
leot13/BarlowTwins/model.py
pointer only (licence: NONE) · get_code("e1c7432eaf01c11e")
How it ran

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

BarlowTwins Ran
ran on a synthesized input · constructed an object; no result was computed
FloCF/SSL_pytorch/torchselfsup/models/barlow_twins.py
code served (permissive licence) · get_code("252dd592b0af15de")
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, BarlowTwins: 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 torch.nn as nn

torch.manual_seed(0)

class SimpleBackbone(nn.Module):
    """Minimal backbone that outputs representation of size repre_dim"""
    def __init__(self, input_dim: int, output_dim: int):
        super().__init__()
        self.linear = nn.Linear(input_dim, output_dim)
    
    def forward(self, x):
        return self.linear(x)

# Create backbone that takes input of dim 4 and outputs repre_dim of 8
backbone_net = SimpleBackbone(input_dim=4, output_dim=8)

# Define arguments for BarlowTwins
ARGS = {
    "backbone_net": backbone_net,
    "repre_dim": 8,
    "projector_hidden": (16, 16, 8),
    "λ": 0.0051
}
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 BarlowTwins — 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 BarlowTwins 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
BarlowTwins Ran
ran on a synthesized input · constructed an object; no result was computed
MaxLikesMath/Barlow-Twins-Pytorch/Twins/barlow.py
code served (permissive licence) · get_code("7c1ae63680739389")
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, BarlowTwins: 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 torch.nn as nn

torch.manual_seed(0)

# Create a simple backbone model
class SimpleBackbone(nn.Module):
    def __init__(self):
        super().__init__()
        self.conv1 = nn.Conv2d(3, 8, kernel_size=3, padding=1)
        self.fc1 = nn.Linear(8 * 4 * 4, 16)
        self.fc2 = nn.Linear(16, 32)
    
    def forward(self, x):
        # x shape: (batch, 3, 4, 4)
        x = self.conv1(x)  # (batch, 8, 4, 4)
        x = x.view(x.size(0), -1)  # (batch, 128)
        x = self.fc1(x)  # (batch, 16)
        x = self.fc2(x)  # (batch, 32)
        return x

backbone = SimpleBackbone()

# latent_id specifies which layer to extract representations from
# Using -2 means second-to-last layer (the fc1 output before fc2)
latent_id = -2

# projection_sizes: input size must match the output of the backbone layer
# The latent layer outputs 16 dims, then we project to 32, then to 8
projection_sizes = [16, 32, 8]

# lambd: tradeoff parameter between on-diagonal and off-diagonal terms
lambd = 0.005

# scale_factor: scaling for the loss
scale_factor = 1.0

ARGS = {
    'backbone': backbone,
    'latent_id': latent_id,
    'projection_sizes': projection_sizes,
    'lambd': lambd,
    'scale_factor': scale_factor,
}
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 BarlowTwins — 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 BarlowTwins 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
BarlowTwins Ran
ran on a synthesized input
Pangoraw/GeoSSL/geossl/barlowtwins.py
code served (permissive licence) · get_code("666e333d72371dc9")
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
from typing import Optional

# Build a minimal ResNetBackbone
backbone = nn.Module()
backbone.out_dim = 8
backbone.forward = lambda x: torch.randn(x.shape[0], 8)

INIT_ARGS = {
    'backbone': backbone,
    'lambd': 0.005,
    'batch_size': 2,
    'h_dim': 12,
    'num_proj_layers': 2
}

ARGS = {
    'x1': torch.randn(2, 3, 32, 32),
    'x2': torch.randn(2, 3, 32, 32)
}
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
torch, torchvision — 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)
BarlowTwinsLoss Ran
ran; our contract draft was wrong, not the code
naver/tldr/tldr/loss.py
pointer only (licence: NOASSERTION) · get_code("d799236e3db12e5f")
How it ran

The body of this sample is withheld: GitHub could not classify the licence of this paper's repository, naver/tldr (NOASSERTION). 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.

BarlowTwinsLoss Ran
ran on a synthesized input
IgorSusmelj/barlowtwins/loss.py
code served (permissive licence) · get_code("158c8987347b3ecf")
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

INIT_ARGS = {
    'device': 'cpu',
    'lambda_param': 0.005,
}

ARGS = {
    'z_a': torch.randn(2, 4),
    'z_b': torch.randn(2, 4),
}

if __name__ == '__main__':
    from torch import nn
    
    class BarlowTwinsLoss(nn.Module):
        def __init__(self, device, lambda_param=0.005):
            super(BarlowTwinsLoss, self).__init__()
            self.lambda_param = lambda_param
            self.device = device

        def forward(self, z_a: torch.Tensor, z_b: torch.Tensor):
            z_a_norm = (z_a - z_a.mean(0)) / z_a.std(0)
            z_b_norm = (z_b - z_b.mean(0)) / z_b.std(0)
            N = z_a.size(0)
            D = z_a.size(1)
            c = torch.mm(z_a_norm.T, z_b_norm) / N
            c_diff = (c - torch.eye(D, device=self.device)).pow(2)
            c_diff[~torch.eye(D, dtype=bool)] *= self.lambda_param
            loss = c_diff.sum()
            return loss
    
    model = BarlowTwinsLoss(**INIT_ARGS)
    output = model(**ARGS)
    print(f"Loss output: {output}")
    print(f"Output shape: {output.shape}")
    print(f"Output type: {type(output)}")
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)
BarlowTwinsLoss Ran
ran on a synthesized input
zcao0420/moformer/loss/barlow_twins.py
code served (permissive licence) · get_code("e9f736b6b3acb5d1")
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

def off_diagonal(x):
    n, m = x.shape
    assert n == m
    return x.flatten()[:-1].view(n - 1, n + 1)[:, 1:].flatten()

class BarlowTwinsLoss(nn.Module):

    def __init__(self, device, batch_size, embed_size, lambd):
        super(BarlowTwinsLoss, self).__init__()
        self.device = device
        self.embed_size = embed_size
        self.batch_size = batch_size
        self.lambd = lambd
        self.bn = nn.BatchNorm1d(self.embed_size, affine=False).to(self.device)

    def forward(self, z1, z2):
        c = self.bn(z1).T @ self.bn(z2).to(self.device)
        c.div_(self.batch_size)
        on_diag = torch.diagonal(c).add_(-1).pow_(2).sum().to(self.device)
        off_diag = off_diagonal(c).pow_(2).sum().to(self.device)
        loss = on_diag + self.lambd * off_diag
        return loss.to(self.device)


INIT_ARGS = {
    'device': 'cpu',
    'batch_size': 2,
    'embed_size': 4,
    'lambd': 0.005
}

ARGS = {
    'z1': torch.randn(2, 4),
    'z2': torch.randn(2, 4)
}

if __name__ == '__main__':
    model = BarlowTwinsLoss(**INIT_ARGS)
    output = model(**ARGS)
    print(f"Loss output: {output}")
    print(f"Output shape: {output.shape}")
    print(f"Output is scalar: {output.dim() == 0}")
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)
BarlowTwinsLoss Ran
ran on a synthesized input
lightly-ai/lightly/lightly/loss/barlow_twins_loss.py
code served (permissive licence) · get_code("659ab61af5f11edd")
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
import torch.nn as torch_nn

# Import the class
from torch import Tensor
import torch.nn.functional as F

def _normalize(z: torch.Tensor) -> torch.Tensor:
    """Helper function to create batches of mean 0 and std 1."""
    return F.batch_norm(z, running_mean=None, running_var=None, weight=None, bias=None, training=True)

def _off_diagonal(x: Tensor) -> Tensor:
    """Returns a flattened view of the off-diagonal elements of a square matrix."""
    n, m = x.shape
    assert n == m
    return x.flatten()[:-1].view(n - 1, n + 1)[:, 1:].flatten()

class BarlowTwinsLoss(torch.nn.Module):
    """Implementation of the Barlow Twins Loss from Barlow Twins[0] paper."""

    def __init__(self, lambda_param: float=0.005, gather_distributed: bool=False):
        """Lambda param configuration with default value like in [0]"""
        super(BarlowTwinsLoss, self).__init__()
        self.lambda_param = lambda_param
        self.gather_distributed = gather_distributed

    def forward(self, z_a: torch.Tensor, z_b: torch.Tensor) -> torch.Tensor:
        """Computes the Barlow Twins loss for the given projections."""
        z_a_norm, z_b_norm = (_normalize(z_a), _normalize(z_b))
        N = z_a.size(0)
        c = z_a_norm.T @ z_b_norm
        c.div_(N)
        invariance_loss = torch.diagonal(c).add_(-1).pow_(2).sum()
        redundancy_reduction_loss = _off_diagonal(c).pow_(2).sum()
        loss: Tensor = invariance_loss + self.lambda_param * redundancy_reduction_loss
        return loss


# Configuration for initialization
INIT_ARGS = {
    'lambda_param': 0.005,
    'gather_distributed': False,
}

# Configuration for forward pass
# z_a and z_b should have shape (batch_size, feature_dim)
# Using batch_size=2, feature_dim=4
ARGS = {
    'z_a': torch.randn(2, 4),
    'z_b': torch.randn(2, 4),
}

# Construct and call the class
if __name__ == '__main__':
    loss_fn = BarlowTwinsLoss(**INIT_ARGS)
    loss = loss_fn(**ARGS)
    print(f"Loss: {loss}")
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)
MLP Ran
ran on a synthesized input · constructed an object; no result was computed
FloCF/SSL_pytorch/torchselfsup/models/barlow_twins.py
code served (permissive licence) · get_code("3849a604087cfc40")
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, MLP: 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 torch.nn as nn

torch.manual_seed(0)

ARGS = {
    'in_dim': 4,
    'hidden_dims': (8, 6, 3),
    'bias': True,
    'use_batchnorm': True,
    'batchnorm_last': 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 MLP — 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 MLP 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
NetWrapper Ran
ran on a synthesized input · constructed an object; no result was computed
MaxLikesMath/Barlow-Twins-Pytorch/Twins/barlow.py
code served (permissive licence) · get_code("814473a28a9616d7")
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, NetWrapper: 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 torch.nn as nn

torch.manual_seed(0)

# Build a simple neural network with multiple layers
# The NetWrapper will extract representations from an intermediate layer
class SimpleNet(nn.Module):
    def __init__(self):
        super().__init__()
        self.fc1 = nn.Linear(4, 8)
        self.fc2 = nn.Linear(8, 6)
        self.fc3 = nn.Linear(6, 3)
    
    def forward(self, x):
        x = torch.relu(self.fc1(x))
        x = torch.relu(self.fc2(x))
        x = self.fc3(x)
        return x

# Create the network
net = SimpleNet()

# ARGS dictionary with all parameters for NetWrapper
ARGS = {
    'net': net,
    'layer': -2  # This will select fc2 (the second-to-last child module)
}
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 NetWrapper — 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 NetWrapper 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
ResNetBackbone Ran
ran on a synthesized input
Pangoraw/GeoSSL/geossl/barlowtwins.py
code served (permissive licence) · get_code("d3607edd155cc1dc")
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 2, 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
from torch import nn, Tensor
from torchvision import models

# Mock the load_state_dict_from_url function since we can't do network I/O
def load_state_dict_from_url(url, progress=True):
    raise NotImplementedError("Network I/O not allowed in test environment")

WEIGHTS_RELEASE = 'v0.1'

def _get_weights_url(rn_model: str, dataset: str, method: str) -> str:
    assert rn_model == 'resnet18'
    assert dataset in ['eurosat', 'resisc45'], "Only the 'eurosat' or 'resisc45' dataset is currently supported"
    METHODS = ['simclr', 'moco', 'byol', 'barlow']
    assert method in METHODS, f'Expected one of {METHODS}, got {method!r}'
    return f'https://github.com/Pangoraw/GeoSSL/releases/download/{WEIGHTS_RELEASE}/{rn_model}-{dataset}-{method}.pth'

class ResNetBackbone(nn.Module):
    """
    A ResNet model built on top of torchvision.models resnet implementation.
    """
    out_dim: int

    @staticmethod
    def from_pretrained(path: str, progress: bool=True) -> 'ResNetBackbone':
        """
        Instanciates the model from pretrained weights.

        >>> model = ResNetBackbone.from_pretrained("resnet18/eurosat/moco")

        Parameters
        ==========
            path: str - an identifier string representing the model.
        Returns
        =======
            backbone: ResNetBackbone - the pretrained backbone.
        """
        rn_model, dataset, method = path.split('/')
        model = ResNetBackbone(rn_model, small_conv=dataset == 'eurosat')
        url = _get_weights_url(rn_model, dataset, method)
        state_dict = load_state_dict_from_url(url, progress=progress)
        model.load_state_dict(state_dict)
        return model

    def __init__(self, resnet: str, num_classes: int=10, with_classifier: bool=False, weights_path=None, pretrained: bool=False, small_conv: bool=False):
        super(ResNetBackbone, self).__init__()
        kwargs = {}
        if hasattr(models, 'ResNet18_Weights'):
            kwargs['weights'] = models.ResNet18_Weights.IMAGENET1K_V1 if pretrained else None
        else:
            kwargs['pretrained'] = pretrained
        self.model = models.__dict__[resnet](num_classes=num_classes, **kwargs)
        if weights_path is not None and pretrained:
            raise Exception("Can't use both pretrained and weights_path")
        if weights_path is not None:
            state_dict = torch.load(weights_path, map_location='cpu')
            self.model.load_state_dict(state_dict, strict=False)
        if not with_classifier:
            self.out_dim = self.model.fc.in_features
            self.model.fc = nn.Identity()
        else:
            self.out_dim = num_classes
        if small_conv:
            self.model.conv1 = nn.Conv2d(3, 64, kernel_size=3, stride=1, padding=2, bias=False)
            self.model.maxpool = nn.Identity()

    def forward(self, x: Tensor) -> Tensor:
        return self.model(x)


INIT_ARGS = {
    'resnet': 'resnet18',
    'num_classes': 10,
    'with_classifier': False,
    'weights_path': None,
    'pretrained': False,
    'small_conv': False,
}

ARGS = {
    'x': torch.randn(2, 3, 224, 224),
}

if __name__ == '__main__':
    model = ResNetBackbone(**INIT_ARGS)
    output = model(**ARGS)
    print(f"Output shape: {output.shape}")
    print(f"Model out_dim: {model.out_dim}")
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
torch, torchvision — 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 — 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)
_get_off_diagonal_elements Ran
ran, honoured the contract we drafted
gaborvecsei/Barlow-Twins/barlow_twins/loss.py
pointer only (licence: NONE) · get_code("b91cd63620b31f22")
How it ran

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

_normalize Ran
ran; our contract draft was wrong, not the code
lightly-ai/lightly/lightly/loss/barlow_twins_loss.py
code served (permissive licence) · get_code("693d992853ac438d")
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 2, dtype family float, shape (2, 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.functional as F

torch.manual_seed(0)

# Create a small tensor with batch size 2 and feature dimension 4
z = torch.randn(2, 4)

ARGS = {
    "z": z
}
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 2, dtype family float, shape (2, 4) — shape (2, 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
_off_diagonal Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
lightly-ai/lightly/lightly/loss/barlow_twins_loss.py
code served (permissive licence) · get_code("9b199e6e012c6948")
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 1, dtype family float, shape (12,) 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)

# The function _off_diagonal takes a square matrix tensor and returns
# flattened off-diagonal elements. It requires:
# - x: a square Tensor (n x n shape)

# Create a small square tensor
x = torch.randn(4, 4)

ARGS = {
    "x": x,
}
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 1, dtype family float, shape (12,) — shape (12,) 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)
facebookresearch/barlowtwins/evaluate.py
code served (permissive licence) · get_code("b0f936d4d6ae3b8c")
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 list, ndim 2, 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 output tensor: batch_size=2, num_classes=4
# This represents logits from a model
output = torch.randn(2, 4)

# Create target tensor: batch_size=2
# These are class indices (0-3 for 4 classes)
target = torch.tensor([1, 3])

# topk parameter: tuple of k values to compute accuracy for
topk = (1, 2)

ARGS = {
    "output": output,
    "target": target,
    "topk": topk,
}
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 list, ndim 2, dtype family float — a list 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
bt_loss Ran
ran; our contract draft was wrong, not the code
pbielak/graph-barlow-twins/GCL/losses/barlow_twins.py
code served (permissive licence) · get_code("f2cfbed090a22f9d")
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

torch.manual_seed(0)

# Create small tensors for h1 and h2
# batch_size=2, feature_dim=4
h1 = torch.randn(2, 4)
h2 = torch.randn(2, 4)

# lambda_ parameter
lambda_ = 0.25

# batch_norm parameter
batch_norm = True

# eps parameter
eps = 1e-15

ARGS = {
    "h1": h1,
    "h2": h2,
    "lambda_": lambda_,
    "batch_norm": batch_norm,
    "eps": eps,
}
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
get_backbone Ran
ran on a synthesized input
jeffwiroj/robust_tutorial/bt_exp/barlow_twin/bt.py
pointer only (licence: NONE) · get_code("72c346ee974adb6e")
How it ran

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

loss Ran
ran, violated the contract we drafted
gaborvecsei/Barlow-Twins/barlow_twins/loss.py
pointer only (licence: NONE) · get_code("bba1fbd383276faa")
How it ran

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

normalize Ran
ran, honoured the contract we drafted
gaborvecsei/Barlow-Twins/barlow_twins/loss.py
pointer only (licence: NONE) · get_code("36fab4f0e7dc9d33")
How it ran

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

projector Ran
ran; our contract draft was wrong, not the code
jeffwiroj/robust_tutorial/bt_exp/barlow_twin/bt.py
pointer only (licence: NONE) · get_code("e2109c17551bb49d")
How it ran

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

BARLIP Not yet run
unverified (harvested, no recorded run)
facebookresearch/clip-rocket/models.py
pointer only (licence: NOASSERTION) · get_code("b3dcc88f892bf077")
How it ran

The body of this sample is withheld: GitHub could not classify the licence of this paper's repository, facebookresearch/clip-rocket (NOASSERTION). 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.

BarlowTwins Not yet run
unverified (harvested, no recorded run)
beresandras/contrastive-classification-keras/algorithms.py
code served (permissive licence) · get_code("0001a7e1fc3c2810")
How it ran

no invocation recorded.

BaseMethod Not yet run
unverified (harvested, no recorded run)
Pangoraw/GeoSSL/geossl/barlowtwins.py
code served (permissive licence) · get_code("87987d8832a7303f")
How it ran

no invocation recorded.

barlow_twins_train Not yet run
unverified (harvested, no recorded run)
kalelpark/FG-SSL/learner/pretrain.py
pointer only (licence: NONE) · get_code("f7168ce264a363d3")
How it ran

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

train_val Not yet run
unverified (harvested, no recorded run)
yaohungt/Barlow-Twins-HSIC/linear.py
code served (permissive licence) · get_code("db91eda17a64ade2")
How it ran

no invocation recorded.

Also present in other papers' code

Of 26 samples lifted from this paper's linked repositories, 26 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 (4 with at least one paper dated earlier, 0 the same month, 4 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
accuracy 116 other papers
14 dated earlier, 102 later · 8 only as an assembly brick
1502.03044 (2015-02)
Show, Attend and Tell: Neural Image Caption Generation with Visual Attention
1610.05820 (2016-10)
Membership Inference Attacks Against Machine Learning Models
1905.03696 (2019-05)
HAWQ: Hessian AWare Quantization of Neural Networks with Mixed-Precision
and 113 more not named here
BaseMethod
brick of this paper's assembly: helper
2 other papers
2 dated earlier · 1 only as an assembly brick
1911.05722 (2019-11)
Momentum Contrast for Unsupervised Visual Representation Learning
2002.05709 (2020-02)
A Simple Framework for Contrastive Learning of Visual Representations
MLP
brick of this paper's assembly: helper
2 other papers
1 dated earlier, 1 later · 1 only as an assembly brick
2011.10566 (2020-11)
Exploring Simple Siamese Representation Learning
2105.04906 (2021-05)
VICReg: Variance-Invariance-Covariance Regularization for Self-Supervised Learning
ResNetBackbone
brick of this paper's assembly: helper
2 other papers
2 dated earlier · 1 only as an assembly brick
1911.05722 (2019-11)
Momentum Contrast for Unsupervised Visual Representation Learning
2002.05709 (2020-02)
A Simple Framework for Contrastive Learning of Visual Representations
bt_loss 1 other paper
1 later
2405.01350 (2024-05)
Community-Invariant Graph Contrastive Learning
train_val 1 other paper
1 later
2104.13712 (2021-04)
A Note on Connecting Barlow Twins with Negative-Sample-Free Contrastive Learning

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-21.

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 rapidly closing the gap with supervised methods on large computer vision benchmarks. A successful approach to SSL is to learn embeddings which are invariant to distortions of the input sample. However, a recurring issue with this approach is the existence of trivial constant solutions. Most current methods avoid such solutions by careful implementation details. We propose an objective function that naturally avoids collapse by measuring the cross-correlation matrix between the outputs of two identical networks fed with distorted versions of a sample, and making it as close to the identity matrix as possible. This causes the embedding vectors of distorted versions of a sample to be similar, while minimizing the redundancy between the components of these vectors. The method is called BARLOW TWINS, owing to neuroscientist H. Barlow's redundancy-reduction principle applied to a pair of identical networks. BARLOW TWINS does not require large batches nor asymmetry between the network twins such as a predictor network, gradient stopping, or a moving average on the weight updates. Intriguingly it benefits from very high-dimensional output vectors. BARLOW TWINS outperforms previous methods on ImageNet for semi-supervised classification in the low-data regime, and is on par with current state of the art for ImageNet classification with a linear classifier head, and for transfer tasks of classification and object detection. 1 Figure 1. BARLOW TWINS's objective function measures the crosscorrelation matrix between the embeddings of two identical networks fed with distorted versions of a batch of samples, and tries to make this matrix close to the identity. This causes the embedding vectors of distorted versions of a sample to be similar, while minimizing the redundancy between the components of these vectors. BARLOW TWINS is competitive with state-of-the-art methods for self-supervised learning while being conceptually simpler, naturally avoiding trivial constant (i.e. collapsed) embeddings, and being robust to the training batch size.

For agents

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

get_harvested_code_for_paper("2103.03230")
get_code_for_paper("2103.03230")
have("2103.03230")

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

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

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

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

Connect an agent — have() is free.