Eliminating Position Bias of Language Models: A Mechanistic Approach

Ziqi Wang, Hanlin Zhang, Xiner Li, Kuan-Hao Huang, Chi Han, Shuiwang Ji, Sham M. Kakade, Hao Peng, Heng Ji

TL;DR

Position bias—where language models favor information based on its location rather than its relevance—is a pervasive issue driven by causal attention and position embeddings. This paper introduces PINE (Position-INvariant inferencE), a training-free, zero-shot approach that eliminates document-level position bias by enabling bidirectional attention between documents and dynamically re-assigning token positions based on attention-derived importance scores. PINE delivers significant performance gains across tasks like retrieval-augmented QA and LLM-as-a-judge, even allowing open-source models to outperform GPT-4o on reasoning benchmarks.

What Problem Does This Paper Address?

Modern Large Language Models (LLMs) are highly sensitive to the order of information in their prompts. Whether it's choosing the best response in an LLM-as-a-judge setup or extracting an answer from a pile of retrieved documents (RAG), changing the sequence of the input text can drastically alter the model's output. Larger models often exhibit a primacy bias (favoring the beginning), while smaller models show a recency bias (favoring the end).

The authors take a mechanistic look at why this happens and trace the root cause to two standard components of the Transformer architecture:

  1. Causal Attention: Forces unidirectional information flow, which inadvertently causes the model to pay more attention to distant content.
  2. Rotary Position Embeddings (RoPE): Introduces a long-form attention weight decay, causing the model to prefer nearby content.

When these two forces interact, they create unpredictable biases, such as the famous "lost in the middle" phenomenon where models fail to notice critical information placed in the center of a long prompt.

Methods

Instead of relying on expensive retraining or prompt engineering, the authors propose PINE (Position-INvariant inferencE), a purely inference-time modification:

  • Bidirectional Inter-Document Attention: PINE modifies the attention mask so that different documents can look at each other bidirectionally, ensuring that the attention mechanism treats all documents equally regardless of their input order. Crucially, intra-document attention remains causal to preserve the internal structure and meaning of each document.
  • Importance-Based Position Re-assignment: To completely decouple the model from the prompt's original ordering, PINE calculates an "importance score" between documents using raw attention values (computed without position embeddings). It then dynamically re-assigns token positions so that more important documents are assigned positions closer to the query token.

The authors mathematically prove that this combination yields inter-document position-invariant representations, meaning the final hidden states remain identical no matter how the input documents are shuffled.

Datasets

The authors evaluated PINE across four distinct tasks spanning general and expert domains:

  1. LM-as-a-judge: Evaluated on RewardBench (consisting of Chat, Chat-Hard, Safety, and Reasoning subsets) using LLaMA-3 and Qwen-1.5 models.
  2. Retrieval-Augmented QA: Tested using the "Lost in the Middle" setup from Liu et al. (2024), featuring document stacks of 10 and 20 documents.
  3. Molecule Generation: Evaluated on the QM9 dataset, where models generate molecular structures based on interchangeable chemical properties.
  4. Math Reasoning: Evaluated on R-GSM (a cleaned subset of GSM8K designed to test robustness against shuffled premises).

Key Insights and Ideas

  • The Dual Nature of Bias: The paper visually demonstrates that causal attention and RoPE pull the model in opposite directions. Causal attention favors distant text, while RoPE favors nearby text.
  • Bidirectional beats Masking: Previous methods like Parallel Context Windows (PCW) attempted to solve position bias by completely masking inter-document attention. However, the authors show this destroys contextual information and degrades language generation performance. PINE’s bidirectional approach maintains this crucial context.
  • Zero-Shot Superpowers: By fixing position bias mechanically at inference time, a 70B open-source model can leapfrog closed-source commercial giants on complex reasoning tasks without a single step of extra training.

Key Results

  • RewardBench Breakthroughs: PINE consistently improved performance on the RewardBench reasoning subset by 8 to 10 percentage points. Notably, Llama-3-70B-Instruct + PINE achieved an accuracy of 87.6%, outperforming both GPT-4-0125-preview (86.9%) and GPT-4o-2024-08-06 (86.6%).
  • Flattening the RAG Curve: In retrieval-augmented QA tasks, vanilla models suffer severe performance drops when the target document is placed in the middle. PINE completely flattens this curve, delivering stable, high accuracy regardless of the gold-standard document's position.
PINE eliminates the "lost in the middle" effect in RAG tasks compared to vanilla inference.
  • Domain Generalization: On the R-GSM math reasoning dataset, PINE boosted the accuracy of Qwen1.5-7B by 12.6% and Qwen1.5-110B by 5.3%.

Limitations and Future Work

The primary trade-off with PINE is computational overhead. Because it requires calculating importance scores and sorting documents for every token, it introduces an additional complexity of $O(nk \log k)$ (where $n$ is text length and $k$ is the number of documents). In practice, the unoptimized implementation runs roughly 2x to 8x slower than vanilla inference.

The authors also noted minor instruction-following degradation in specific edge cases (e.g., models occasionally failing to output answers in a strictly requested format). Future work will focus on optimizing the implementation to eliminate the current "for" loops and reduce runtime latency.

Summary updated

BibTeX
@inproceedings{wang2025eliminating,
  author = {Ziqi Wang and Hanlin Zhang and Xiner Li and Kuan-Hao Huang and Chi Han and Shuiwang Ji and Sham M. Kakade and Hao Peng and Heng Ji},
  title = {{Eliminating Position Bias of Language Models: A Mechanistic Approach}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=fvkElsJOsN},
}
Figure