Information Entropy Invariance: Enhancing Length Extrapolation in Attention Mechanisms

Kewei Li, Yanwen Kong, Yiping Xu, Jianlin Su, Lan Huang +2 more
1/15/2025
5 citations
cs.CL
transformer-attention

Official code: HT-NEKO/Information-Entropy-Invariance (2 stars, Python, last commit 2025-11-25).

Abstract

Since the emergence of research on improving the length extrapolation capabilities of large language models in 2021, some studies have made modifications to the scaling factor in the scaled dot-product attention mechanism as part of their proposed methods without rigorous theoretical justifications. To fill this gap, we propose two new scaled temperatures based on information entropy invariance to enhance length extrapolation.

Show full abstract

First, a training-free method InfoScale is designed for dotproduct attention, and preserves focus on original tokens during length extrapolation by ensuring consistent entropy. Second, we theoretically analyze the impact of scaling (CosScale) on cosine attention. Experimental data demonstrates that combining InfoScale and CosScale achieves state-ofthe-art performance on the GAU-α model with a context window extended to 64 times the training length, and outperforms seven existing methods. Our analysis reveals that significantly increasing CosScale approximates the Windowed Attention, and highlights the significance of attention score dilution as a key challenge in long-range context handling. The code and data are available at https://github.com/HT-NEKO/ Information-Entropy-Invariance.

View on arXivView PDF

Code Implementations(1)

20Python, ShellJan 23, 20251 years ago

Similar Papers

Cite this paper

@article{li2025information,
  title  = {Information Entropy Invariance: Enhancing Length Extrapolation in Attention Mechanisms},
  author = {Kewei Li and Yanwen Kong and Yiping Xu and Jianlin Su and Lan Huang and Ruochi Zhang and Fengfeng Zhou},
  year   = {2025},
  eprint = {2501.08570},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2501.08570v3}
}

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

Discussion