首页›Ahead of AI›文章

Understanding Positional Embeddings in Modern LLMs

Sebastian Raschka, PhD · 2026年11月15日

AI 摘要 AI 生成,可能有误

本文是一篇详细介绍大语言模型(LLM)如何编码词元位置信息的教程,解释了为什么需要显式的位置信号(超越因果注意力掩码所隐含的顺序),并讲解了诸如GPT-2的可学习绝对位置嵌入、原始Transformer的固定正弦位置编码以及RoPE等方法,配有图示、数学公式和PyTorch代码加以说明。作者还预告了2026年开放权重模型架构中所采用的位置编码方法。本文既是一份可独立使用的基础参考资料,其写作源于读者对RoPE教程的请求,同时也是为即将推出的现代大语言模型架构趋势分析所做的准备。

This article explains how LLMs encode and process token position information by covering classic and contemporary methods like RoPE. It’s essentially a comprehensive journey where we will work through the mechanisms with visual examples, a little math, and a small PyTorch implementation. And, of course, we will then also look at how modern architectures adapt or omit explicit positional encodings.

Below, you can find a preview of which positional embedding choices are used in 2026 open-weight models. We will discuss these choices later after covering the underlying mechanisms.

Figure 1: A preview of the gallery’s 2026 architectures, grouped by positional encoding. Architecture figures taken from my LLM gallery.
继续阅读全文

为了尊重作者,这里只展示开头几段。你可以去原文阅读,或者在 HorizonReader 里读:划线做笔记、让 AI 帮忙。

更多来自 Ahead of AI

Building Reasoning Models from the Ground Up: A Full Video Course

AI 摘要The author announces an 11-hour, eight-video course that builds a reasoning model from scratch in Python and PyTorch, starting from a pre-trained Qwen3 model and covering evaluation with a math verifier, inference-time scaling techniques like sampling, self-consistency, and self-refinement, and reinforcement learning with verifiable rewards using GRPO. The videos accompany his book 'Build a Reasoning Model (From Scratch)' and require comfort with Python and PyTorch, with a GPU recommended for the training-focused later videos. He also explains that reasoning models act as the 'engine' inside agent harnesses, making them essential for understanding modern LLM-based agents.

Language Models for Text Classification: From Bag-of-Words to Jev

AI 摘要This article analyzes the newly released Jev AI model, positioning it as a fast and inexpensive text classifier that bridges the gap between general-purpose LLMs and narrow task-specific classifiers. To demystify the hype, the author traces the history of language models for text classification, from bag-of-words representations with classic methods like naive Bayes and logistic regression, through word embeddings and recurrent neural networks such as LSTMs, up to transformer-era approaches. The author concludes that while Jev is essentially a text classifier, it is more general and capable than its simple predecessors, which explains its recent popularity.

GPT-6 Astra, Looped Transformers, and Hidden Reasoning

AI 摘要The article reviews OpenAI's newly released GPT-6 Astra, describing it as the best model the author has used, with standout performance in 3D rendering, animation, and computer-use tasks, and explaining how computer-use skills are trained via reinforcement learning in macOS environments. It then explains 'looped transformers' (recurrent depth), an architecture in which intermediate representations pass through the same transformer blocks multiple times with shared weights, an idea dating back to Universal Transformers (2018). Finally, it examines whether this looped design relates to rumors that Astra conceals its chain-of-thought reasoning trace.

How Claude Watermarks AI-Generated Text

AI 摘要The author expands on a popular social media post by creating a detailed 48-minute video lecture (with over 50 slides and a transcript) explaining how Anthropic's new watermarking for Claude-generated text works. The lecture first covers how LLM text generation functions under the hood—tokenization, score distributions, and next-token sampling—to show that watermarking is a minor tweak within the normal generation process. The goal is to help readers understand how the invisible watermark is embedded, why it can fail or be removed, and its pros and cons.

Building an AI Text Detector From Scratch

AI 摘要This article presents an educational tutorial on building an AI text detector from scratch by fine-tuning a DistilBERT classifier that outputs a 0-100 score estimating how likely a text is AI-generated, similar to the approach behind Substack's new AI detection feature. The detector also serves as a verifier to train a small language model to produce text that avoids detection, illustrating the cat-and-mouse nature of AI detection, its limitations such as false positives, and the broader concept of verifier-based LLM applications. The end-to-end project includes evaluation, training, and local deployment via an API and a user-friendly browser interface.