SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2104.01677 · NeurIPS · 2022

A contrastive rule for meta-learning

Johannes Von Oswald, João Sacramento, Nicolas Zucchet, Simon Schug, Dominic Zhao

arXiv · PDF · Open in the Atlas

Code that ran

8 of 8 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; 0 honoured the contract we drafted, 0 violated it and 8 have no contract verdict; 0 failures of our instrument; 0 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/2104.01677.json · badge: /api/ran/2104.01677.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
smonsays/contrastive-meta-learning canonical (classifier label)
classifier basis: census
8 ran · 0 no recorded run
FunctionStatusWhere it lives
activation Ran
ran on a synthesized input
smonsays/contrastive-meta-learning/fewshot/model.py
code served (permissive licence) · get_code("9a8856189ab87282")
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 Sequential. 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
from collections import OrderedDict

torch.manual_seed(0)

ARGS = {
    'stride': 1,
    'max_pool_r': 2
}
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 Sequential — a Sequential output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a Sequential output the recorded ndim 1 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
conv_block Ran
ran on a synthesized input
smonsays/contrastive-meta-learning/fewshot/model.py
code served (permissive licence) · get_code("ed0b510614476bf6")
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 soft_conv_block. 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
from collections import OrderedDict

torch.manual_seed(0)

# Create a minimal bank/template class that satisfies how SConv2d uses it
class MinimalBank(nn.Module):
    def __init__(self, num_templates, out_channels):
        super(MinimalBank, self).__init__()
        self.num_templates = num_templates
        self.out_channels = out_channels
    
    def forward(self, coefficients):
        # coefficients shape: (num_templates, 1, input_channel, 1, 1)
        # Should return parameters of shape (out_channels, input_channel, kernel_h, kernel_w)
        batch_size = coefficients.shape[0]
        input_channel = coefficients.shape[2]
        # Create a dummy kernel by reshaping/expanding coefficients
        # Output shape should be (out_channels, input_channel, 3, 3) for a 3x3 kernel
        kernel = torch.randn(self.out_channels, input_channel, 3, 3)
        return kernel

# Define parameters for conv_block
in_channels = 4
out_channels = 5
num_templates = 8

# Create the bank
hnet_model = MinimalBank(num_templates=num_templates, out_channels=out_channels)

ARGS = {
    'hnet_model': hnet_model,
    'in_channels': in_channels,
    'out_channels': out_channels,
    'kernel_size': 3,
    'stride': 1,
    'padding': 1,
    'bias': True
}
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 soft_conv_block — a soft_conv_block output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a soft_conv_block 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
cross_entropy Ran
ran on a synthesized input
smonsays/contrastive-meta-learning/bandit/energy/loss.py
code served (permissive licence) · get_code("d27c55374c7a7997")
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 jax
import jax.numpy as jnp
import optax
import numpy as np

def reduce(loss, reduction, axis):
    """Helper function to reduce loss based on reduction strategy."""
    if reduction == 'mean':
        return jnp.mean(loss)
    elif reduction == 'sum':
        return jnp.sum(loss)
    elif reduction == 'none':
        return loss
    else:
        return jnp.mean(loss)

# Create small dummy tensors for testing
batch_size = 2
num_classes = 4
output_dim = 4

# output: logits from model, shape (batch_size, num_classes)
output = jnp.array([
    [1.0, 2.0, 0.5, 1.5],
    [0.1, 0.2, 3.0, 0.5]
], dtype=jnp.float32)

# target: class indices, shape (batch_size,)
target = jnp.array([1, 2], dtype=jnp.int32)

# params: dummy model parameters (can be None or empty dict for this example)
params = {}

# hparams: dummy hyperparameters dict
hparams = {'learning_rate': 0.001}

