SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2207.11240 · ICML · 2023

Discrete Key-Value Bottleneck

Yoshua Bengio, Bernhard Schölkopf, Michael Mozer, Anirudh Goyal, Frederik Träuble, Kenji Kawaguchi, Nasim Rahaman

arXiv · PDF · Open in the Atlas

Code that ran

8 of 9 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, 2 violated it and 6 have no contract verdict; 0 failures of our instrument; 1 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/2207.11240.json · badge: /api/ran/2207.11240.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
ftraeuble/experiments_discrete_key_value_bottleneck canonical (classifier label)
classifier basis not recorded on the link
6 ran · 1 no recorded run
copy not recorded community
not in the paper's declared repositories
2 ran · 0 no recorded run
FunctionStatusWhere it lives
default Ran
ran, violated the contract we drafted
this paper's copy was not recorded; identical code first harvested from ThomasMrY/VCT
pointer only; the stored copy get_code serves, from ThomasMrY/VCT, is pointer only (licence: NONE) · get_code("60fff7c3c400d7ff")
How it ran

The body of this sample is withheld: this paper's copy of the code was not recorded (its link names no repository or source path), so no licence was read for it. 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.

embedding_dataset_exists Ran
ran on a synthesized input
ftraeuble/experiments_discrete_key_value_bottleneck/kv_bottleneck_experiments/utils/data.py
code served (permissive licence) · get_code("746e0f9d6857f472")
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 bool, 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 os
import tempfile
import torch

# Create a temporary directory structure for testing
temp_dir = tempfile.mkdtemp()
backbone_embeddings_dir = os.path.join(temp_dir, 'backbone_embeddings')
os.makedirs(backbone_embeddings_dir, exist_ok=True)

# Create dummy embedding and label files
torch.manual_seed(0)
dummy_embeddings = torch.randn(2, 4)
dummy_labels = torch.randint(0, 2, (2,))

# Create all required files
backbone = "resnet50"
pretrain_layer = "layer4"
dataset = "cifar10"

embedding_train_file = f'{backbone}_{pretrain_layer}_{dataset}_train_embeddings.pt'
labels_train_file = f'{backbone}_{pretrain_layer}_{dataset}_train_labels.pt'
embedding_test_file = f'{backbone}_{pretrain_layer}_{dataset}_test_embeddings.pt'
labels_test_file = f'{backbone}_{pretrain_layer}_{dataset}_test_labels.pt'

torch.save(dummy_embeddings, os.path.join(backbone_embeddings_dir, embedding_train_file))
torch.save(dummy_labels, os.path.join(backbone_embeddings_dir, labels_train_file))
torch.save(dummy_embeddings, os.path.join(backbone_embeddings_dir, embedding_test_file))
torch.save(dummy_labels, os.path.join(backbone_embeddings_dir, labels_test_file))

# Create args object as a simple class
class Args:
    def __init__(self, root_dir, backbone, pretrain_layer):
        self.root_dir = root_dir
        self.backbone = backbone
        self.pretrain_layer = pretrain_layer

args = Args(root_dir=temp_dir, backbone=backbone, pretrain_layer=pretrain_layer)

ARGS = {
    'dataset': dataset,
    'args': args
}
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 bool, 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
exists Ran
ran, violated the contract we drafted
this paper's copy was not recorded; identical code first harvested from ThomasMrY/VCT
pointer only; the stored copy get_code serves, from ThomasMrY/VCT, is pointer only (licence: NONE) · get_code("aa5486a3650902d8")
How it ran

The body of this sample is withheld: this paper's copy of the code was not recorded (its link names no repository or source path), so no licence was read for it. 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.

get_class_nums Ran
ran on a synthesized input
ftraeuble/experiments_discrete_key_value_bottleneck/kv_bottleneck_experiments/utils/base.py
code served (permissive licence) · get_code("e9304c4dd4be4d62")
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 int, ndim 0, dtype family int, 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

# Create a simple args object that satisfies the function requirements
class Args:
    def __init__(self, dataset_name):
        self.dataset_name = dataset_name

# Test with CIFAR10
ARGS = {'args': Args('CIFAR10')}
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 int, ndim 0, dtype family int, 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_embedding_dataloader Ran
ran on a synthesized input
ftraeuble/experiments_discrete_key_value_bottleneck/kv_bottleneck_experiments/utils/data.py
code served (permissive licence) · get_code("05b24aa01f9569e1")
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 tuple, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. The code mentions cuda, and the harness aliases cuda to the CPU for every sample; whether this run needed that is 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 os
import tempfile
from unittest.mock import Mock

torch.manual_seed(0)

# Create a temporary directory for the embedding files
temp_dir = tempfile.mkdtemp()
backbone_embeddings_dir = os.path.join(temp_dir, 'backbone_embeddings')
os.makedirs(backbone_embeddings_dir, exist_ok=True)

# Create mock embedding and label files for train and test
dataset_name = 'cifar10'
backbone = 'resnet50'
pretrain_layer = 'layer4'

for mode in ['train', 'test']:
    embedding_file = f'{backbone}_{pretrain_layer}_{dataset_name}_{mode}_embeddings.pt'
    labels_file = f'{backbone}_{pretrain_layer}_{dataset_name}_{mode}_labels.pt'
    
    embedding_path = os.path.join(backbone_embeddings_dir, embedding_file)
    labels_path = os.path.join(backbone_embeddings_dir, labels_file)
    
    # Create tiny embeddings (batch_size=2, embedding_dim=4)
    embeddings = torch.randn(2, 4)
    labels = torch.tensor([0, 1])
    
    torch.save(embeddings, embedding_path)
    torch.save(labels, labels_path)

