跳到主要内容Skip to main content

位置编码Positional Encoding

Positional Encoding

  • 核心概念Core concepts
  • 第四段 · 看懂Stage 4 · Under the Hood
  • 引用核验 2026-11-09refs checked 2026-11-09
解决什么问题What problem it solves

让模型知道每个词在句子里的先后顺序。Lets the model know the order of words in a sentence.

这是什么What it is

给每个位置附加一组数字,使模型能分辨「猫追狗」和「狗追猫」。

Attaching a set of numbers to each position so the model can tell "the cat chased the dog" from "the dog chased the cat".

Attention alone is order-agnostic; position encoding injects “which token” so the model can distinguish “cat chases dog” from “dog chases cat”.
注意力本身对顺序不敏感;位置编码把「第几个 token」加进表示,模型才能区分「猫追狗」和「狗追猫」。Attention alone is order-agnostic; position encoding injects “which token” so the model can distinguish “cat chases dog” from “dog chases cat”.
为什么需要知道Why it matters

它解释了为什么上下文窗口超了之后,模型对长文的理解会明显退化。It explains why comprehension of long passages degrades noticeably once you exceed the context window.

出处Sources
  • RoFormer / RoPE(论文)RoFormer: Rotary Position Embedding (paper) ↗
  • Attention Is All You Need(正余弦编码)Attention Is All You Need (sinusoidal encoding, paper) ↗
用这个术语做任务Use this term in a task

别停在定义:去任务手册看按什么顺序做、验收什么;或者按你手头的任务,筛 3 个工具候选。Don’t stop at the definition: use the task handbook for the order and checks, or filter three tool candidates for the job at hand.

任务手册 →Task handbooks → · 按任务筛 3 个候选 →Filter three candidates →