返回游戏大厅

Transformer 架构演示

输入文字,观察 Token 如何在 Attention 机制中流动并生成输出。

Inputs Embedding Encoder Layer Self-Attention Feed Forward Decoder Layer Masked Self-Attention Cross-Attention Feed Forward Linear & Softmax Output Probabilities Outputs (Shifted)

组件速览

  • Embedding:将离散 Token 转换为可微向量。
  • Encoder:堆叠 Self-Attention + FFN,提取语义上下文。
  • Decoder:Masked Self-Attention + Cross-Attention,结合历史输出与编码特征生成答案。
  • Linear & Softmax:把隐状态映射到词表概率。

Attention 流程

动画展示了单个 Token 的旅程:

  1. 输入序列 -> Embedding,叠加位置编码。
  2. 进入 Encoder Self-Attention,获得上下文相关性。
  3. 通过桥接路径把编码结果送入 Decoder 的 Cross-Attention。
  4. Decoder 与自身历史 (Masked Self-Attention) 协调,输出下一 token 概率。

交互提示

  • 在输入框中输入多词短语,点击「开始处理」。
  • 每个词会按顺序以粒子形式经过 Encoder → Decoder。
  • 关注蓝色粒子(编码)与粉色粒子(解码)的交叉点,代表 Cross-Attention。
  • 输出端闪光提示 Softmax 产生的概率峰值。