Found in the Middle: How Language Models Use Long Contexts Better via Plug-and-Play Positional Encoding

Zhenyu (Allen) Zhang, Runjin Chen, Shiwei Liu, Zhewei Yao, Olatunji Ruwase +3 more
2/3/2026

No official code found. Best implementation: VITA-Group/Ms-PoE (35 stars, MIT, last commit 2024-05-07).

Abstract

This paper aims to overcome the"lost-in-the-middle"challenge of large language models (LLMs). While recent advancements have successfully enabled LLMs to perform stable language modeling with up to 4 million tokens, the persistent difficulty faced by most LLMs in identifying relevant information situated in the middle of the context has not been adequately tackled. To address this problem, this paper introduces Multi-scale Positional Encoding (Ms-PoE) which is a simple yet effective plug-and-play approach to enhance the capacity of LLMs to handle the relevant information located in the middle of the context, without fine-tuning or introducing any additional overhead. Ms-PoE leverages the position indice rescaling to relieve the long-term decay effect introduced by RoPE, while meticulously assigning distinct scaling ratios to different attention heads to preserve essential knowledge learned during the pre-training step, forming a multi-scale context fusion from short to long distance. Extensive experiments with a wide range of LLMs demonstrate the efficacy of our approach. Notably, Ms-PoE achieves an average accuracy gain of up to 3.8 on the Zero-SCROLLS benchmark over the original LLMs. Code are available at https://github.com/VITA-Group/Ms-PoE.

View on arXivView PDF

Code Implementations(1)

VITA-Group/Ms-PoECommunity100%
MIT

"Found in the Middle: How Language Models Use Long Contexts Better via Plug-and-Play Positional Encoding" Zhenyu Zhang, Runjin Chen, Shiwei Liu, Zhewei Yao, Olatunji Ruwase, Beidi Chen, Xiaoxia Wu, Zhangyang Wang.

354Shell, PythonMar 4, 20242 years agoMIT
large-language-modelslong-contextlost-in-the-middlepositional-encoding

Similar Papers

Cite this paper

@article{zhang2026found,
  title  = {Found in the Middle: How Language Models Use Long Contexts Better via Plug-and-Play Positional Encoding},
  author = {Zhenyu (Allen) Zhang and Runjin Chen and Shiwei Liu and Zhewei Yao and Olatunji Ruwase and Beidi Chen and Xiaoxia Wu and Zhangyang Wang},
  year   = {2026},
  eprint = {2403.04797},
  archivePrefix = {arXiv},
  doi    = {10.48550/arXiv.2403.04797},
  url    = {https://arxiv.org/abs/2403.04797},
  journal = {NEURIPS 2024 2024}
}

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/2403.04797.svg)](https://codeofpaper.com/paper/2403.04797)

Discussion