SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2402.04315 · ACL · 2024

Training Language Models to Generate Text with Citations via Fine-grained Rewards

Yushi Hu, Zeqiu Wu, Wenya Wang, Chengyu Huang

arXiv · PDF · Open in the Atlas

Code that ran

7 of 12 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 0 have no contract verdict; 7 failures of our instrument; 5 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.04315.json · badge: /api/ran/2402.04315.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
hcy123902/atg-w-fg-rw canonical (classifier label)
classifier basis: census
7 ran · 5 no recorded run
FunctionStatusWhere it lives
make_doc_prompt Ran
ran; our contract draft was wrong, not the code
hcy123902/atg-w-fg-rw/evaluation/eval_utils.py
code served (permissive licence) · get_code("c7d29eb322d5d6e3")
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 str. 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)

# Construct valid arguments for make_doc_prompt
doc = {
    'text': 'This is the main body text of the document.',
    'title': 'Sample Document Title',
    'summary': 'This is a shorter summary version.'
}

doc_id = 0

doc_prompt = 'Document {ID}: {T}\n{P}'

use_shorter = None

ARGS = {
    'doc': doc,
    'doc_id': doc_id,
    'doc_prompt': doc_prompt,
    'use_shorter': use_shorter
}
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 str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str 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
normalize_answer Ran
ran; our contract draft was wrong, not the code
hcy123902/atg-w-fg-rw/evaluation/eval_utils.py
pointer only (licence: Apache-2.0); the stored copy get_code serves, from shmsw25/GraphRetriever, is pointer only (licence: NONE) · get_code("dae7ab386661a4f4")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (Apache-2.0), but get_code serves the stored copy, first harvested from shmsw25/GraphRetriever, and GitHub detected no licence in that repository when it was checked. 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.

reduce_mean Ran
ran; our contract draft was wrong, not the code
hcy123902/atg-w-fg-rw/fgrlhf/utils.py
code served (permissive licence) · get_code("e5bacba887a721ef")
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 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

torch.manual_seed(0)

# Create small test tensors
value = torch.randn(2, 4)  # batch_size=2, dim=4
mask = torch.ones(2, 4)    # same shape as value

# Test with axis=None
ARGS = {
    "value": value,
    "mask": mask,
    "axis": None
}
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 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
reduce_std Ran
ran; our contract draft was wrong, not the code
hcy123902/atg-w-fg-rw/fgrlhf/utils.py
code served (permissive licence) · get_code("174bfbbeb1f29e12")
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 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

torch.manual_seed(0)

# Create small test tensors
# value: the tensor to reduce
# mask: binary mask to select which elements to include
value = torch.randn(2, 4)
mask = torch.ones(2, 4)

# Set some mask values to 0 to have meaningful masking
mask[0, 2] = 0
mask[1, 3] = 0

ARGS = {
    "value": value,
    "mask": mask,
}
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 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
reduce_sum Ran
ran; our contract draft was wrong, not the code
hcy123902/atg-w-fg-rw/fgrlhf/utils.py
code served (permissive licence) · get_code("5874b0a8910897fd")
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 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

torch.manual_seed(0)

# Create small tensors for testing
value = torch.randn(2, 4)  # Shape (2, 4)
mask = torch.randint(0, 2, (2, 4)).float()  # Shape (2, 4), binary mask as floats

ARGS = {
    "value": value,
    "mask": mask,
    "axis": None
}
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 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
remove_citations Ran
ran; our contract draft was wrong, not the code
hcy123902/atg-w-fg-rw/evaluation/eval_utils.py
code served (permissive licence) · get_code("5df8b525aada9853")
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 str. 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 re

def remove_citations(sent):
    return re.sub('\\[\\d+', '', re.sub(' \\[\\d+', '', sent)).replace(' |', '').replace(']', '')

ARGS = {
    'sent': 'This is a sample sentence [1 with citations [2 and more [3 text.'
}
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 str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str 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_qampari_text Ran
ran; our contract draft was wrong, not the code
hcy123902/atg-w-fg-rw/fgrlhf/reward_utils.py
code served (permissive licence) · get_code("d36629ddac8ee6aa")
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 re

def split_qampari_text(long_text):
    sents = long_text.split(',')
    if long_text.endswith(','):
        sents = sents[:-1]
    sentence_end_char_idxs = [0]
    refs = [[(0, -1)]]
    current_idx = 0
    for i, sent in enumerate(sents):
        if i == len(sents) - 1 and (not long_text.endswith(',')):
            next_idx = current_idx + len(sent)
        else:
            next_idx = current_idx + len('{},'.format(sent))
        sentence_end_char_idxs.append(next_idx)
        ref = [(current_idx + m.end(), int(m.group()[:-1]) - 1) for m in re.finditer('\\d+\\]', long_text[current_idx:next_idx])]
        refs.append(ref)
        current_idx = next_idx
    sents = [sent.replace('<|im_end|>', '') for sent in sents]
    return (sents, sentence_end_char_idxs, refs)

# Test with a simple text that includes references like "1]", "2]"
long_text = "This is a sentence with reference 1],another sentence with 2]"

ARGS = {
    "long_text": long_text
}
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 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
get_rouge_scores Not yet run
unverified (harvested, no recorded run)
hcy123902/atg-w-fg-rw/fgrlhf/evaluators.py
code served (permissive licence) · get_code("031d4bfddac2dbef")
How it ran

no invocation recorded.

get_single_rouge_score Not yet run
unverified (harvested, no recorded run)
hcy123902/atg-w-fg-rw/fgrlhf/evaluators.py
code served (permissive licence) · get_code("46fb11d38baff4e2")
How it ran

no invocation recorded.

