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

Zhenghua Wang, Yiran Ding, Changze Lv, Zhibo Xu, Tianlong Li +3 more
3/6/2025
cs.CL

No confident code implementation found for this paper. 2 possible matches can be shown below.

Abstract

Although large language models (LLMs) have achieved significant progress in handling long-context inputs, they still suffer from the ``lost-in-the-middle'' problem, where crucial information in the middle of the context is often underrepresented or lost. Our extensive experiments reveal that this issue may arise from the rapid long-term decay in Rotary Position Embedding (RoPE). To address this problem, we propose a layer-specific positional encoding scaling method that assigns distinct scaling factors to each layer, slowing down the decay rate caused by RoPE to make the model pay more attention to the middle context. A specially designed genetic algorithm is employed to efficiently select the optimal scaling factors for each layer by incorporating Bezier curves to reduce the search space. Through comprehensive experimentation, we demonstrate that our method significantly alleviates the ``lost-in-the-middle'' problem. Our approach results in an average accuracy improvement of up to 20% on the Key-Value Retrieval dataset. Furthermore, we show that layer-specific interpolation, as opposed to uniform interpolation across all layers, enhances the model's extrapolation capabilities when combined with PI and Dynamic-NTK positional encoding schemes.

View on arXivView PDF

Code Implementations

No confident code match yet

We couldn't find an author-owned or strongly-evidenced community implementation for this paper. 2 weaker matches are hidden by default — verify before relying on them.

No code implementations found yet.

Know of an implementation? Let us know in the comments below!

Similar Papers

Cite this paper

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

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2503.04355.svg)](https://codeofpaper.com/paper/2503.04355)

Discussion