Position Encoding Basics
PremiumWhy Transformers need position information, and the methods and limits of absolute position encoding
Get code accessPermutation Invariance in Transformers
Let’s start with a key fact: standard Self-Attention does not care about input order.
Recall the Attention formula:
Here , , . If we shuffle the tokens in , the , , and vectors for each token do not change, only their positions in the sequence do. Attention computes pairwise dot products between all tokens, which is order-invariant.
In other words, “I like cats” and “Cats like me” look the same to Attention. That is clearly unacceptable because language meaning depends on word order.
That is why we need position encoding: inject position information into the input so the model knows where each token is in the sequence.
Log in to continue reading
This is premium content. Please log in to access the full article.