SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2207.02970 · ECCV · 2022

Network Binarization via Contrastive Learning

Yan Yan, Dan Xu, Yuzhang Shang, Liqiang Nie, Ziliang Zong

arXiv · PDF · Open in the Atlas

Code that ran

4 of 4 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (4 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 4 have no contract verdict; 0 failures of our instrument; 0 no recorded run), measured 2026-11-24; 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/2207.02970.json · badge: /api/ran/2207.02970.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
42Shawn/CMIM marked official in Papers with Code
Papers with Code archive
4 ran · 0 no recorded run
FunctionStatusWhere it lives
ContrastLoss Ran
ran on a synthesized input · constructed an object; no result was computed
42Shawn/CMIM/CMIM/cifar100/contrastive_alignment/criterion.py
code served (permissive licence) · get_code("f9f0276f9881c6ce")
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, ContrastLoss: 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)

# ContrastLoss expects:
# - n_data: int (total number of data points)
# - eps: float (default 1e-07)
# The forward method expects:
# - x: tensor of shape (bs, N+1) where bs is batch size and N is number of negatives

# Create a small tensor to pass to forward
# Shape: (batch_size=2, N+1=5) where N=4 negatives + 1 positive
x = torch.randn(2, 5)

# n_data should be larger than the batch to make sense for the contrastive loss
n_data = 100

ARGS = {
    'n_data': n_data,
    'eps': 1e-07
}
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 ContrastLoss — 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 ContrastLoss 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
ContrastMemory Ran
ran on a synthesized input · constructed an object; no result was computed
42Shawn/CMIM/CMIM/cifar100/contrastive_alignment/criterion.py
code served (permissive licence) · get_code("a10e610c2b6a4903")
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, ContrastMemory: 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
import math

torch.manual_seed(0)

# Parameters for ContrastMemory.__init__
feat_dim = 4
n_data = 10
nce_n = 2
nce_t = 0.07
nce_mom = 0.999

# Create the module instance
model = nn.Module()

# Now create arguments for the forward pass
batch_size = 2
feat_s = torch.randn(batch_size, feat_dim)
feat_t = torch.randn(batch_size, feat_dim)
idx = torch.tensor([0, 1], dtype=torch.long)
sample_idx = torch.tensor([0, 1, 2, 3, 4, 5], dtype=torch.long)

ARGS = {
    'feat_dim': feat_dim,
    'n_data': n_data,
    'nce_n': nce_n,
    'nce_t': nce_t,
    'nce_mom': nce_mom,
}
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 ContrastMemory — 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 ContrastMemory 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
Embed Ran
ran on a synthesized input · constructed an object; no result was computed
42Shawn/CMIM/CMIM/cifar100/contrastive_alignment/criterion.py
code served (permissive licence) · get_code("6fb273c6076eb82c")
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, Embed: 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,
    'out_dim': 3,
}
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 Embed — 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 Embed 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
contrastive_alignment Ran
ran on a synthesized input · constructed an object; no result was computed
42Shawn/CMIM/CMIM/cifar100/contrastive_alignment/criterion.py
code served (permissive licence) · get_code("3761ae6d7aa4a39a")
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, contrastive_alignment: 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
import math

torch.manual_seed(0)

# Parameters for contrastive_alignment
s_dim = 4  # student feature dimension
t_dim = 5  # teacher feature dimension
feat_dim = 3  # projection space dimension
nce_n = 2  # number of negatives
nce_t = 0.07  # temperature
nce_mom = 0.999  # momentum for memory buffer
n_data = 8  # total number of samples in training set

# Create small dummy tensors for forward pass
batch_size = 2
feat_s = torch.randn(batch_size, s_dim)  # student features
feat_t = torch.randn(batch_size, t_dim)  # teacher features
idx = torch.tensor([0, 1], dtype=torch.long)  # indices for memory update
sample_idx = torch.tensor([0, 1, 2, 3, 4, 5], dtype=torch.long)  # sampled indices (bs * (N+1))

ARGS = {
    's_dim': s_dim,
    't_dim': t_dim,
    'feat_dim': feat_dim,
    'nce_n': nce_n,
    'nce_t': nce_t,
    'nce_mom': nce_mom,
    'n_data': n_data,
}
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 contrastive_alignment — 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 contrastive_alignment 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

Also present in other papers' code

Of 4 samples lifted from this paper's linked repositories, 4 carry a function identity and 0 do not. Of the 4 distinct functions with an identity, 2 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 2 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
ContrastLoss
brick of this paper's assembly: loss
1 other paper
1 later
2404.03263 (2024-04)
On the Surprising Efficacy of Distillation as an Alternative to Pre-Training Small Models
ContrastMemory
brick of this paper's assembly: helper
1 other paper
1 later
2404.03263 (2024-04)
On the Surprising Efficacy of Distillation as an Alternative to Pre-Training Small Models

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

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

Neural network binarization accelerates deep models by quantizing their weights and activations into 1-bit. However, there is still a huge performance gap between Binary Neural Networks (BNNs) and their full-precision (FP) counterparts. As the quantization error caused by weights binarization has been reduced in earlier works, the activations binarization becomes the major obstacle for further improvement of the accuracy. BNN characterises a unique and interesting structure, where the binary and latent FP activations exist in the same forward pass (i.e. Binarize(aF ) = aB). To mitigate the information degradation caused by the binarization operation from FP to binary activations, we establish a contrastive learning framework while training BNNs through the lens of Mutual Information (MI) maximization. MI is introduced as the metric to measure the information shared between binary and the FP activations, which assists binarization with contrastive learning. Specifically, the representation ability of the BNNs is greatly strengthened via pulling the positive pairs with binary and FP activations from the same input samples, as well as pushing negative pairs from different samples (the number of negative pairs can be exponentially large). This benefits the downstream tasks, not only classification but also segmentation and depth estimation, etc. The experimental results show that our method can be implemented as a pile-up module on existing stateof-the-art binarization methods and can remarkably improve the performance over them on CIFAR-10/100 and ImageNet, in addition to the great generalization ability on NYUD-v2. The code is available at https://github.com/42Shawn/CMIM.

For agents

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

get_harvested_code_for_paper("2207.02970")
get_code_for_paper("2207.02970")
have("2207.02970")

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

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

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

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

Connect an agent — have() is free.