Definition

Positional Encoding

Positional encoding gives a sequence model information about where a token occurs. The original Transformer added fixed sine and cosine vectors to token embeddings. Other architectures use learned position embeddings or methods that incorporate relative position into attention calculations.

Follow the same token across two positions

Put “dog” at position 0 in “dog bites man” and at position 2 in “man bites dog.” Assume both occurrences use the same token ID and start with the same token embedding. In the original Transformer, the vector added at position 0 differs from the one added at position 2. For the first sine coordinate, those contributions are sin(0) = 0 and sin(2) ≈ 0.91. The model receives both a token representation and information about its place in the sentence.

Positional encoding in the Transformer paper

Intelligence at Scale by Shashank Agarwal

Positional Encoding diagram from Intelligence at Scale
Diagram from chapter 3, Attention Is All You Need

Explained in

Chapter 3: Attention Is All You Need Free

The paper behind every major AI model today. Google invented it. Then watched someone else ship it.

Related terms

This is one term. The chapter is the argument.

Intelligence at Scale: 22 chapters, 65,000 words, 80-plus diagrams. Kindle, paperback and hardcover on Amazon.

Buy on Amazon.com
← All terms