SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2311.02262 · ICLR · 2024

Tell Your Model Where to Attend: Post-hoc Attention Steering for LLMs

Tuo Zhao, Chandan Singh, Jianfeng Gao, Xiaodong Liu, Qingru Zhang, Liyuan Liu

arXiv · PDF · Open in the Atlas

Code that ran

4 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, 0 violated it and 0 have no contract verdict; 3 failures of our instrument; 1 no recorded run), measured 2026-11-23; 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/2311.02262.json · badge: /api/ran/2311.02262.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
QingruZhang/PASTA canonical (classifier label)
classifier basis: census
4 ran · 1 no recorded run
FunctionStatusWhere it lives
calcluate_attn_metric Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
QingruZhang/PASTA/evaluation/evaluator.py
code served (permissive licence) · get_code("4b4fad5805d70e10")
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, ndim 2, dtype family float; 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

torch.manual_seed(0)

# Create a small attention score tensor
# Shape: (batch_size, num_tokens, num_heads)
# Using distinct dimensions: 2 (batch), 3 (tokens), 4 (heads)
sub_attn_score = torch.randn(2, 3, 4)

# Test with one of the valid metrics
metric = 'token_mean_head_all'

ARGS = {
    'sub_attn_score': sub_attn_score,
    'metric': metric
}
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, ndim 2, dtype family float — a list 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
concatenate_attention_scores Ran
ran; our contract draft was wrong, not the code
QingruZhang/PASTA/evaluation/evaluator.py
code served (permissive licence) · get_code("ddf7e7a257aa45a2")
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, ndim 5, dtype family float; 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

torch.manual_seed(0)

# Analyze the function:
# - output_attentions is a list of length num_new_tokens
# - Each element is a list of length num_layer
# - Each element in that list is a tensor with .size(-1) method
# - The tensor is indexed with [:, :, -1, :] and [:, :, 0, :token_len]
# - Results are unsqueezed at dim 2 and concatenated

# Build a minimal example:
# num_new_tokens = 3 (outer list length)
# num_layer = 2 (inner list length)
# Each tensor should have shape that supports [:, :, -1, :] and [:, :, 0, :]
# This suggests shape (batch, num_heads, seq_len, token_dim)

batch_size = 2
num_heads = 3
seq_len = 5
token_dim = 4

# Create output_attentions: list of lists of tensors
output_attentions = []
for token_id in range(3):  # num_new_tokens = 3
    layer_list = []
    for layer_id in range(2):  # num_layer = 2
        # Shape: (batch, num_heads, seq_len, token_dim)
        tensor = torch.randn(batch_size, num_heads, seq_len, token_dim)
        layer_list.append(tensor)
    output_attentions.append(layer_list)

ARGS = {
    "output_attentions": output_attentions
}
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, ndim 5, dtype family float — a list 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_all_substring_index Ran
ran, honoured the contract we drafted
QingruZhang/PASTA/evaluation/evaluator.py
code served (permissive licence) · get_code("a353d69f2ff9ea8b")
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, 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

# The function takes two string parameters
string = "hello world hello"
substring = "hello"

ARGS = {
    "string": string,
    "substring": substring
}
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, ndim 1, dtype family int — a list 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
read_head_config Ran
ran; our contract draft was wrong, not the code
QingruZhang/PASTA/evaluation/utils/experiment_utils.py
code served (permissive licence) · get_code("91ae75b88a82d08b")
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 json
import tempfile
import os

# Create a temporary JSON file with valid head config
temp_dir = tempfile.mkdtemp()
config_file = os.path.join(temp_dir, 'head_config.json')
config_dict = {
    "num_heads": 8,
    "hidden_size": 768,
    "dropout": 0.1
}
with open(config_file, 'w') as f:
    json.dump(config_dict, f)

# Define ARGS with a valid path to the JSON file
ARGS = {
    'pasta_head_config': config_file
}
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 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
determine_article Not yet run
unverified (harvested, no recorded run)
QingruZhang/PASTA/evaluation/utils/lang_utils.py
code served (permissive licence) · get_code("4d22e52c376c83f6")
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, 2 are also present in other papers whose code we hold (1 with at least one paper dated earlier, 0 the same month, 1 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
determine_article 1 other paper
1 dated earlier
2304.00740 (2023-04)
Inspecting and Editing Knowledge Representations in Language Models
read_head_config 1 other paper
1 later
2603.01281 (2026-03)
Spectral Attention Steering for Prompt Highlighting

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-23.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

In human-written articles, we often leverage the subtleties of text style, such as bold and italics, to guide the attention of readers. These textual emphases are vital for the readers to grasp the conveyed information. When interacting with large language models (LLMs), we have a similar need -steering the model to pay closer attention to user-specified information, e.g., an instruction. Existing methods, however, are constrained to process plain text and do not support such a mechanism. This motivates us to introduce PASTA -Post-hoc Attention STeering Approach, a method that allows LLMs to read text with user-specified emphasis marks. To this end, PASTA identifies a small subset of attention heads and applies precise attention reweighting on them, directing the model attention to user-specified parts. Like prompting, PASTA is applied at inference time and does not require changing any model parameters. Experiments demonstrate that PASTA can substantially enhance an LLM's ability to follow user instructions or integrate new knowledge from user inputs, leading to a significant performance improvement on a variety of tasks, e.g., an average accuracy improvement of 22% for LLAMA-7B. Our code is publicly available at https://github.com/QingruZhang/PASTA. * Work completed during Qingru Zhang's internship at Microsoft Research. 1 We use prompts to refer to all LLM text inputs, including user instructions, and the other background information (which we refer to as context).

For agents

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

get_harvested_code_for_paper("2311.02262")
get_code_for_paper("2311.02262")
have("2311.02262")

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

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

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

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

Connect an agent — have() is free.