[Paper Review] The Impact of Positional Encoding on Length Generalization in Transformers
NoPE (no positional encoding) outperforms explicit positional encodings for length generalization in decoder-only Transformers across reasoning and mathematical tasks, and NoPE can represent absolute and relative positions, often behaving like T5’s Relative PE.
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 embeddings are not essential for decoder-only Transformers to generalize well to longer sequences.
Motivation & Objective
- Investigate how different positional encoding schemes affect length generalization in decoder-only Transformers trained from scratch.
- Compare Absolute Position Embedding (APE), T5’s Relative PE, ALiBi, Rotary, and NoPE across a battery of reasoning and mathematical tasks.
- Assess whether no positional encoding can support or surpass length generalization in downstream tasks.
Proposed method
- Use a conventional decoder-only Transformer of ~107M parameters trained from scratch with autoregressive objective.
- Evaluate five position encoding approaches: APE (sinusoidal), T5’s Relative Bias, ALiBi, Rotary, and NoPE (no PE).
- Assess performance on a suite of synthesis tasks including Primitive (Copy, Reverse) and Mathematical/Reasoning tasks (Addition, Polynomial Eval., Sorting, Summation, Parity, LEGO) and classical datasets (SCAN, PCFG).
- Test length generalization by training on lengths up to L (default L=20) and evaluating on lengths up to 2L, including IISD/extended length scenarios.
- Analyze attention patterns and scratchpad (Chain-of-Thought) formats to understand interaction between PE and length generalization.
- Provide theoretical results showing NoPE can represent absolute and relative PEs, with empirical evidence that SGD trains NoPE to resemble relative encoding like T5’s RPE.

Experimental results
Research questions
- RQ1Does removing explicit positional encoding (NoPE) improve length generalization in decoder-only Transformers across diverse downstream tasks?
- RQ2Among APE, T5 Relative Bias, ALiBi, Rotary, and NoPE, which PE scheme offers the best extrapolation to longer sequences?
- RQ3Can NoPE implicitly represent both absolute and relative positions, and which does it resemble in practice when trained from scratch?
- RQ4How do scratchpad (CoT) formats interact with different PEs in length generalization?
- RQ5What are the attention-pattern differences induced by each PE, and how do they relate to length generalization performance?
Key findings
- NoPE consistently outperforms explicit positional encodings (APE, ALiBi, Rotary, and even T5’s Relative Bias) on length generalization across multiple tasks.
- NoPE achieves similar or better generalization without additional computation in attention, unlike explicit PEs that require extra terms.
- Theoretical results show NoPE can represent both absolute and relative PEs, but SGD-trained NoPE behavior aligns with relative PE attention patterns similar to T5’s RPE.
- Scratchpad improves length generalization only for some tasks (not universally) and depends on its format and the PE used.
- Attention analyses indicate NoPE and T5’s Relative PE encourage attending to both long and short-range positions, while ALiBi biases toward recent tokens, and Rotary resembles APE in behavior.

Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.