The EOS Decision and Length Extrapolation

Benjamin Newman, John Hewitt, Percy Liang, Christopher D. Manning · DOI

Abstract

Extrapolation to unseen sequence lengths is a challenge for neural generative models of language. In this work, we characterize the effect on length extrapolation of a modeling decision often overlooked: predicting the end of the generative process through the use of a special end-of-sequence (EOS) vocabulary item. We study an oracle setting - forcing models to generate to the correct sequence length at test time - to compare the length-extrapolative behavior of networks trained to predict EOS (+EOS) with networks not trained to (-EOS). We find that -EOS substantially outperforms +EOS, for example extrapolating well to lengths 10 times longer than those seen at training time in a bracket closing task, as well as achieving a 40% improvement over +EOS in the difficult SCAN dataset length generalization task. By comparing the hidden states and dynamics of -EOS and +EOS models, we observe that +EOS models fail to generalize because they (1) unnecessarily stratify their hidden states by their linear position is a sequence (structures we call length manifolds) or (2) get stuck in clusters (which we refer to as length attractors) once the EOS token is the highest-probability prediction.

Introduction

Length extrapolation—the ability of a model to generalize to sequences significantly longer than those encountered during training—remains a persistent challenge in natural language processing. While architectural limitations like memory constraints or positional encoding schemes are frequently cited as the cause, this research investigates a different culprit: the End-of-Sequence (EOS) decision. Standard training requires models to simultaneously learn content generation and the decision of when to stop. We hypothesize that the pressure to predict the end of a sequence forces models to track linear position so strictly that they lose the ability to generalize underlying logic to longer sequences.

Methods: The Length Oracle

To isolate the impact of the EOS decision, we compare two training regimes:

  1. +EOS: Standard training where the model predicts an <EOS> token to terminate sequences.
  2. -EOS: Training without any EOS tokens.

Because -EOS models never learn to stop, we employ a Length Oracle Evaluation. At test time, both models are "forced" to generate until they reach the correct ground-truth length. This allows us to evaluate the model's capacity for content generation independently of its stopping mechanism.

The Length Oracle evaluation process: sequences are generated without EOS and truncated to the ground-truth length for comparison.

Experimental Setup

We evaluated these models across three benchmarks of increasing complexity:

  • Dyck-(k,m): A formal language task requiring the model to balance nested parentheses, testing its ability to maintain a stack-like memory.
  • SCAN: A synthetic benchmark for compositional generalization, specifically using the "length split" to test extrapolation from short commands to long action sequences.
  • WMT2009 (German-English): A real-world machine translation task to assess the findings in natural language contexts.

Key Insights: Manifolds and Attractors

Using Principal Component Analysis (PCA) to visualize hidden states, we identified two primary failure modes in +EOS models:

  1. Length Manifolds: In +EOS models, hidden states become stratified by their linear position. The model effectively builds a map where "Position 5" is distinct from "Position 10." When asked to generate at "Position 50" (unseen in training), the model falls off its internal map, leading to logical breakdown.
  2. Length Attractors: Once a +EOS model determines a sequence should have ended, its hidden state is pulled into an "attractor"—a state from which it cannot escape. Even when forced to continue by the Length Oracle, the model remains stuck, often repeating tokens or producing nonsense.
PCA visualizations of hidden states in Dyck-2,4. The +EOS model (left) shows linear stratification by position, while the -EOS model (right) avoids this 'length manifold' structure.

In contrast, -EOS models do not face the "counting burden." Without the pressure to predict an end, their hidden states move freely through the content space, untethered to absolute linear positions.

Key Results

  • 10x Extrapolation: On the Dyck task, -EOS models maintained high accuracy on sequences 10 times longer than their training data, whereas +EOS models failed almost immediately.
  • SCAN Superiority: In the SCAN length-generalization task, -EOS models achieved a 40% improvement over +EOS models in the oracle setting.
  • Architecture Agnostic: Even Transformers using sinusoidal positional encodings failed to extrapolate when trained with EOS, suggesting the bottleneck is the objective itself rather than the architecture.
  • Natural Language Nuance: In WMT translation, the benefit of -EOS was less pronounced. This likely occurs because natural language contains "soft" length markers (e.g., periods, closing quotes) that act as proxies for the EOS decision.

Conclusion and Future Work

This work demonstrates that the requirement to predict sequence termination fundamentally limits a model's ability to extrapolate. While -EOS models are not directly deployable as they lack a stopping mechanism, they serve as a critical diagnostic tool. Future research should focus on "middle ground" solutions, such as implicit checklist models or training techniques that decouple content generation from absolute positional tracking.

Summary updated

BibTeX
@inproceedings{newman2020eos,
  author = {Benjamin Newman and John Hewitt and Percy Liang and Christopher D. Manning},
  title = {{The EOS Decision and Length Extrapolation}},
  booktitle = {BlackboxNLP @ EMNLP},
  year = {2020},
  doi = {10.18653/v1/2020.blackboxnlp-1.26},
}
Figure