SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2110.10083 · NeurIPS · 2021

Contrastive Active Inference

Tim Verbelen, Bart Dhoedt, Pietro Mazzaglia

arXiv · PDF · Open in the Atlas

Code that ran

9 of 10 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (2 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 2 have no contract verdict; 7 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/2110.10083.json · badge: /api/ran/2110.10083.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
mazpie/contrastive-aif marked official in Papers with Code
Papers with Code archive
9 ran · 1 no recorded run
FunctionStatusWhere it lives
FreezeParameters Ran
ran on a synthesized input · constructed an object; no result was computed
mazpie/contrastive-aif/agents.py
code served (permissive licence) · get_code("21a1b62a3b1d50d8")
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, FreezeParameters: 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
from typing import Iterable

torch.manual_seed(0)

# Create simple nn.Module instances for testing
class SimpleModule(nn.Module):
    def __init__(self, in_features: int, out_features: int):
        super().__init__()
        self.linear = nn.Linear(in_features, out_features)
    
    def forward(self, x):
        return self.linear(x)

class AnotherModule(nn.Module):
    def __init__(self, in_features: int, out_features: int):
        super().__init__()
        self.conv = nn.Conv1d(in_features, out_features, kernel_size=3)
    
    def forward(self, x):
        return self.conv(x)

# Create module instances with distinct dimensions
module1 = SimpleModule(in_features=4, out_features=3)
module2 = AnotherModule(in_features=3, out_features=2)

# Create an iterable of modules
modules = [module1, module2]

ARGS = {
    "modules": modules
}
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 FreezeParameters — 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 FreezeParameters 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
RunningMeanStd Ran
ran on a synthesized input · constructed an object; no result was computed
mazpie/contrastive-aif/agents.py
code served (permissive licence) · get_code("09d1b0e1811952ff")
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, RunningMeanStd: 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 numpy as np

ARGS = {
    'epsilon': 0.0001,
    'shape': (4,)
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type RunningMeanStd — 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 RunningMeanStd 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
detach_state Ran
ran; our contract draft was wrong, not the code
mazpie/contrastive-aif/agents.py
code served (permissive licence) · get_code("445535640638841c")
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 torch
import torch.nn as nn

torch.manual_seed(0)

# Construct a minimal rssm_state dict with required keys
# The function calls .detach() on each value, so they must be tensors
rssm_state = {
    'mean': torch.randn(2, 4),
    'std': torch.randn(2, 4),
    'stoch': torch.randn(2, 4),
    'deter': torch.randn(2, 4)
}

ARGS = {
    'rssm_state': rssm_state
}
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 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
expand_state Ran
ran; our contract draft was wrong, not the code
mazpie/contrastive-aif/agents.py
code served (permissive licence) · get_code("97920ad76eb461ca")
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 torch

torch.manual_seed(0)

# Create a minimal rssm_state dict with tensors that can be expanded
rssm_state = {
    'mean': torch.randn(1, 4),
    'std': torch.randn(1, 4),
    'stoch': torch.randn(1, 3),
    'deter': torch.randn(1, 5)
}

n = 2

ARGS = {
    'rssm_state': rssm_state,
    'n': n
}
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 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
flatten_state Ran
ran; our contract draft was wrong, not the code
mazpie/contrastive-aif/agents.py
code served (permissive licence) · get_code("7bd437277f3c1ca4")
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 torch

torch.manual_seed(0)

# Create a sample rssm_state dict with properly shaped tensors
# The function reshapes tensors to [-1, last_dimension]
# So we create tensors with batch and sequence dimensions that will be flattened

rssm_state = {
    'mean': torch.randn(2, 3, 4),      # batch=2, seq=3, feature=4
    'std': torch.randn(2, 3, 5),       # batch=2, seq=3, feature=5
    'stoch': torch.randn(2, 3, 6),     # batch=2, seq=3, feature=6
    'deter': torch.randn(2, 3, 7),     # batch=2, seq=3, feature=7
}

ARGS = {
    'rssm_state': rssm_state,
}
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 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
get_dist Ran
ran; our contract draft was wrong, not the code
mazpie/contrastive-aif/agents.py
code served (permissive licence) · get_code("49f065db9df001d7")
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 Independent. 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.distributions as D

torch.manual_seed(0)

# The function expects rssm_state to be a dict with 'mean' and 'std' keys
# These should be tensors that D.Normal can accept
mean = torch.randn(2, 4)
std = torch.abs(torch.randn(2, 4)) + 0.1  # ensure positive std

rssm_state = {
    'mean': mean,
    'std': std
}

ARGS = {
    'rssm_state': rssm_state
}
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 Independent — a Independent output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a Independent 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
get_parameters Ran
ran; our contract draft was wrong, not the code
mazpie/contrastive-aif/agents.py
code served (permissive licence) · get_code("3091e1fe6e877363")
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 list. 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 typing import Iterable

torch.manual_seed(0)

# Create small nn.Module instances
class SimpleLinear(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 3)
    
    def forward(self, x):
        return self.linear(x)

class SimpleConv(nn.Module):
    def __init__(self):
        super().__init__()
        self.conv = nn.Conv1d(2, 3, kernel_size=2)
    
    def forward(self, x):
        return self.conv(x)

# Instantiate modules
module1 = SimpleLinear()
module2 = SimpleConv()

# Create an iterable of modules
modules = [module1, module2]

ARGS = {
    "modules": modules
}
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 list — a list output has no array shape of its own; none is 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
lambda_dreamer_values Ran
ran; our contract draft was wrong, not the code
mazpie/contrastive-aif/agents.py
code served (permissive licence) · get_code("1ad74b47dfca89f6")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 1, dtype family float, shape (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

torch.manual_seed(0)

# Create small tensors for the function
# rewards: tensor of shape (T,) where T is sequence length
# value_preds: tensor of shape (T,) for value predictions
# gamma: float or tensor of shape (T,)
# gae_lamda: float between 0 and 1

sequence_length = 4

rewards = torch.randn(sequence_length)
value_preds = torch.randn(sequence_length)
gamma = 0.99
gae_lamda = 0.95

ARGS = {
    "rewards": rewards,
    "value_preds": value_preds,
    "gamma": gamma,
    "gae_lamda": gae_lamda,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 1, dtype family float, shape (4,) — shape (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
stack_states Ran
ran; our contract draft was wrong, not the code
mazpie/contrastive-aif/agents.py
code served (permissive licence) · get_code("37e6eb67b71c9c45")
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 torch

torch.manual_seed(0)

# Create a list of RSSM states, each state is a dict with 'mean', 'std', 'stoch', 'deter' keys
rssm_states = [
    {
        'mean': torch.randn(2, 4),      # batch_size=2, feature_dim=4
        'std': torch.randn(2, 4),
        'stoch': torch.randn(2, 4),
        'deter': torch.randn(2, 4),
    },
    {
        'mean': torch.randn(2, 4),
        'std': torch.randn(2, 4),
        'stoch': torch.randn(2, 4),
        'deter': torch.randn(2, 4),
    },
]

ARGS = {
    'rssm_states': rssm_states,
    'dim': 0,
}
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 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
Agent Not yet run
unverified (harvested, no recorded run)
mazpie/contrastive-aif/agents.py
code served (permissive licence) · get_code("75ec50fcae15b56d")
How it ran

no invocation recorded.

Also present in other papers' code

Of 10 samples lifted from this paper's linked repositories, 10 carry a function identity and 0 do not. Of the 10 distinct functions with an identity, 1 are also present in other papers whose code we hold (1 with at least one paper dated earlier, 0 the same month, 0 later) and 9 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

FunctionAlso present inEarliest-datedOthers named
get_parameters
brick of this paper's assembly: helper
1 other paper
1 dated earlier
1912.01603 (2019-12)
Dream to Control: Learning Behaviors by Latent Imagination

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

Active inference is a unifying theory for perception and action resting upon the idea that the brain maintains an internal model of the world by minimizing free energy. From a behavioral perspective, active inference agents can be seen as selfevidencing beings that act to fulfill their optimistic predictions, namely preferred outcomes or goals. In contrast, reinforcement learning requires human-designed rewards to accomplish any desired outcome. Although active inference could provide a more natural self-supervised objective for control, its applicability has been limited because of the shortcomings in scaling the approach to complex environments. In this work, we propose a contrastive objective for active inference that strongly reduces the computational burden in learning the agent's generative model and planning future actions. Our method performs notably better than likelihood-based active inference in image-based tasks, while also being computationally cheaper and easier to train. We compare to reinforcement learning agents that have access to human-designed reward functions, showing that our approach closely matches their performance. Finally, we also show that contrastive methods perform significantly better in the case of distractors in the environment and that our method is able to generalize goals to variations in the background.

For agents

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

get_harvested_code_for_paper("2110.10083")
get_code_for_paper("2110.10083")
have("2110.10083")

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

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

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

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

Connect an agent — have() is free.