The Impact of Positional Encoding on Length Generalization in Transformers
Amirhossein Kazemnejad, Inkit Padhi, Karthikeyan Natesan Ramamurthy, Payel Das, Siva Reddy
摘要
Length generalization, the ability to generalize from small training context sizes to larger ones, is a critical challenge in the development of Transformer-based language models. Positional encoding (PE) has been identified as a major factor influencing length generalization, but the exact impact of different PE schemes on extrapolation in downstream tasks remains unclear. In this paper, we conduct a systematic empirical study comparing the length generalization performance of decoder-only Transformers with five different position encoding approaches including Absolute Position Embedding (APE), T5's Relative PE, ALiBi, and Rotary, in addition to Transformers without positional encoding (NoPE). Our evaluation encompasses a battery of reasoning and mathematical tasks. Our findings reveal that the most commonly used positional encoding methods, such as ALiBi, Rotary, and APE, are not well suited for length generalization in downstream tasks. More importantly, NoPE outperforms other explicit positional encoding methods while requiring no additional computation. We theoretically demonstrate that NoPE can represent both absolute and relative PEs, but when trained with SGD, it mostly resembles T5's Relative PE attention patterns. Finally, we find that scratchpad is not always helpful to solve length generalization and its format highly impacts the model's performance. Overall, our work suggests that explicit position encodings are not essential for decoder-only Transformers to generalize well to longer sequences.
问 Lune
几分钟读透这篇 Paper,不用再花一下午。
Lune 能读完全文,也能读引用它的顶会 Paper,讲清它的结论、证据和局限,每一点都注明出自哪篇 Paper。不用硬啃,也不靠猜。
已有 132 篇顶会 Paper 引用了它。别等审稿人问起,先弄清它们发现了什么。
脉络
- What Algorithms can Transformers Learn? A Study in Length Generalization 引用了 Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolation
- What Algorithms can Transformers Learn? A Study in Length Generalization 引用了 Language Models are Few-Shot Learners
- What Algorithms can Transformers Learn? A Study in Length Generalization 引用了 Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
- Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolation 引用了 Language Models are Few-Shot Learners
- The Flan Collection: Designing Data and Methods for Effective Instruction Tuning 引用了 Language Models are Few-Shot Learners
- The Flan Collection: Designing Data and Methods for Effective Instruction Tuning 引用了 Training language models to follow instructions with human feedback
- Repeat After Me: Transformers are Better than State Space Models at Copying 引用了 What Algorithms can Transformers Learn? A Study in Length Generalization
- Repeat After Me: Transformers are Better than State Space Models at Copying 引用了 Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolation
- Repeat After Me: Transformers are Better than State Space Models at Copying 引用了 Language Models are Few-Shot Learners
- Chain-of-Thought Prompting Elicits Reasoning in Large Language Models 引用了 Training language models to follow instructions with human feedback
- Training language models to follow instructions with human feedback 引用了 Language Models are Few-Shot Learners
- Cameras as Relative Positional Encoding 引用了 Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolation
- Cameras as Relative Positional Encoding 引用了 YaRN: Efficient Context Window Extension of Large Language Models
- Scan and Snap: Understanding Training Dynamics and Token Composition in 1-layer Transformer 引用了 Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolation
- Scan and Snap: Understanding Training Dynamics and Token Composition in 1-layer Transformer 引用了 Language Models are Few-Shot Learners
引用它的顶会 Paper132
- YaRN: Efficient Context Window Extension of Large Language ModelsBowen Peng, Jeffrey Quesnelle, Honglu Fan, Enrico ShippoleICLR 2024 · 508 次引用
- What Algorithms can Transformers Learn? A Study in Length GeneralizationHattie Zhou, Arwen Bradley, Etai Littwin, Noam Razin 等ICLR 2024 · 189 次引用
- Repeat After Me: Transformers are Better than State Space Models at CopyingSamy Jelassi, David Brandfonbrener, Sham M. Kakade, Eran MalachICML 2024 · 176 次引用
- Scan and Snap: Understanding Training Dynamics and Token Composition in 1-layer TransformerYuandong Tian, Yiping Wang, Beidi Chen, Simon S. DuNeurIPS 2023 · 125 次引用
- Cameras as Relative Positional EncodingRuilong Li, Brent Yi, Junchen Liu, Hang Gao 等NeurIPS 2025 · 113 次引用
它引用的 Paper22
- Language Models are Few-Shot LearnersTom B. Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah 等NeurIPS 2020 · 64,255 次引用
- Training language models to follow instructions with human feedbackLong Ouyang, Jeffrey Wu, Xu Jiang, Diogo Almeida 等NeurIPS 2022 · 24,707 次引用
- Chain-of-Thought Prompting Elicits Reasoning in Large Language ModelsJason Wei, Xuezhi Wang, Dale Schuurmans, Maarten Bosma 等NeurIPS 2022 · 22,562 次引用
- Train Short, Test Long: Attention with Linear Biases Enables Input Length ExtrapolationOfir Press, Noah A. Smith, Mike LewisICLR 2022 · 1,168 次引用
- The Flan Collection: Designing Data and Methods for Effective Instruction TuningShayne Longpre, Le Hou, Tu Vu, Albert Webson 等ICML 2023 · 908 次引用
相关 Paper
- Functional Interpolation for Relative Positions improves Long Context TransformersShanda Li, Chong You, Guru Guruganesh, Joshua Ainslie 等ICLR 2024 · 66 次引用
- Dissecting Transformer Length Extrapolation via the Lens of Receptive Field AnalysisTa-Chung Chi, Ting-Han Fan, Alexander Rudnicky, Peter J. RamadgeACL 2023 · 4 次引用
- DAPE: Data-Adaptive Positional Encoding for Length ExtrapolationChuanyang Zheng, Yihang Gao, Han Shi, Minbin Huang 等NeurIPS 2024 · 42 次引用
- Wavelet-based Positional Representation for Long ContextYui Oka, Taku Hasegawa, Kyosuke Nishida, Kuniko SaitoICLR 2025
- LongEmbed: Extending Embedding Models for Long Context RetrievalDawei Zhu, Liang Wang, Nan Yang, Yifan Song 等EMNLP 2024 · 7 次引用
