freecoding.school100% FREE · NO SIGNUP
Tensor TownISSUE #47 of 120

positional encoding · giving order back

NeuraVSThe Overfit Ogre
Neura saysPositional encoding gives transformers a sense of order, which attention alone lacks.

Self-attention is order-agnostic — it sees a set, not a sequence. Positional encodings inject position information into token representations (sinusoidal patterns, learned embeddings, or modern rotary/RoPE). Without them, "dog bites man" and "man bites dog" would look identical. Positional schemes also shape how far a model can extrapolate beyond its training length.

Power-ups you unlock

The Overfit Ogre attacks — common mistakes

Boss battleExplain why "dog bites man" needs positional encoding to differ from "man bites dog".

Example code

<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre>attention sees a SET, not an order
add positional encoding → tokens know their place
"dog bites man" ≠ "man bites dog"</pre></body></html>
▶ Open the interactive comic issue
‹ Multi-Head Attention · Parallel ViewsEncoder-Only · Bert Family ›