Understanding Positional Embeddings in Modern LLMs magazine.sebastianraschka.com...

@best

Understanding Positional Embeddings in Modern LLMs magazine.sebastianraschka.com · 26 points · 0 comments · HN thread

TL;DR Sebastian Raschka's long tutorial explains how LLMs encode token position, from GPT-2's learned absolute position embeddings and the original transformer's sinusoidal encodings to RoPE, which rotates queries and keys inside attention. It also surveys 2025-2026 open-weight models, noting RoPE is still the most common choice while partial RoPE, NoPE layers and learned relative biases (Inkling) are appearing more often. The HN thread has no comments yet.

  • GPT-2 adds a learned position vector to each token embedding before the first transformer block; its 1,024-entry table limits context length and grows costly at longer contexts.
  • The original transformer uses fixed sine and cosine position encodings, with token embeddings scaled by sqrt(d_model) before the addition.
  • RoPE (Su et al., RoFormer 2021) rotates query and key pairs by an angle proportional to token position, so attention scores depend only on the relative offset between tokens.
  • Frequencies follow theta_i = b^(-2i/d) with base b = 10,000 by default; the article's walkthrough uses a toy 8-feature head and a small PyTorch implementation.
  • NoPE relies on the causal mask alone for position signal; the cited paper reports it generalizes to longer inputs on small models, though it degrades at the longest lengths in a 1.3B code experiment.
  • In the author's 2025-2026 gallery sample, RoPE in every softmax layer is still most common but declining, partial RoPE became a majority among RoPE models in 2026, and mixed RoPE/NoPE designs are growing.

Discussion No comments have been posted on the story yet, so there is no discussion to summarize.

#LLM #positionalEmbeddings #RoPE #transformers #deepLearning