Papers › Mitigate Position Bias in Large Language Models via Scaling a Single Dimension

Mitigate Position Bias in Large Language Models via Scaling a Single Dimension

4 Jun 2024arXiv:2406.02536archive 2025-07-28

Yijiong Yu, Huiqiang Jiang, Xufang Luo, Qianhui Wu, Chin-Yew Lin, Dongsheng Li, Yuqing Yang, Yongfeng Huang, Lili Qiu

Large Language Models (LLMs) are increasingly applied in various real-world scenarios due to their excellent generalization capabilities and robust generative abilities. However, they exhibit position bias, also known as "lost in the middle", a phenomenon that is especially pronounced in long-context scenarios, which indicates the placement of the key information in different positions of a prompt can significantly affect accuracy. This paper first explores the micro-level manifestations of position bias, concluding that attention weights are a micro-level expression of position bias. It further identifies that, in addition to position embeddings, causal attention mask also contributes to position bias by creating position-specific hidden states. Based on these insights, we propose a method to mitigate position bias by scaling this positional hidden states. Experiments on the NaturalQuestions Multi-document QA, KV retrieval, LongBench and timeline reorder tasks, using various models including RoPE models, context windowextended models, and Alibi models, demonstrate the effectiveness and generalizability of our approach. Our method can improve performance by up to 15.2% by modifying just one dimension of hidden states. Our code is available at https://aka.ms/PositionalHidden.

PaperPDFCodeCode Syntology ran

In Syntology Open this paper in Syntology's Atlas, the map of the papers in Syntology's graph and their citations.

For agents, Syntology's MCP tool lists every function and class Syntology harvested from this paper and whether it ran (how to connect): get_harvested_code_for_paper(arxiv_id="2406.02536")

Code

Syntology Ran 16 of 22 code samples harvested from 1 repository linked to this paper; 6 have no recorded run. Of those that ran: 4 ran · our draft was wrong; 2 ran · fixture could not drive it; 10 ran with no contract checked.

By repository: official repository: 22 samples from 1 repository, 16 ran. The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.

PositionalHidden/PositionalHidden officialmentioned on GitHubpytorchMIT report

Repository list and official/mentioned flags are the archive's, frozen 2025-07-28. Reachability, where shown, is from one Syntology probe window (2026-09-16 to 2026-09-18); repositories not probed show nothing. GitHub stars are not tracked.

Code Syntology ran Syntology

22 samples harvested; 16 ran; 0 honoured the contract we drafted; 6 have no recorded run. Read from Syntology's graph 2026-09-24; that is when this build read the record, not when the samples ran.

4ran · our draft was wrong
2ran · fixture could not drive it
10ran
6unverified

Licence: 0 of the 22 samples are pointer only, meaning Syntology does not serve that copy's text. This page shows no code text for any sample; each one links to its file in the repository.

Harvested from PositionalHidden/PositionalHidden. “Ran” means the sample executed on a synthesized input. It does not mean the output is correct, and nothing here reproduces the paper's results. “Honoured” and “violated” refer to a contract Syntology drafted from the code itself; “our draft was wrong” and “fixture could not drive it” are failures of Syntology's instrument, not of the code.

Each sample ends with its code_sha256, Syntology's identity for that exact code. An agent fetches the stored sample with Syntology's MCP tool get_code(code_sha256="…") (how to connect); click an identity to copy that call.

Repository labels, per sample. official repository: The archive marks this repository official for the paper. named in the paper: The archive records that the paper mentions this repository; it is not marked official. community (archive-listed): In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper. found in paper text by Syntology: Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted. community: Not in the archive's code links for this paper; a community repository Syntology harvested. Samples from a repository marked official are listed first. Licence labels name the repository's licence as recorded at harvest. “Pointer only” means Syntology does not serve that copy's text, for one of four reasons: no licence file was found; the licence was not identified; the licence is recorded as permissive but that copy's record is not marked cleared; or the licence is outside the permissive list Syntology serves text under (MIT, Apache-2.0, BSD and similar). Some licences outside that list permit redistribution, such as WTFPL, and GPL-3.0 under its conditions; they are simply not on the list. Hover a licence label for the reason. File links open the file on GitHub at the default branch, which may have changed since the harvest.