postprocess_text Not yet run
unverified (harvested, no recorded run)
hcy123902/atg-w-fg-rw/fgrlhf/evaluators.py
code served (permissive licence) · get_code("94a55f838c975848")
How it ran

no invocation recorded.

split_text_to_sentences Not yet run
unverified (harvested, no recorded run)
hcy123902/atg-w-fg-rw/fgrlhf/reward_utils.py
code served (permissive licence) · get_code("e7f95d91543ac720")
How it ran

no invocation recorded.

split_text_to_subsentences Not yet run
unverified (harvested, no recorded run)
hcy123902/atg-w-fg-rw/fgrlhf/reward_utils.py
code served (permissive licence) · get_code("11589c4018cfc261")
How it ran

no invocation recorded.

Also present in other papers' code

Of 12 samples lifted from this paper's linked repositories, 12 carry a function identity and 0 do not. Of the 12 distinct functions with an identity, 9 are also present in other papers whose code we hold (6 with at least one paper dated earlier, 2 the same month, 9 later) and 3 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
normalize_answer 133 other papers
59 dated earlier, 8 the same month, 65 later, 1 undated · 1 only as an assembly brick
1508.06615 (2015-08)
Character-Aware Neural Language Models
1606.05250 (2016-06)
SQuAD: 100,000+ Questions for Machine Comprehension of Text
1608.07905 (2016-08)
Machine Comprehension Using Match-LSTM and Answer Pointer
and 130 more not named here
reduce_mean 7 other papers
5 dated earlier, 2 later · 3 only as an assembly brick
2210.03078 (2022-10)
RAINIER: Reinforced Knowledge Introspector for Commonsense Question Answering
2212.10409 (2022-12)
ClarifyDelphi: Reinforced Clarification Questions with Defeasibility Rewards for Social and Moral Situations
2305.13829 (2023-05)
Learning from Mistakes via Cooperative Study Assistant for Large Language Models
and 4 more not named here
reduce_sum 7 other papers
5 dated earlier, 2 later · 3 only as an assembly brick
2210.03078 (2022-10)
RAINIER: Reinforced Knowledge Introspector for Commonsense Question Answering
2212.10409 (2022-12)
ClarifyDelphi: Reinforced Clarification Questions with Defeasibility Rewards for Social and Moral Situations
2305.13829 (2023-05)
Learning from Mistakes via Cooperative Study Assistant for Large Language Models
and 4 more not named here
remove_citations 7 other papers
2 dated earlier, 1 the same month, 4 later
2305.14627 (2023-05)
Enabling Large Language Models to Generate Text with Citations
2311.07838 (2023-11)
LLatrieval: LLM-Verified Retrieval for Verifiable Generation
2402.16617 (2024-02)
Long-Context Language Modeling with Parallel Context Encoding
and 4 more not named here
reduce_std 5 other papers
4 dated earlier, 1 later · 1 only as an assembly brick
2210.03078 (2022-10)
RAINIER: Reinforced Knowledge Introspector for Commonsense Question Answering
2212.10409 (2022-12)
ClarifyDelphi: Reinforced Clarification Questions with Defeasibility Rewards for Social and Moral Situations
2305.13829 (2023-05)
Learning from Mistakes via Cooperative Study Assistant for Large Language Models
and 2 more not named here
make_doc_prompt 3 other papers
2 dated earlier, 1 later
2305.14627 (2023-05)
Enabling Large Language Models to Generate Text with Citations
2311.07838 (2023-11)
LLatrieval: LLM-Verified Retrieval for Verifiable Generation
2025.findings-acl.588 (2025 (year only))
All That Glitters is Not Gold: Improving Robust Retrieval-Augmented Language Models with Fact-Centric Preference Alignment
postprocess_text 2 other papers
2 later
2410.06554 (2024-10)
The Accuracy Paradox in RLHF: When Better Reward Models Don't Yield Better Language Models
2025.findings-emnlp.228 (2025 (year only))
FG-PRM: Fine-grained Hallucination Detection and Mitigation in Language Model Mathematical Reasoning
split_text_to_sentences 2 other papers
2 later
2403.06754 (2024-03)
ALaRM: Align Language Models via Hierarchical Rewards Modeling
2410.06554 (2024-10)
The Accuracy Paradox in RLHF: When Better Reward Models Don't Yield Better Language Models
split_text_to_subsentences 2 other papers
2 later
2403.06754 (2024-03)
ALaRM: Align Language Models via Hierarchical Rewards Modeling
2410.06554 (2024-10)
The Accuracy Paradox in RLHF: When Better Reward Models Don't Yield Better Language Models

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

While recent Large Language Models (LLMs) have proven useful in answering user queries, they are prone to hallucination, and their responses often lack credibility due to missing references to reliable sources. An intuitive solution to these issues would be to include in-text citations referring to external documents as evidence. While previous works have directly prompted LLMs to generate in-text citations, their performances are far from satisfactory, especially when it comes to smaller LLMs. In this work, we propose an effective training framework using fine-grained rewards to teach LLMs to generate highly supportive and relevant citations, while ensuring the correctness of their responses. We also conduct a systematic analysis of applying these fine-grained rewards to common LLM training strategies, demonstrating its advantage over conventional practices. We conduct extensive experiments on Question Answering (QA) datasets taken from the ALCE benchmark and validate the model's generalizability using EXPERTQA. On LLaMA-2-7B, the incorporation of fine-grained rewards achieves the best performance among the baselines, even surpassing that of GPT-3.5-turbo. 1

For agents

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

get_harvested_code_for_paper("2402.04315")
get_code_for_paper("2402.04315")
have("2402.04315")

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

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

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

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

Connect an agent — have() is free.