ARGS = {
    'reduction': 'mean',
    'axis': None,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
jax, numpy, optax — 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
linear_block Ran
ran on a synthesized input
smonsays/contrastive-meta-learning/fewshot/model.py
code served (permissive licence) · get_code("23c12ab5afb90600")
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 Sequential. 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
from collections import OrderedDict

torch.manual_seed(0)

ARGS = {
    'in_channels': 4,
    'out_channels': 8,
}
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 Sequential — a Sequential output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a Sequential output the recorded ndim 1 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
load_default_config Ran
ran on a synthesized input
smonsays/contrastive-meta-learning/bandit/ray_metabandit.py
code served (permissive licence) · get_code("4cd2f30024266dd9")
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.

from ray import tune

ARGS = {
    'method': 'cml',
    'meta_model': 'imaml',
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
ray — 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
parse_arguments Ran
ran on a synthesized input
smonsays/contrastive-meta-learning/bandit/ray_metabandit.py
code served (permissive licence) · get_code("2186a88be6035ce8")
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 argparse

ARGS = {
    'args': ['--method', 'cml', '--meta_model', 'imaml']
}
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
squared_error Ran
ran on a synthesized input
smonsays/contrastive-meta-learning/bandit/energy/loss.py
code served (permissive licence) · get_code("9a0da98175e2951e")
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 torch
import torch.nn as nn
import numpy as np

torch.manual_seed(0)

# Helper function to reduce tensors (mimicking what reduce does in the loss function)
def reduce(tensor, reduction='mean', axis=None):
    if axis is not None:
        tensor = tensor.sum(dim=axis)
    
    if reduction == 'mean':
        return tensor.mean()
    elif reduction == 'sum':
        return tensor.sum()
    else:
        return tensor

# Create small dummy tensors for testing
output = torch.randn(2, 4)  # batch size 2, dim 4
target = torch.randn(2, 4)  # batch size 2, dim 4

# Create dummy params and hparams
params = {'weight': torch.randn(4, 3)}
hparams = {'learning_rate': 0.01, 'epochs': 10}

ARGS = {
    'reduction': 'mean',
    'axis': None
}
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 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
squared_error_masked Ran
ran on a synthesized input
smonsays/contrastive-meta-learning/bandit/energy/loss.py
code served (permissive licence) · get_code("bf36baa479d385eb")
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 jax.numpy as jnp
import numpy as np

def reduce(loss_masked, reduction, axis):
    """Helper function to reduce loss based on reduction type"""
    if reduction == 'mean':
        return jnp.mean(loss_masked)
    elif reduction == 'sum':
        return jnp.sum(loss_masked)
    else:
        return loss_masked

# Create test data
batch_size = 2
feature_dim = 4
seq_len = 3

# output: model predictions, shape (batch, seq_len, feature_dim)
output = jnp.ones((batch_size, seq_len, feature_dim))

# target: stacked [reward, mask] along axis -2
# shape (batch, seq_len, 2, feature_dim)
# where target[:, :, 0, :] is reward and target[:, :, 1, :] is mask
reward = jnp.ones((batch_size, seq_len, feature_dim)) * 0.5
mask = jnp.ones((batch_size, seq_len, feature_dim))
target = jnp.stack([reward, mask], axis=-2)

# params: can be any object, not used in function body
params = None

# hparams: can be any object, not used in function body
hparams = None

ARGS = {
    'reduction': 'mean',
    'axis': None,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
jax, numpy — 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

Also present in other papers' code

Of 8 samples lifted from this paper's linked repositories, 8 carry a function identity and 0 do not. Of the 8 distinct functions with an identity, 0 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 0 later) and 8 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.

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

Humans and other animals are capable of improving their learning performance as they solve related tasks from a given problem domain, to the point of being able to learn from extremely limited data. While synaptic plasticity is generically thought to underlie learning in the brain, the precise neural and synaptic mechanisms by which learning processes improve through experience are not well understood. Here, we present a general-purpose, biologically-plausible meta-learning rule which estimates gradients with respect to the parameters of an underlying learning algorithm by simply running it twice. Our rule may be understood as a generalization of contrastive Hebbian learning to meta-learning and notably, it neither requires computing second derivatives nor going backwards in time, two characteristic features of previous gradient-based methods that are hard to conceive in physical neural circuits. We demonstrate the generality of our rule by applying it to two distinct models: a complex synapse with internal states which consolidate task-shared information, and a dual-system architecture in which a primary network is rapidly modulated by another one to learn the specifics of each task. For both models, our meta-learning rule matches or outperforms reference algorithms on a wide range of benchmark problems, while only using information presumed to be locally available at neurons and synapses. We corroborate these findings with a theoretical analysis of the gradient estimation error incurred by our rule. 1

For agents

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

get_harvested_code_for_paper("2104.01677")
get_code_for_paper("2104.01677")
have("2104.01677")

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

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

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

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

Connect an agent — have() is free.