Transformer Architecture: The Positional Encoding(kazemnejad.com)
kazemnejad.com
Transformer Architecture: The Positional Encoding
https://kazemnejad.com/blog/transformer_architecture_positional_encoding/
https://kazemnejad.com/blog/transformer_architecture_positional_encoding/
The idea is that we can just rotate the vector by an amount proportional to its position - this has the property that the dot product of two vectors encoded this way only depends on the difference in positions, not the absolute positions themselves (since the dot product is based on angle between the vectors). And we care about the dot product, since that's what the attention operation ultimately applies to the vectors.
I've written up a _somewhat_ first principles derivation of this here: https://mfaizan.github.io/2023/04/02/sines.html, if interested!