# Positional Encoding

- **Canonical URL:** https://getaimath.com/dictionary/positional-encoding/
- **Topics:** [Transformer Architecture](https://getaimath.com/dictionary/category/transformer-architecture/)
- **Also called:** Positional Embedding
- **Last updated:** 2026-11-25

## What is Positional Encoding?

**In one sentence:** Positional encoding adds information about word order, so the model knows which word came first, second, and so on.

Attention by itself treats a sentence like a bag of words with no order. But "dog bites man" and "man bites dog" mean very different things. Positional encoding adds a position signal to each token so order is not lost.

![Transformers & Attention: The Smart Highlighter — Simple cartoon diagram showing how a Transformer reads a whole sentence at once and shines a bright highlighter beam from the word "IT" back to "trophy" so it knows what "IT" means.](https://getaimath.com/diagrams/transformer-architecture.png)
*Napkin Diagram (Transformer Architecture): Older AI read word-by-word and often lost track of earlier words; a Transformer highlights which words connect to which.*

## What is an example of Positional Encoding?

Without positional encoding, a model could not tell "I ate the cake" from "the cake ate I."

## Why does Positional Encoding matter?

Word order carries meaning, so every Transformer needs some form of positional information.

## Related Concepts

- [Attention Mask](https://getaimath.com/dictionary/attention-mask/): An attention mask is a pattern that tells the model which positions it may or may not attend to.
- [Rotary Positional Embedding (RoPE)](https://getaimath.com/dictionary/rotary-positional-embedding-rope/): RoPE is a popular way to tell a model about word positions by rotating its query and key numbers by an angle based on position.
- [FlashAttention](https://getaimath.com/dictionary/flashattention/): FlashAttention is a clever way to compute attention on GPUs that is much faster and uses much less memory, while giving the same results.
- [ALiBi](https://getaimath.com/dictionary/alibi/): ALiBi is a simple way of handling word position by adding a penalty to attention scores based on how far apart two words are.
- [Grouped-Query Attention (GQA)](https://getaimath.com/dictionary/grouped-query-attention-gqa/): Grouped-query attention is a middle ground where groups of heads share keys and values, balancing speed and quality.
- [Feed-Forward Network (FFN)](https://getaimath.com/dictionary/feed-forward-network-ffn/): A feed-forward network is the part of each Transformer block that processes each token on its own after attention.

---
Source: The AI Math Dictionary (https://getaimath.com/dictionary/positional-encoding/)
