S3-10 · 进阶 · 并行关系视图S3-10 · Advanced · Parallel relationship views

多头注意力 · 同一句话,三套看法同时算Multi-Head Attention · Three Views of One Sentence, Computed Together

parallel heads → different weighted views → concatenate and project

多头注意力(Multi-Head Attention)让多组独立注意力并行观察不同关系,再把各组结果合并。多个 head 不是多个 Agent,也不保证每个 head 都能被人解释。Multi-head attention runs several independent attention views in parallel, then combines their results. Heads are not Agents, and each head is not guaranteed to have a human-readable role.

01 · 同时看三种线索01 · Track three clues at once

读“女孩把书给男孩,因为他需要它”时,你会只盯着一种关系吗?In “The girl gave the boy a book because he needed it,” would one relationship be enough?

02 切换三个 head,再拖动合并比例Switch Heads, Then Adjust Their Merge

3 路并行3 parallel views
当前视图Inspected view
HEAD 1
指代关系reference relation
最粗来源Thickest source
48%
合并主导Merge leader
H1
45%

S3 线宽语法不变:lineWidth = 1.5 + weight × 10。切换 head 改变“哪套权重”,拖合并比例改变最终混合。S3 line grammar stays fixed: lineWidth = 1.5 + weight × 10. Switching heads changes the weight set; merge sliders change the final mix.

03 多头注意力的 4 个零件Four Parts of Multi-Head Attention

split · attend · join
PART 01

独立投影Separate projections

每个 head 有自己的一套 Q、K、V 投影。Each head owns a separate Q, K, and V projection.

PART 02

并行权重Parallel weights

各 head 对同一序列独立分配注意力。Heads assign attention over the same sequence independently.

PART 03

各自结果Per-head results

每一路先形成自己的加权汇总。Each path first produces its own weighted result.

PART 04

合并投影Joined projection

结果拼接后再投影回统一表示。Results concatenate, then project back into one representation.

04 最小机制:先各看各的,再装回一个向量Minimal Mechanism: Separate Views, Then One Vector Again

Concat(head1…headh)WO
headi = Attention(QWiQ, KWiK, VWiV)
三个滑杆是教学用合并比例。真实 Transformer 通常用学习到的输出投影完成合并,不是人工命名每个 head。The sliders are a teaching proxy for combination. A real Transformer usually learns an output projection; people do not manually name every head.
复制成多路Fan into heads同一输入,不同投影Same input, different projections
并行注意Attend in parallel每路得到一套线宽Each path gets its own widths
合并输出Merge outputs多种关系进入同一表示Views return to one representation

05 边界实验:让一路吞掉全部合并权重Boundary Test: Let One Head Swallow the Entire Merge

主动制造失败Create a failure

有多个 head,不等于真的使用了多种关系Having many heads does not mean many views survive

把 Head 1 拉到 100%,其余接近 0。并行结构仍在,但合并结果几乎只剩一路。Push Head 1 to 100% and the others near zero. Parallel paths still exist, but the merged result keeps almost one view.

尚未执行。三路都会进入合并结果。Not run yet. All three views enter the merged result.
一个 head 就是一个 Agent。One head is one Agent. → ✓ head 是一次并行注意力计算路径。A head is one parallel attention path.
每个 head 必然有清楚语义。Every head must have a clear meaning. → ✓ 角色标签只是教学视图,不是保证。Role labels are teaching views, not guarantees.
head 越多一定越聪明。More heads always mean more intelligence. → ✓ 数量、维度与任务效果需要一起验证。Count, dimension, and task results must be evaluated together.
06 · 一句话带走06 · One line to keep

多头注意力用多套独立权重并行观察同一序列,再合并成一个结果;切换 head 和拖动比例即可分别检验“分头看”与“合起来”。Multi-head attention applies independent weight sets to one sequence in parallel, then merges the results. Switch heads and adjust the mix to verify both stages.