可视化资源

注意力机制

从 Encoder-Decoder Attention 到 Self-Attention 与 Multi-Head Attention 的可视化。

编码器—解码器注意力

解码器逐步生成时的注意力流动
解码器每生成一个 token,都对编码器输出进行一次加权聚合(注意力)。
来源:Jay Alammar — The Illustrated Transformer

自注意力(Self-Attention)

自注意力计算流程
序列中每个位置作为 Query,与所有位置的 Key 计算相似度,再加权 Value 求和。
来源:Jay Alammar — The Illustrated Transformer

多头注意力(Multi-Head Attention)

多头注意力
多个独立的注意力"头"分别建模不同子空间,拼接后线性投影。
来源:Jay Alammar — The Illustrated Transformer

图片来源:Jay Alammar — The Illustrated Transformer

交互式资源