Skip to main content
QUICK REVIEW

[Paper Review] Transformers Can Achieve Length Generalization But Not Robustly

Yongchao Zhou, Uri Alon|arXiv (Cornell University)|Feb 14, 2024
Neural Networks and ApplicationsComputer Science3 citations
TL;DR

This paper demonstrates that Transformers can achieve length generalization up to 2.5× longer sequences than seen during training on a decimal addition task, using a specific combination of FIRE position encoding, reversed data format, and index hints. However, this success is fragile and highly sensitive to random weight initialization and training data order, indicating that robustness remains a critical challenge despite strong extrapolation performance.

ABSTRACT

Length generalization, defined as the ability to extrapolate from shorter training sequences to longer test ones, is a significant challenge for language models. This issue persists even with large-scale Transformers handling relatively straightforward tasks. In this paper, we test the Transformer's ability of length generalization using the task of addition of two integers. We show that the success of length generalization is intricately linked to the data format and the type of position encoding. Using the right combination of data format and position encodings, we show for the first time that standard Transformers can extrapolate to a sequence length that is 2.5x the input length. Nevertheless, unlike in-distribution generalization, length generalization remains fragile, significantly influenced by factors like random weight initialization and training data order, leading to large variances across different random seeds.

Motivation & Objective

  • To investigate whether Transformers can achieve robust length generalization in algorithmic reasoning tasks.
  • To evaluate the impact of position encoding and data format on length generalization performance.
  • To determine whether architectural design alone enables length generalization or if data and training configuration are equally critical.
  • To assess the robustness of length generalization under varying training conditions such as random seed and data order.

Proposed method

  • The study uses a synthetic task of N-digit decimal addition to evaluate length generalization in Transformers.
  • It employs FIRE position encoding with randomized positions to improve sequence modeling beyond training length.
  • The data is formatted in reversed order with index hints to enhance model learning of positional dependencies.
  • Experiments compare various combinations of position encodings and data formats across multiple random seeds and training data orders.
  • Model performance is evaluated on test sequences up to 100 digits, trained only on sequences up to 40 digits.
  • Hyperparameters such as weight decay and dropout are systematically varied to assess their impact on generalization robustness.
Figure 1 : Using an appropriate position encoding and data formatting, we demonstrate that Transformers can generalize to 100-digit decimal addition tasks with more than 98% of accuracy when trained up to 40-digit addition, resulting in a length extension ratio of $2.5\times$ , which is much more th
Figure 1 : Using an appropriate position encoding and data formatting, we demonstrate that Transformers can generalize to 100-digit decimal addition tasks with more than 98% of accuracy when trained up to 40-digit addition, resulting in a length extension ratio of $2.5\times$ , which is much more th

Experimental results

Research questions

  • RQ1Can Transformers generalize to sequence lengths significantly longer than seen during training when using optimal data formatting and position encoding?
  • RQ2How do different position encoding schemes interact with data format to influence length generalization?
  • RQ3To what extent is length generalization robust to variations in random weight initialization and training data order?
  • RQ4Does regularization via weight decay or dropout improve the robustness of length generalization?
  • RQ5Is there a synergistic combination of data format and position encoding that enables strong length generalization where others fail?

Key findings

  • Transformers can achieve 2.5× length generalization in decimal addition, generalizing from 40-digit to 100-digit sequences with over 98% accuracy.
  • The success of length generalization is critically dependent on the combination of FIRE position encoding with randomized positions and reversed data formatting with index hints.
  • Despite strong generalization performance, the model's accuracy varies significantly across random seeds, indicating high sensitivity to weight initialization.
  • Training data order also has a substantial impact, with performance varying widely depending on the sequence in which examples are presented.
  • Regularization techniques like weight decay and dropout do not significantly improve robustness, and high dropout rates (e.g., 0.2) severely degrade generalization.
  • The results show that while length generalization is achievable with proper design, it remains fragile and unreliable under standard training conditions.
Figure 2 : Comparative overview of PEs and data formats: While most related studies focus on APE or NoPE, our approach integrates FIRE (Li et al., 2023 ) and Randomized PE (Ruoss et al., 2023 ) . All studies utilize a reversed format. Shen et al. ( 2023 ) enhance this with random space augmentation,
Figure 2 : Comparative overview of PEs and data formats: While most related studies focus on APE or NoPE, our approach integrates FIRE (Li et al., 2023 ) and Randomized PE (Ruoss et al., 2023 ) . All studies utilize a reversed format. Shen et al. ( 2023 ) enhance this with random space augmentation,

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.