SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2303.00957 · ICLR · 2023

Preference Transformer: Modeling Human Preferences using Transformers for RL

Honglak Lee, Jinwoo Shin, Pieter Abbeel, Kimin Lee, Kaist, Jongjin Park, Changyeon Kim

arXiv · PDF · Open in the Atlas

Code that ran

7 of 7 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, 1 violated it and 4 have no contract verdict; 2 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/2303.00957.json · badge: /api/ran/2303.00957.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
csmile-1006/preferencetransformer canonical (classifier label)
classifier basis not recorded on the link
7 ran · 0 no recorded run
FunctionStatusWhere it lives
batch_to_jax Ran
ran on a synthesized input
csmile-1006/preferencetransformer/dataset_utils.py
code served (permissive licence) · get_code("79158e16a5bf1c29")
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 jax
import jax.numpy as jnp

# batch_to_jax takes a batch and applies jax.device_put to each leaf
# The input should be a nested structure (dict, list, tuple, etc.) of arrays

# Create a simple batch structure with JAX arrays
batch_data = {
    'features': jnp.array([[1.0, 2.0, 3.0, 4.0],
                           [5.0, 6.0, 7.0, 8.0]]),
    'labels': jnp.array([0, 1]),
    'nested': {
        'auxiliary': jnp.array([[9.0, 10.0, 11.0, 12.0]])
    }
}

