# Transformer 正弦位置编码

> 来源：https://deeplearning.bnuai.com/demos/positional-encoding ｜ 作者：唐志清（北京师范大学） ｜ 更新：2026-11-01 ｜ 内容依据邱锡鹏《神经网络与深度学习》（https://nndl.ai/）及作者公开课件

> （此处为交互演示，请在网页中使用：https://deeplearning.bnuai.com/demos/positional-encoding）

## 观察要点

1. 自注意力本身对输入顺序不敏感（置换等变），必须额外注入位置信息。
2. 不同维度使用不同频率，组合起来能唯一表示每个位置。
3. 许多新模型改用可学习位置编码或旋转位置编码（RoPE）等相对位置方案。

相关章节：[第 8 章 注意力机制与外部记忆](https://deeplearning.bnuai.com/chapters/08-attention-memory)。
