SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2402.00782 · 2024

Dense Reward for Free in Reinforcement Learning from Human Feedback

arXiv · PDF · Open in the Atlas

Code that ran

3 of 5 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; 1 honoured the contract we drafted, 1 violated it and 0 have no contract verdict; 1 failure of our instrument; 2 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/2402.00782.json · badge: /api/ran/2402.00782.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
xanderjc/attention-based-credit canonical (classifier label)
classifier basis: census
3 ran · 2 no recorded run
FunctionStatusWhere it lives
check_special_tokens Ran
ran, violated the contract we drafted
xanderjc/attention-based-credit/abcrl/helpers/tokenizer_equivalence.py
code served (permissive licence) · get_code("656b5c1bcfee332a")
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 torch
import numpy as np

class MockTokenizer:
    def __init__(self, special_tokens):
        self.all_special_tokens = special_tokens

# Create two tokenizers with special tokens
tokenizer1 = MockTokenizer(['<pad>', '<unk>', '<bos>', '<eos>'])
tokenizer2 = MockTokenizer(['<pad>', '<unk>', '<bos>', '<eos>'])

ARGS = {
    'tokenizer1': tokenizer1,
    'tokenizer2': tokenizer2,
}
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 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
get_attention_distribution Ran
ran; our contract draft was wrong, not the code
xanderjc/attention-based-credit/abcrl/attention/redistribution.py
code served (permissive licence) · get_code("556ee836f3fe3f6c")
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 (5,) 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)

# Construct the arguments
# response: torch.Tensor - a 1D tensor representing the response
response = torch.randn(5, dtype=torch.float32)

# query: torch.Tensor - a 1D tensor representing the query
query = torch.randn(3, dtype=torch.float32)

# attention: torch.Tensor - a 2D attention matrix
# The function expects to extract a submatrix from indices [len(query):len(query)+len(response)]
# So we need a matrix that's at least (len(query) + len(response)) x (len(query) + len(response))
# query length = 3, response length = 5
# So we need at least 8x8 attention matrix
attention = torch.randn(8, 8, dtype=torch.float32)

ARGS = {
    "response": response,
    "query": query,
    "attention": attention,
}
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 (5,) — shape (5,) 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_reward Ran
ran, honoured the contract we drafted
xanderjc/attention-based-credit/abcrl/reward_modelling/starling.py
code served (permissive licence) · get_code("6d632dad98d9d43e")
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 (2,) 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
import math

torch.manual_seed(0)

# Create a minimal reward model that accepts input_ids and attention_mask
class MinimalRewardModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(2048, 1)
    
    def forward(self, input_ids, attention_mask):
        # Return a list of tensors (one per sample in batch)
        batch_size = input_ids.shape[0]
        rewards = []
        for i in range(batch_size):
            reward = self.linear(input_ids[i].float())
            rewards.append(reward)
        return rewards

# Create a minimal tokenizer that has a __call__ method
class MinimalTokenizer:
    def __call__(self, samples, truncation=True, max_length=2048, padding='max_length', return_tensors='pt'):
        batch_size = len(samples)
        # Return a dict with 'input_ids' and 'attention_mask'
        result = {
            'input_ids': torch.randint(0, 1000, (batch_size, max_length)),
            'attention_mask': torch.ones(batch_size, max_length)
        }
        # Add a to() method to the result dict
        class TensorDict(dict):
            def to(self, device):
                return {k: v.to(device) for k, v in self.items()}
        
        return TensorDict(result)

reward_model = MinimalRewardModel()
reward_tokenizer = MinimalTokenizer()
reward_device = 'cpu'
reward_batch_size = 2
samples = ["This is sample one.", "This is sample two."]

ARGS = {
    'samples': samples,
    'reward_model': reward_model,
    'reward_tokenizer': reward_tokenizer,
    'reward_device': reward_device,
    'reward_batch_size': reward_batch_size
}
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 (2,) — shape (2,) 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
build_nectar_dataset Not yet run
unverified (harvested, no recorded run)
xanderjc/attention-based-credit/abcrl/datasets/nectar.py
code served (permissive licence) · get_code("9bd8f37d391d794d")
How it ran

no invocation recorded.

get_generator_attention_distribution Not yet run
unverified (harvested, no recorded run)
xanderjc/attention-based-credit/abcrl/attention/redistribution.py
code served (permissive licence) · get_code("43a9ad195396ee88")
How it ran

no invocation recorded.

Also present in other papers' code

Of 5 samples lifted from this paper's linked repositories, 5 carry a function identity and 0 do not. Of the 5 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 5 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

Reinforcement Learning from Human Feedback (RLHF) has been credited as the key advance that has allowed Large Language Models (LLMs) to effectively follow instructions and produce useful assistance. Classically, this involves generating completions from the LLM in response to a query before using a separate reward model to assign a score to the full completion. As an auto-regressive process, the LLM has to take many "actions" (selecting individual tokens) and only receives a single, sparse reward at the end of an episode, a setup that is known to be difficult to optimise in traditional reinforcement learning. In this work we leverage the fact that the reward model contains more information than just its scalar output, in particular, it calculates an attention map over tokens as part of the transformer architecture. We use these attention weights to redistribute the reward along the whole completion, effectively densifying the signal and highlighting the most important tokens, all without incurring extra computational cost or requiring any additional modelling. We demonstrate that, theoretically, this approach is equivalent to potential-based reward shaping, ensuring that the optimal policy remains unchanged. Empirically, we show that it stabilises training, accelerates the rate of learning, and, in practical cases, may lead to better local optima.

For agents

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

get_harvested_code_for_paper("2402.00782")
get_code_for_paper("2402.00782")
have("2402.00782")

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

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

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

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

Connect an agent — have() is free.