Transformer Language Models without Positional Encodings Still Learn Positional Information

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

Abstract

Causal transformer language models (LMs), such as GPT-3, typically require some form of positional encoding, such as positional embeddings. However, we show that LMs without any explicit positional encoding are still competitive with standard models, and that this phenomenon is robust across different datasets, model sizes, and sequence lengths. Probing experiments reveal that such models acquire an implicit notion of absolute positions throughout the network, effectively compensating for the missing information. We conjecture that causal attention enables the model to infer the number of predecessors that each token can attend to, thereby approximating its absolute position. Our findings indicate that causal LMs might derive positional awareness not only from the explicit positioning mechanism, but also from the effects of the causal mask.

Introduction

The vanilla Transformer architecture is inherently permutation-invariant; without explicit intervention, the model treats the input as a "bag-of-words." To address this, standard practice involves injecting positional information via absolute embeddings (e.g., GPT-3), sinusoidal functions, or relative biases (e.g., ALiBi). This paper investigates whether such explicit injection is strictly necessary for causal language models. Given that causal models use a "causal mask" to restrict attention to preceding tokens, the authors hypothesize that this mask itself breaks symmetry and provides a proxy for positional information.

Methods

The study compares four Transformer variants: NoPos (no explicit positional information), Learned absolute embeddings, Sinusoidal fixed embeddings, and ALiBi relative attention biases. Experiments were conducted on WikiText-103 and a subset of The Pile, with model sizes ranging from 125M to 1.3B parameters. To analyze internal representations, the authors employed probing, training a classifier on frozen hidden states to predict absolute token positions. They also performed word order analysis by shuffling sequence prefixes to measure the model's reliance on learned order.

Key Insights: The Causal Mask as a Counter

The primary finding is that the causal mask acts as a "counter." In a causal model, the $n$-th token attends to exactly $n$ predecessors. The model learns to leverage this structural constraint to approximate its absolute position. Probing results indicate that positional awareness is not present in the initial layer but emerges rapidly. By the middle layers, the NoPos model's internal "map" of positions is nearly as accurate as models with explicit embeddings.

Figure 2: Mean Absolute Distance of position predictions across layers. Positional information in NoPos models emerges rapidly within the first few layers.

Crucially, this phenomenon is unique to causal models. Masked Language Models (MLMs), which lack the directional constraint of a causal mask, fail to learn positional information without explicit encodings.

Results

The NoPos model demonstrates remarkable competitiveness. On a 1.3B parameter model trained on The Pile, NoPos achieved a perplexity of 13.10, closely trailing the Learned (13.05) and ALiBi (12.51) variants.

Figure 1: Perplexity comparison of different positional encoding methods. NoPos remains competitive with standard approaches.

Further analysis showed that as model scale increases, the performance gap between NoPos and position-aware models diminishes. Sensitivity tests confirmed that NoPos models are not merely relying on bag-of-words statistics; shuffling the prefix of a sequence caused a significant jump in loss (from ~4 to ~11), proving the model actively utilizes the learned word order.

Discussion and Limitations

While NoPos models are competitive, the "inductive bias" provided by explicit encodings remains beneficial, particularly for tasks like length extrapolation where methods like ALiBi excel. However, the discovery that Transformers can implicitly learn position suggests that future architectural designs could be simplified by relying more on structural constraints like the causal mask. This research challenges the long-held belief that explicit positional encodings are an absolute requirement for autoregressive Transformers.

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