The Impact of Positional Encoding on Length Generalization in Transformers

By Amirhossein Kazemnejad, Inkit Padhi, Karthikeyan Natesan Ramamurthy, Payel Das, Siva Reddy. 2023

396 citations recorded by the source corpus.

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.

Subfields: Artificial Intelligence, Computer Vision and Pattern Recognition, Model Architectures

How researchers see this paper

The researchers whose trusted networks rank it highest, strongest advocate first. Every researcher gets a different order.

In Artificial Intelligence

  1. Gabriel Synnaeve
  2. Jianfeng Gao
  3. Yossi Adi
  4. Quoc V. Le
  5. Ji-rong Wen
  6. Wayne Xin Zhao
  7. Jade Copet
  8. Nicolas Usunier

In Computer Vision and Pattern Recognition

  1. Luc Van Gool
  2. Dacheng Tao
  3. Jiashi Feng
  4. Chunhua Shen
  5. Quoc V. Le
  6. Alan L. Yuille
  7. Xiaogang Wang
  8. Ming-Hsuan Yang

In Model Architectures

  1. Hugo Touvron
  2. Enze Xie
  3. Jian-Yun Nie
  4. Han Cai
  5. Haotian Tang
  6. Ji-rong Wen
  7. Nicolas Usunier
  8. Joanna Bitton

Citations in the corpus