Why do Transformers require explicit positional information while RNNs do not?

Last updated 22 November 2026

An RNN processes tokens one after another, so order is baked into its computation. Self-attention treats its input as an unordered set: permute the tokens and the outputs are permuted in the same way. So Transformers must inject position explicitly.

  • RNNs: order is implicit: The hidden state h_t = f(h_{t-1}, x_t) depends on everything before step t, so swapping two tokens changes the result.

  • Self-attention is permutation-equivariant:

    • Attention scores depend only on content (q_i · k_j), not on where tokens sit. The FFN is applied per token, so it adds no order either.

    • Without positions, "dog bites man" and "man bites dog" would produce the same set of representations.

  • How position is added:

    • Absolute encodings added to the embeddings: sinusoidal (original paper) or learned (BERT, GPT-2).

    • Relative schemes inside attention: RoPE rotates q and k, and ALiBi adds a distance-based bias. These tend to extrapolate better to longer sequences.

  • Nuance: A causal mask breaks the symmetry, so decoder-only models without positional encodings (NoPE) can partly infer position. Bidirectional encoders cannot.

  • https://www.nostrobeai.com/interview-questions/machine-learning
  • https://medium.com/@xiaxiami/understanding-positional-encoding-in-transformer-and-large-language-models-58f1d9a713ed
  • https://medium.com/@mujeeb.merwat/why-positional-emneddings-are-required-in-attention-models-4ccaf91d3f76
All Transformers interview questions