DAPE: Data-Adaptive Positional Encoding for Length Extrapolation

Chuanyang Zheng, Yihang Gao, Han Shi, Minbin Huang, Jingyao Li +6 more
2/3/2026

No official code found. Best implementation: chuanyang-Zheng/DAPE (41 stars, Apache-2.0, last commit 2024-10-11).

Abstract

Positional encoding plays a crucial role in transformers, significantly impacting model performance and length generalization. Prior research has introduced absolute positional encoding (APE) and relative positional encoding (RPE) to distinguish token positions in given sequences. However, both APE and RPE remain fixed after model training regardless of input data, limiting their adaptability and flexibility. Hence, we expect that the desired positional encoding should be data-adaptive and can be dynamically adjusted with the given attention. In this paper, we propose a Data-Adaptive Positional Encoding (DAPE) method, which dynamically and semantically adjusts based on input context and learned fixed priors. Experimental validation on real-world datasets (Arxiv, Books3, and CHE) demonstrates that DAPE enhances model performances in terms of trained length and length generalization, where the improvements are statistically significant. The model visualization suggests that our model can keep both local and anti-local information. Finally, we successfully train the model on sequence length 128 and achieve better performance at evaluation sequence length 8192, compared with other static positional encoding methods, revealing the benefit of the adaptive positional encoding method.

View on arXivView PDF

Code Implementations(1)

Apache-2.0

The this is the official implementation of "DAPE: Data-Adaptive Positional Encoding for Length Extrapolation"

410C, C++May 23, 20242 years agoApache-2.0

Similar Papers

Cite this paper

@article{zheng2026dape,
  title  = {DAPE: Data-Adaptive Positional Encoding for Length Extrapolation},
  author = {Chuanyang Zheng and Yihang Gao and Han Shi and Minbin Huang and Jingyao Li and Jing Xiong and Xiaozhe Ren and Michael K. Ng and Xin Jiang and Zhenguo Li and Yu Li},
  year   = {2026},
  eprint = {2405.14722},
  archivePrefix = {arXiv},
  doi    = {10.52202/079017-0838},
  url    = {https://arxiv.org/abs/2405.14722},
  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/2405.14722.svg)](https://codeofpaper.com/paper/2405.14722)

Discussion