Transformer Language Models without Positional Encodings Still Learn Positional Information

Adi Haviv, Ori Ram, Ofir Press, Peter Izsak, Omer Levy

Introduction

The prevailing architecture for modern natural language processing, the Transformer, is fundamentally permutation-invariant. Because the self-attention mechanism treats input sequences as unordered sets, explicit positional information—such as learned absolute embeddings or relative biases—is typically injected to provide sequence order. This study challenges the necessity of these explicit signals, demonstrating that causal (autoregressive) language models can implicitly learn absolute positions through the structural constraints of their attention masks.

Methodology

The researchers evaluated "NoPos" models—standard Transformer architectures with all positional encoding layers removed. These were compared against three established baselines:

  1. Learned Absolute Embeddings: Unique vectors for each discrete position.
  2. Sinusoidal Embeddings: Fixed mathematical functions representing position.
  3. ALiBi: A method applying distance-based penalties to attention scores.

To verify the presence of positional information within the "NoPos" models, the authors employed linear probing. They froze the pre-trained language models and trained a simple two-layer network to predict a token's absolute position (0–1023) based on its internal hidden representations.

Implicit Position Recovery

The core finding is that the "causal mask"—which restricts tokens to attending only to themselves and their predecessors—acts as a "ruler." By "counting" the number of attendable tokens, the model derives a signal for absolute position.

Probing experiments revealed that NoPos models become position-aware remarkably early in the network. As shown in Figure 2, the mean absolute distance of position predictions drops sharply by the fourth layer. By the middle layers, the NoPos model's internal representations contain positional data comparable in accuracy to models explicitly trained with absolute embeddings.

Figure 2: Mean absolute distance of position predictions across layers. NoPos models (blue) quickly recover positional information after the initial layers.

The accuracy of this implicit learning is further visualized in Figure 3, where the probe's predicted positions for a NoPos model align closely with the ground truth target positions across the entire sequence length.

Figure 3: Predicted vs. target position for the NoPos probe, demonstrating high correlation and successful implicit position recovery.

Experimental Results

The models were benchmarked on WikiText-103 and a 21-billion-token subset of The Pile. At the 1.3B parameter scale, the NoPos model achieved a perplexity of 13.10, closely trailing the Learned Absolute (13.05) and Sinusoidal (12.93) models.

Key observations include:

  • Scaling Benefits: The performance gap between NoPos and position-aware models narrows as parameter counts increase, suggesting larger models are more adept at extracting implicit cues.
  • Information Shedding: Probes indicated that while middle layers are highly position-aware, the final layers "shed" this information to prioritize the next-token prediction task.
  • The Necessity of Causality: Experiments with Masked Language Models (MLMs), which lack a causal mask, failed to converge without explicit positional encodings, confirming that the directional constraint is the primary driver of implicit learning.

Conclusion

This research proves that explicit positional encodings are not a strict requirement for causal Transformers. While providing an inductive bias through explicit encodings remains slightly superior in terms of perplexity, the model's ability to "count" via the causal mask provides a robust alternative. Future work may explore the implications of this finding for long-context modeling and spatial reasoning tasks.

Summary updated

BibTeX
@inproceedings{haviv2022transformer,
  author = {Adi Haviv and Ori Ram and Ofir Press and Peter Izsak and Omer Levy},
  title = {{Transformer Language Models without Positional Encodings Still Learn Positional Information}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2022},
  doi = {10.18653/v1/2022.findings-emnlp.99},
}
Figure