RoPE, which appeared in 2021 with RoFormer, has become the main method for representing positions in large modern language models. Its principle differs from that of the vectors learned from GPT-2: position information occurs within the attention mechanism.
RoPE rotates query and key vectors
With RoPE, initial token representations do not receive positional additions. These are the so-called query and key vectors which undergo a rotation, determined by the place of the token in the sequence.
This operation occurs in each layer of attention. Previous methods provided position information when constructing the initial representation of the tokens.
GPT-2 learns its positions, sinusoidal coding calculates them
In GPT-2, each location has its own vector, learned during training according to a principle comparable to that of word representations. This vector is added to that of the token: “fox” thus receives a different addition at positions 3 and 7, and its representation differs for attention. But GPT-2 only has 1,024 learned positional vectors: none corresponds to position 1,025. With this method, the length of the context must therefore be fixed before training.
The evening letterFree · 7 p.m.
Are you passionate about AI research?
The papers and advances that matter, explained simply, every evening. Free.
Included upon registration: our selection of the best AI guides & comparisons.
Choose your pace
Free · No spam · Unsubscribe in 1 click
In 2017, initial work on transformers presented another solution: calculating positional representations with sine and cosine functions. No positional parameter is then to be learned. The different feature pairs follow distinct frequency oscillations.
Attention alone does not identify order
At the center of transformers, attention determines what is relevant for a token by examining other tokens. Its calculation uses scalar products between vectors, without having alone an indication of their order in the sequence.
Positional information provides this missing cue. Whether it is learned, calculated by sinusoidal functions or integrated by rotation, it allows the model to take into account the order of words and better grasp linguistic nuances.