ARGS = {
    'batch': batch_data
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
jax — 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
default_init Ran
ran; our contract draft was wrong, not the code
csmile-1006/preferencetransformer/common.py
code served (permissive licence) · get_code("718462716d78ea99")
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 flax.linen as nn

ARGS = {
    "scale": jnp.sqrt(2)
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
flax, jax — 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
evaluate Ran
ran on a synthesized input
csmile-1006/preferencetransformer/evaluation.py
code served (permissive licence) · get_code("46f37a79cc320105")
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 numpy as np
import flax.linen as nn
from typing import Dict
import gym
from gym import spaces


class DummyAgent(nn.Module):
    """Minimal agent that implements sample_actions method."""
    
    @nn.compact
    def __call__(self, observation):
        return observation
    
    def sample_actions(self, observation, temperature=0.0):
        """Return a dummy action based on observation."""
        # Return a scalar action (or small array depending on action space)
        return np.array(0)


class DummyEnv(gym.Env):
    """Minimal gym environment for testing."""
    
    def __init__(self):
        self.observation_space = spaces.Box(low=-1, high=1, shape=(4,), dtype=np.float32)
        self.action_space = spaces.Discrete(2)
        self.step_count = 0
        self.max_steps = 3
    
    def reset(self):
        self.step_count = 0
        return self.observation_space.sample()
    
    def step(self, action):
        self.step_count += 1
        done = self.step_count >= self.max_steps
        observation = self.observation_space.sample()
        reward = 1.0
        info = {
            'episode': {
                'return': 3.0,
                'length': 3,
                'success': 1.0
            }
        }
        return observation, reward, done, info
    
    def render(self, mode='human'):
        pass


# Create dummy agent and environment
agent = DummyAgent()
env = DummyEnv()
num_episodes = 2

ARGS = {
    'agent': agent,
    'env': env,
    'num_episodes': num_episodes
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
flax, gym, numpy, tqdm — 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
loss Ran
ran, violated the contract we drafted
csmile-1006/preferencetransformer/critic.py
code served (permissive licence) · get_code("13df74f8d96dca61")
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 ArrayImpl, ndim 1, dtype family float, shape (6,) 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 jax.numpy as jnp
import numpy as np

# The loss function takes a diff array and an expectile parameter
# diff should be a JAX array (or numpy array that can be converted)
# expectile is a float between 0 and 1

# Create a small diff array
diff = jnp.array([0.5, -0.3, 0.1, -0.2, 0.8, -0.5])

# Set expectile parameter
expectile = 0.8

ARGS = {
    "diff": diff,
    "expectile": expectile,
}
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 ArrayImpl, ndim 1, dtype family float, shape (6,) — shape (6,) 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
merge_trajectories Ran
ran on a synthesized input
csmile-1006/preferencetransformer/dataset_utils.py
code served (permissive licence) · get_code("0c3b9f06d1f100cd")
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. 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

# The function expects trajs: a list of trajectories
# Each trajectory is iterable and yields tuples of:
# (obs, act, rew, mask, done, next_obs)
# All of these should be stackable with np.stack

# Create sample trajectory data
# Each step in a trajectory is (obs, act, rew, mask, done, next_obs)

# Trajectory 1: 3 steps
traj1 = [
    (np.array([1.0, 2.0, 3.0, 4.0]), np.array([0.5, 0.6]), np.array(1.0), np.array(1.0), np.array(0.0), np.array([1.1, 2.1, 3.1, 4.1])),
    (np.array([1.5, 2.5, 3.5, 4.5]), np.array([0.7, 0.8]), np.array(2.0), np.array(1.0), np.array(0.0), np.array([1.6, 2.6, 3.6, 4.6])),
    (np.array([2.0, 3.0, 4.0, 5.0]), np.array([0.9, 1.0]), np.array(3.0), np.array(0.0), np.array(1.0), np.array([2.1, 3.1, 4.1, 5.1])),
]

# Trajectory 2: 2 steps
traj2 = [
    (np.array([5.0, 6.0, 7.0, 8.0]), np.array([1.1, 1.2]), np.array(4.0), np.array(1.0), np.array(0.0), np.array([5.1, 6.1, 7.1, 8.1])),
    (np.array([6.0, 7.0, 8.0, 9.0]), np.array([1.3, 1.4]), np.array(5.0), np.array(1.0), np.array(1.0), np.array([6.1, 7.1, 8.1, 9.1])),
]

trajs = [traj1, traj2]

ARGS = {
    "trajs": trajs
}
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 tuple — a tuple 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
multiple_action_q_function Ran
ran; our contract draft was wrong, not the code
csmile-1006/preferencetransformer/JaxPref/model.py
code served (permissive licence) · get_code("18c566cc009ddb07")
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

torch.manual_seed(0)

def extend_and_repeat(tensor, axis, repeats):
    """Helper function that mimics extend_and_repeat behavior"""
    shape = list(tensor.shape)
    shape.insert(axis, repeats)
    return tensor.unsqueeze(axis).expand(shape)

class SimpleQNetwork(nn.Module):
    """Minimal Q-network that takes observations and actions"""
    def __init__(self, obs_dim=4, action_dim=3):
        super().__init__()
        self.linear = nn.Linear(obs_dim + action_dim, 1)
    
    def forward(self, observations, actions, **kwargs):
        """Compute Q-values from observations and actions"""
        combined = torch.cat([observations, actions], dim=-1)
        q_values = self.linear(combined).squeeze(-1)
        return q_values

# Create decorator function
def multiple_action_q_function(forward):
    def wrapped(self, observations, actions, **kwargs):
        multiple_actions = False
        batch_size = observations.shape[0]
        if actions.ndim == 3 and observations.ndim == 2:
            multiple_actions = True
            observations = extend_and_repeat(observations, 1, actions.shape[1]).reshape(-1, observations.shape[-1])
            actions = actions.reshape(-1, actions.shape[-1])
        q_values = forward(self, observations, actions, **kwargs)
        if multiple_actions:
            q_values = q_values.reshape(batch_size, -1)
        return q_values
    return wrapped

# Create a decorated Q-network
class DecoratedQNetwork(SimpleQNetwork):
    @multiple_action_q_function
    def forward(self, observations, actions, **kwargs):
        combined = torch.cat([observations, actions], dim=-1)
        q_values = self.linear(combined).squeeze(-1)
        return q_values

# Build test arguments
model = DecoratedQNetwork(obs_dim=4, action_dim=3)
observations = torch.randn(2, 4)
actions = torch.randn(2, 5, 3)

ARGS = {
    "forward": model.forward
}
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 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
split_into_trajectories Ran
ran on a synthesized input
csmile-1006/preferencetransformer/dataset_utils.py
code served (permissive licence) · get_code("2101c5b4715a06ea")
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 numpy as np

torch.manual_seed(0)

# Create small tensors for a simple trajectory dataset
# observations: shape (batch_size, obs_dim)
# actions: shape (batch_size, action_dim)
# rewards: shape (batch_size,)
# masks: shape (batch_size,)
# dones_float: shape (batch_size,)
# next_observations: shape (batch_size, obs_dim)

batch_size = 5
obs_dim = 4
action_dim = 3

observations = torch.randn(batch_size, obs_dim)
actions = torch.randn(batch_size, action_dim)
rewards = torch.randn(batch_size)
masks = torch.ones(batch_size)
dones_float = torch.tensor([0.0, 0.0, 1.0, 0.0, 1.0])
next_observations = torch.randn(batch_size, obs_dim)

ARGS = {
    'observations': observations,
    'actions': actions,
    'rewards': rewards,
    'masks': masks,
    'dones_float': dones_float,
    'next_observations': next_observations
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch, tqdm — 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

Also present in other papers' code

Of 7 samples lifted from this paper's linked repositories, 7 carry a function identity and 0 do not. Of the 7 distinct functions with an identity, 5 are also present in other papers whose code we hold (4 with at least one paper dated earlier, 2 the same month, 3 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
default_init 8 other papers
4 dated earlier, 1 the same month, 3 later
1812.05905 (2018-12)
Soft Actor-Critic Algorithms and Applications
2106.03273 (2021-06)
Control-Oriented Model-Based Reinforcement Learning with Implicit Differentiation
2206.01079 (2022-06)
When does return-conditioned supervised learning work for offline reinforcement learning?
and 5 more not named here
multiple_action_q_function 4 other papers
2 dated earlier, 2 later
2006.04779 (2020-06)
Conservative Q-Learning for Offline Reinforcement Learning
2301.12842 (2023-01)
Direct Preference-based Policy Optimization without Reward Modeling
2310.17966 (2023-10)
Train Once, Get a Family: State-Adaptive Balances for Offline-to-Online Reinforcement Learning
and 1 more not named here
loss 3 other papers
2 dated earlier, 1 later · 2 only as an assembly brick
2206.04745 (2022-06)
Mildly Conservative Q-Learning for Offline Reinforcement Learning
2210.04251 (2022-10)
State Advantage Weighting for Offline RL
2310.17966 (2023-10)
Train Once, Get a Family: State-Adaptive Balances for Offline-to-Online Reinforcement Learning
batch_to_jax 1 other paper
1 dated earlier
2301.12842 (2023-01)
Direct Preference-based Policy Optimization without Reward Modeling
merge_trajectories 1 other paper
1 the same month
2303.15810 (2023-03)
Offline RL with No OOD Actions: In-Sample Learning via Implicit Value Regularization

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

Preference-based reinforcement learning (RL) provides a framework to train agents using human preferences between two behaviors. However, preferencebased RL has been challenging to scale since it requires a large amount of human feedback to learn a reward function aligned with human intent. In this paper, we present Preference Transformer, a neural architecture that models human preferences using transformers. Unlike prior approaches assuming human judgment is based on the Markovian rewards which contribute to the decision equally, we introduce a new preference model based on the weighted sum of non-Markovian rewards. We then design the proposed preference model using a transformer architecture that stacks causal and bidirectional self-attention layers. We demonstrate that Preference Transformer can solve a variety of control tasks using real human preferences, while prior approaches fail to work. We also show that Preference Transformer can induce a well-specified reward and attend to critical events in the trajectory by automatically capturing the temporal dependencies in human decision-making. Code is available on the project website: https://sites.google.com/view/preference-transformer.

For agents

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

get_harvested_code_for_paper("2303.00957")
get_code_for_paper("2303.00957")
have("2303.00957")

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

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

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

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

Connect an agent — have() is free.