Skip to content
AI & Machine Learning Rich #positional-encoding#rope#transformer

Positional Encoding & RoPE

Attention is order-blind. Add positional signal: sinusoidal, learned, or rotary.

A free, animated positional encoding & rope you can read here or embed on any website, from Scrollchart.

Positional Encoding & RoPE

Positional Encoding & RoPEAttention is order-blind: three schemes to inject position (sinusoidal, learned, rotary)Sinusoidal (fixed)Learned (trainable)RoPE (rotary)dim 0dim 15pos 0pos 7sin(pos/10000^(2i/d)) at even dimslow dims oscillate fast, high dims slowp0p1p2p3p4p5(max_len x d) table, updated by gradient descentdoes not extrapolate beyond max_len0,1fast2,34,56,7slowq,k rotated by angle m*theta_i at position mdot-product depends only on relative distanceenables length extrapolation (YaRN, LLaMA-3)ComparisonSinusoidalLearnedRoPEExtrapolates?yes (degrades)noyes (with YaRN)Parametersnone (fixed)max_len x dnone (fixed)Used inoriginal TransformerBERT, GPT-2Llama 2/3, MistralRoPE is now the dominant scheme in open-weight frontier models: no extra parameters, multiplicative injection, relative-distance attention, extensible context.

Three position schemes side by side. Sinusoidal: stacked sin/cos at varied frequencies forming a heatmap. Learned: a (max_len x d) trainable table. RoPE: pairs of dimensions rotated by angle proportional to position, applied multiplicatively in Q/K. Length extrapolation behavior shown for each.

Good for

  • RoPE/ALiBi explainers
  • Long-context model articles
  • Architecture comparisons

Source & accuracy

This positional encoding & rope is an editorial illustration built to represent the concept accurately. Where it shows figures, they are typical or representative values chosen to make the relationship clear, not a single underlying dataset. The diagram and its explainer are reviewed and maintained centrally, and updated over time as understanding improves.

Adding order to orderless attention

Attention mechanisms are inherently permutation-invariant: they compute relationships between all pairs of tokens without regard to sequence position. While this flexibility is powerful, it also means the model cannot distinguish between identical sequences presented in different orders. Positional encoding solves this by injecting position information directly into token embeddings before they enter the attention layers.

The classical approach uses sinusoidal functions of different frequencies to encode each position and embedding dimension, creating a unique fixed pattern for every position. Learnable positional embeddings offer an alternative, allowing the model to optimize position representations during training. Both methods create a structured signal that attention can parse to extract sequential relationships.

Rotary embeddings for extrapolation

Rotary Position Embedding (RoPE) takes a different approach by applying geometric rotations to the query and key vectors before computing attention scores. This method naturally handles sequences longer than those seen during training, since the rotation angles scale predictably with position. RoPE has become standard in modern large language models because it combines stability with strong extrapolation properties, allowing models trained on sequences of length 2048 to handle 8192-token contexts at inference time.

Embed this diagram

Add this animated positional encoding & rope to your own site. Copy one line of HTML, or use the embed builder for theme and sizing options.

Reference

What this is
A free, embeddable, animated positional encoding & rope for any website.
Who uses it
AI/ML blogs, CS educators.
How to embed
Copy one line of HTML. No signup. No watermark. Works in WordPress, Webflow, Ghost, Substack, plain HTML.
File size
iframe embed, ~80 KB gzipped (loads on demand, does not block your page paint).
License
Free forever. Editorial explainer text included; updated centrally over time.

Embed format options

Copy the universal HTML snippet, the WordPress shortcode, or an iframe fallback - see the WordPress plugin page for details. Any format keeps the same Core Web Vitals profile and the same explainer text.

Embed snippet
<div data-scrollchart="positional-encoding" data-scrollchart-v="1"></div>
<script src="https://scrollchart.com/embed.js" async></script>

Frequently asked questions

Where can I get a free animated "Positional Encoding & RoPE" for my website?
Scrollchart provides "Positional Encoding & RoPE" as a free, embeddable animated diagram you can add to any website with one line of HTML. No signup is required and there is no watermark. The diagram and its explainer text are served from scrollchart.com, so the embed stays current without any maintenance on your end.
How do I embed a positional encoding & rope in a developer or tech blog?
Copy the one-line snippet from the Scrollchart diagram page and paste it into your post HTML. It works in any static site generator, CMS, or hand-coded HTML page. The embed is a thin loader, not an iframe, so the content is fully in your DOM.