Layer-Specific Scaling of Positional Encodings for Superior Long-Context Modeling

Zhenghua Wang, Yiran Ding, Changze Lv, Zhibo Xu, Tianlong Li, Tianyuan Shi, Xiaoqing Zheng, Xuanjing HuangarXiv 2025 · DOI

TL;DR

This paper tackles the "lost-in-the-middle" problem in LLMs, where crucial information in the middle of long contexts is often ignored. They propose a novel layer-specific scaling of positional encodings (specifically RoPE) to boost attention to middle-context information, achieving significant accuracy improvements.

What Problem Does This Paper Address?

Large Language Models (LLMs) have become incredibly adept at processing vast amounts of text. However, as context lengths increase, a persistent issue emerges: the "lost-in-the-middle" problem. This means that while LLMs can effectively attend to information at the beginning and end of a long input, they tend to overlook or underrepresent crucial details buried in the middle. This significantly degrades performance on various long-context tasks. The authors hypothesize that this issue stems from the inherent long-term decay property of Rotary Position Embeddings (RoPE), a popular method for encoding positional information.

Methods

The core of this paper is a layer-specific positional encoding scaling method. Instead of applying a uniform scaling factor across all layers, they assign distinct scaling factors to each layer. This is done to counteract the rapid decay of RoPE, encouraging the model to pay more attention to the middle of the context.

To efficiently determine these optimal layer-specific scaling factors, they employ a two-pronged approach:

  1. Bézier Curves: They use Bézier curves to model the functional relationship between layer depth and scaling factors. This allows them to represent complex scaling patterns with a small number of control points, significantly reducing the search space.
  2. Genetic Algorithm: A specially designed genetic algorithm is used to optimize the control points of these Bézier curves. This algorithm efficiently searches for the best scaling factors, drastically speeding up the process compared to brute-force methods.

Datasets

The authors evaluated their method on several datasets:

  • MDQA (Multi-Document Question Answering): A dataset for multi-document question answering.
  • Key-Value Retrieval: A dataset designed to assess retrieval capabilities using key-value pairs (UUIDs).
  • ZeroScrolls: A benchmark comprising seven sub-datasets for various long-text tasks like summarization, question answering, and sentiment classification.
  • PG19: Used for evaluating the model's extrapolation capabilities.

Key Insights and Ideas

  • RoPE's Long-Term Decay is a Culprit: The paper provides evidence suggesting that the natural decay of RoPE's positional information over long distances contributes to the "lost-in-the-middle" problem.
  • Layer-Specific Scaling is Crucial: Unlike uniform scaling, applying different scaling factors to different layers is key to effectively mitigating the "lost-in-the-middle" issue without harming performance at the context ends.
  • Earlier Layers Aggregate, Later Layers Filter: The authors hypothesize that earlier layers are more involved in aggregating information, while later layers focus on filtering and refining. This informs their approach to assigning scaling factors.
  • Bézier Curves + Genetic Algorithm = Efficient Optimization: This combination offers a computationally efficient way to find optimal layer-specific scaling factors, making the approach practical.

Key Results

  • Significant Accuracy Improvement: The proposed method achieved an average accuracy improvement of up to 20% on the Key-Value Retrieval dataset and 2.7% on the MDQA dataset.
  • Enhanced Context Utilization: Across multiple long-text tasks from the ZeroScrolls benchmark, their method showed consistent improvements, with Vicuna-7B-v1.5 demonstrating a 10.55% improvement on the Qasper dataset.
  • Superior Extrapolation: When combined with Position Interpolation (PI) and Dynamic-NTK, layer-specific scaling enhanced the model's extrapolation capabilities, leading to lower perplexity on the PG19 dataset.
  • Efficiency: The genetic algorithm with Bézier curves can determine optimal scaling factors in approximately 4-8 hours using modest computational resources, significantly faster than brute-force methods.
  • No Inference Delay: Unlike some prior methods that require real-time calculations, their approach does not introduce any additional latency during inference.

Limitations and Future Work

  • Model Size: Experiments were primarily conducted on models up to 7B parameters due to computational constraints. The authors believe their method's effectiveness would extend to larger models.
  • Hyperparameter Tuning: The genetic algorithm's hyperparameters were not exhaustively tuned, suggesting that further optimization could yield even better results.
  • Generalizability to Other LLMs: While the method is presented as versatile, further testing on LLMs with different architectures or post-training strategies could be beneficial.
  • Future Work: The authors suggest further empirical studies and theoretical analyses to validate their hypotheses about the roles of different layers in information processing and to explore optimal scaling strategies for middle layers during interpolation.

Summary updated

BibTeX
@misc{wang2025layer,
  author = {Zhenghua Wang and Yiran Ding and Changze Lv and Zhibo Xu and Tianlong Li and Tianyuan Shi and Xiaoqing Zheng and Xuanjing Huang},
  title = {{Layer-Specific Scaling of Positional Encodings for Superior Long-Context Modeling}},
  year = {2025},
  eprint = {2503.04355},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2503.04355},
}
Figure