# Create args object with required attributes
args = Mock()
args.root_dir = temp_dir
args.backbone = backbone
args.pretrain_layer = pretrain_layer
args.batch_size = 2

ARGS = {
    'dataset': dataset_name,
    'args': args,
}
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 tuple, ndim 1, dtype family float — a tuple 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
get_encoder_output_shape Ran
ran on a synthesized input
ftraeuble/experiments_discrete_key_value_bottleneck/kv_bottleneck_experiments/utils/model.py
code served (permissive licence) · get_code("de459db4d1d897e2")
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 tuple, ndim 1, dtype family int; 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

class Args:
    def __init__(self, backbone, pretrain_layer, accept_image_fmap):
        self.backbone = backbone
        self.pretrain_layer = pretrain_layer
        self.accept_image_fmap = accept_image_fmap

# Test with dino_resnet50
ARGS = {
    'args': Args(
        backbone='dino_resnet50',
        pretrain_layer=2,
        accept_image_fmap=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 tuple, ndim 1, dtype family int — a tuple 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
get_image_size Ran
ran on a synthesized input
ftraeuble/experiments_discrete_key_value_bottleneck/kv_bottleneck_experiments/utils/base.py
code served (permissive licence) · get_code("1e4efca94cf1e079")
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 int, ndim 0, dtype family int, 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 numpy as np

# The function get_image_size only takes a dataset_name parameter
# and checks if it matches 'CIFAR10' or 'CIFAR100'
# It returns the image size (32) for those datasets

ARGS = {
    'dataset_name': 'CIFAR10'
}
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 int, ndim 0, dtype family int, 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_resnet50_output_shape Ran
ran on a synthesized input
ftraeuble/experiments_discrete_key_value_bottleneck/kv_bottleneck_experiments/utils/model.py
code served (permissive licence) · get_code("e9809af7e92e8792")
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 tuple, ndim 1, dtype family int; 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

class SimpleArgs:
    def __init__(self, accept_image_fmap, pretrain_layer):
        self.accept_image_fmap = accept_image_fmap
        self.pretrain_layer = pretrain_layer

ARGS = {
    "args": SimpleArgs(accept_image_fmap=True, pretrain_layer=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 tuple, ndim 1, dtype family int — a tuple 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
get_split_dataloaders Not yet run
unverified (harvested, no recorded run)
ftraeuble/experiments_discrete_key_value_bottleneck/kv_bottleneck_experiments/utils/data.py
code served (permissive licence) · get_code("c1432af58cb5e45a")
How it ran

no invocation recorded.

Also present in other papers' code

Of 9 samples lifted from this paper's linked repositories, 9 carry a function identity and 0 do not. Of the 9 distinct functions with an identity, 2 are also present in other papers whose code we hold (2 with at least one paper dated earlier, 2 the same month, 2 later) and 7 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
exists 486 other papers
104 dated earlier, 4 the same month, 375 later, 1 same year, order not determinable, 2 undated · 78 only as an assembly brick
1603.08155 (2016-03)
Perceptual Losses for Real-Time Style Transfer and Super-Resolution
1611.07004 (2016-11)
Image-to-Image Translation with Conditional Adversarial Networks
1804.04637 (2018-04)
EMBER: An Open Dataset for Training Static PE Malware Machine Learning Models
and 483 more not named here
default 163 other papers
55 dated earlier, 2 the same month, 105 later, 1 undated · 27 only as an assembly brick
1603.08155 (2016-03)
Perceptual Losses for Real-Time Style Transfer and Super-Resolution
1810.00825 (2018-10)
Set Transformer: A Framework for Attention-based Permutation-Invariant Neural Networks
1907.01470 (2019-07)
Augmenting Self-attention with Persistent Memory
and 160 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

Deep neural networks perform well on classification tasks where data streams are i.i.d. and labeled data is abundant. Challenges emerge with non-stationary training data streams such as continual learning. One powerful approach that has addressed this challenge involves pre-training of large encoders on volumes of readily available data, followed by task-specific tuning. Given a new task, however, updating the weights of these encoders is challenging as a large number of weights needs to be fine-tuned, and as a result, they forget information about the previous tasks. In the present work, we propose a model architecture to address this issue, building upon a discrete bottleneck containing pairs of separate and learnable key-value codes. Our paradigm will be to encode; process the representation via a discrete bottleneck; and decode. Here, the input is fed to the pre-trained encoder, the output of the encoder is used to select the nearest keys, and the corresponding values are fed to the decoder to solve the current task. The model can only fetch and re-use a sparse number of these keyvalue pairs during inference, enabling localized and context-dependent model updates. We theoretically investigate the ability of the discrete key-value bottleneck to minimize the effect of learning under distribution shifts and show that it reduces the complexity of the hypothesis class. We empirically verify the proposed method under challenging class-incremental learning scenarios and show that the proposed model -without any task boundaries -reduces catastrophic forgetting across a wide variety of pre-trained models, outperforming relevant baselines on this task.

For agents

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

get_harvested_code_for_paper("2207.11240")
get_code_for_paper("2207.11240")
have("2207.11240")

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

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

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

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

Connect an agent — have() is free.