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

Language models suffer from "position bias," where they favor information based on its location in a prompt rather than its actual relevance. This paper introduces PINE (Position-INvariant inferencE), a training-free, zero-shot method that eliminates this bias by making inter-document attention bidirectional and re-assigning position embeddings based on document importance.

The Problem: Position Bias in LLMs

Modern Large Language Models (LLMs) are notoriously sensitive to the order of information. If you ask an LLM to compare two responses, it might favor the first one simply because it appeared first (primacy bias). In Retrieval-Augmented Generation (RAG), models often struggle to find the "needle in the haystack" if the relevant document is buried in the middle of a long context—a phenomenon known as being "lost in the middle."

Overview of position bias and its mechanistic roots in causal attention and position encoding.

The authors identify the mechanistic root of this problem: the combination of causal attention (where tokens only look at previous tokens) and position embeddings (which signal a token's absolute or relative index). Together, these operations ensure that a model's internal representation of a document changes depending on where that document is placed, even when the order should be irrelevant to the task.

Introducing PINE: A Mechanistic Solution

The authors propose PINE, a mechanistic approach to force position invariance during inference without any additional training. It consists of two main steps:

  1. Bidirectional Inter-Document Attention: Standard LLMs use a causal mask. PINE modifies the attention mask so that different documents can "see" each other bidirectionally. However, it keeps attention within a document causal to preserve the local linguistic structure.
  2. Importance-Based Position Re-assignment: Instead of using the arbitrary order provided in the input prompt, PINE calculates an "importance score" for each document based on raw attention values (computed without position embeddings). It then re-assigns position indices so that the most "important" documents are assigned positions that the model naturally favors (typically closer to the query).

By combining these, the authors mathematically prove that the model's output becomes invariant to the input order of the documents.

Experimental Setup and Datasets

The researchers evaluated PINE across several diverse benchmarks:

  • RewardBench: A comprehensive benchmark for evaluating reward models, covering Chat, Chat-Hard, Safety, and Reasoning subsets.
  • Retrieval-Augmented QA: Using a setup with 10 or 20 retrieved documents where only one contains the correct answer (the "gold" document).
  • QM9: A dataset of 134k small molecules used here for property-conditioned molecule generation.
  • R-GSM: A modified version of the GSM8K math reasoning dataset where the order of premises is shuffled to test for consistency.

Key Insights and Results

  • Tackling the Root Cause: Unlike previous "ad-hoc" solutions that try to mitigate bias through data augmentation or prompt engineering, this paper tackles the architecture. By identifying that only attention and position embeddings cause this bias, they can eliminate it at the source.
  • Bidirectional > Masked: Previous attempts to solve this (like Parallel Context Windows) often masked out inter-document attention entirely. PINE shows that allowing documents to "talk" to each other bidirectionally preserves vital context that simple masking loses.
  • Reasoning Superpowers: On the RewardBench reasoning set, PINE improved Llama-3-70B-Instruct by 8 to 10 percentage points. This allowed the open-source model to outperform proprietary giants like GPT-4o and GPT-4-Turbo.
  • Solving "Lost in the Middle": In RAG tasks, PINE achieved near-constant performance regardless of whether the "gold" document was at the beginning, middle, or end of the prompt.
  • Cross-Domain Success: The method improved molecule generation accuracy and math reasoning consistency, proving that position bias is a fundamental structural issue across different types of data.

Limitations and Future Work

The primary trade-off for PINE is computational overhead. Because the method requires calculating importance scores and re-running parts of the attention mechanism, the "wall time" (actual elapsed time) for inference is currently 2x to 8x slower than vanilla inference.

The authors note that their current implementation uses unoptimized Python loops. They suggest that future work involving custom CUDA kernels or more efficient attention sorting could significantly reduce this latency. Additionally, they observed that PINE can occasionally cause a slight dip in a model's ability to follow strict output formatting instructions, a side effect that warrants further investigation.

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