repeat_kv PositionalHidden/PositionalHidden/positional_hidden/models/modeling_gemma_hidden_scale.py official repository ran · fixture could not drive it fingerprinted MIT (permissive) · 30d7eec482ebf6b1 · report
apply_rotary_pos_emb PositionalHidden/PositionalHidden/positional_hidden/models/modeling_llama_hidden_scale.py official repository ran · fixture could not drive it MIT (permissive) · d61c483a3c2b3156 · report
apply_rotary_pos_emb PositionalHidden/PositionalHidden/positional_hidden/models/modeling_gemma_hidden_scale.py official repository ran · our draft was wrong MIT (permissive) · bac65c3dafaec040 · report
apply_rotary_pos_emb_gemma PositionalHidden/PositionalHidden/positional_hidden/models/modeling_llama_hidden_scale.py official repository ran MIT (permissive) · 061f05dab3ffd652 · report
best_subspan_em PositionalHidden/PositionalHidden/experiments/lost_in_the_middle/metrics.py official repository ran MIT (permissive) · 10af7cdbc53df7e5 · report
build_mpt_alibi_tensor PositionalHidden/PositionalHidden/positional_hidden/models/modeling_mpt_hidden_scale.py official repository ran MIT (permissive) · 6acdafe16c0d4786 · report
count_score PositionalHidden/PositionalHidden/experiments/run_on_longbench/metrics.py official repository ran fingerprinted MIT (permissive) · 1051445c95f4d2fc · report
eval_dims PositionalHidden/PositionalHidden/experiments/search_dimension/eval_on_valid_set.py official repository ran MIT (permissive) · 76822e2ad71afee9 · report
format_chat_prompt PositionalHidden/PositionalHidden/experiments/KV/run_hidden_scale_KV.py official repository ran MIT (permissive) · b9ac8a016e78383a · report
format_chat_prompt PositionalHidden/PositionalHidden/experiments/run_on_longbench/run_on_longbench.py official repository ran MIT (permissive) · 6c56afd9bf4ea601 · report
format_chat_prompt PositionalHidden/PositionalHidden/experiments/search_dimension/eval_on_valid_set.py official repository ran MIT (permissive) · e52c1a2fa822f109 · report
get_model_class PositionalHidden/PositionalHidden/positional_hidden/use_model.py official repository ran MIT (permissive) · 2b1ae840dfdd7e16 · report
normalize_answer PositionalHidden/PositionalHidden/experiments/run_on_longbench/metrics.py official repository ran · our draft was wrong fingerprinted MIT (permissive) · e7e75981cb464788 · report
normalize_zh_answer PositionalHidden/PositionalHidden/experiments/run_on_longbench/metrics.py official repository ran · our draft was wrong fingerprinted MIT (permissive) · 8c5c581f9264c810 · report
prompt_func PositionalHidden/PositionalHidden/experiments/run_on_longbench/run_on_longbench.py official repository ran MIT (permissive) · e60745782705e531 · report
rotate_half PositionalHidden/PositionalHidden/positional_hidden/models/modeling_gemma_hidden_scale.py official repository ran · our draft was wrong fingerprinted MIT (permissive) · b99eea6376d1e212 · report
get_closedbook_qa_prompt PositionalHidden/PositionalHidden/experiments/lost_in_the_middle/prompting.py official repository unverified MIT (permissive) · 91506e645c7a9e50 · report
get_hidden_states PositionalHidden/PositionalHidden/experiments/search_dimension/get_avg_hidden_state.py official repository unverified MIT (permissive) · 6325cba09a03eb90 · report
get_kv_retrieval_prompt PositionalHidden/PositionalHidden/experiments/lost_in_the_middle/prompting.py official repository unverified MIT (permissive) · aca69348624f921b · report
get_model_class PositionalHidden/PositionalHidden/experiments/KV/run_hidden_scale_KV.py official repository unverified MIT (permissive) · 3fbc0e8f6cb70422 · report
get_qa_prompt PositionalHidden/PositionalHidden/experiments/lost_in_the_middle/prompting.py official repository unverified MIT (permissive) · 286b6ac3dc4a717d · report
normalize_answer PositionalHidden/PositionalHidden/experiments/lost_in_the_middle/metrics.py official repository unverified MIT (permissive) · 9706a9a0b961096b · report

Results from the paper archive 2025-07-28

No leaderboard rows for this paper in the archive.

Methods

ALiBiRotary Embeddings

Report a problem or propose a change · a person checks every report against the paper or source before anything changes; decisions are listed on /corrections