注意力分数 · 一条粗线是怎样算出来的Attention Score · How a Thick Line Gets Its Number
Q · K → scale by √dk → softmax → attention weight → line width
注意力分数是查询与键的匹配值经缩放和归一化后形成的权重。它把点积、softmax 与可见线宽接成一条可核对的因果链。An attention score becomes a weight after the Query–Key match is scaled and normalized. It connects dot product, softmax, and visible line width into one checkable causal chain.
01 · 粗线背后有账本01 · Every thick line has a ledger
为什么某条注意力线是 8.1 px,而不是凭感觉画粗一点?Why is one attention line 8.1 px wide instead of simply “drawn a bit thicker”?
Q·K
02点击一条线,展开四格账本Select a Line and Unfold Its Four-Cell Ledger
点积 → 线宽Dot product → width
① 点积① Dot product
—
Q · K
② 缩放② Scaled
—
÷ √2
③ 权重 → ④ 线宽③ Weight → ④ Width
—
—
复用 S3 线宽语法:lineWidth = 1.5 + weight × 10。只有 softmax 后的非负权重进入线宽。S3 line grammar reused: lineWidth = 1.5 + weight × 10. Only nonnegative post-softmax weights enter line width.
03从匹配值到可见线宽的 4 格Four Cells from Match Value to Visible Width
逐格可审计Auditable cell by cell
CELL 01
点积Dot product
Q 的两个分量与 K 的两个分量分别相乘再相加。Multiply the two Q and K component pairs, then add them.
CELL 02
缩放Scale
除以 √dk,避免维度大时点积过尖。Divide by √dk so large dimensions do not make scores too sharp.
CELL 03
Softmax
所有候选一起归一化为总和 1 的非负权重。Normalize all candidates together into nonnegative weights summing to one.
CELL 04
线宽Line width
统一映射把同一个权重变成可比较的粗细。One shared mapping turns that weight into comparable thickness.
04最小机制:三步计算,一步显示Minimal Mechanism: Three Calculations, One Display
α = softmax(QKT / √dk)
Q · Ki → si/√2 → αi → 1.5 + 10αi
点击不同线,前三格来自计算,最后一格只负责把 α 变成画面语言。Select different lines. The first three cells are computation; the last only translates α into visual language.
Q · K得到可正可负的匹配值A signed match value
÷ √dk控制分数尺度Control score scale
softmax → px权重竞争后再画线Compete, normalize, then draw
05边界实验:跳过缩放与 softmax 直接画线Boundary Test: Draw Raw Scores Without Scaling or Softmax
主动制造失败Create a failure
原始点积可能为负,也不保证总和为 1Raw dot products may be negative and do not sum to one
把三个点积直接当权重。负分无法成为负线宽,正分总和也不等于 100%,可视语法失去统一意义。Treat the three dot products as weights. A negative score cannot become negative width, and positive scores do not sum to 100%, so the visual grammar loses meaning.
尚未执行。正常线宽只接受 softmax 后权重。Not run yet. Normal line width uses post-softmax weights only.
✗ 点积就是最终注意力权重。The dot product is the final attention weight. → ✓ 它还要经过缩放与候选间归一化。It still needs scaling and cross-candidate normalization.
✗ 每条线可以独立做 softmax。Each line can run softmax alone. → ✓ 候选必须一起竞争,总和才为 1。Candidates compete together so weights sum to one.
✗ 粗细只是装饰。Thickness is decorative. → ✓ 同一公式把权重机械映射成线宽。One formula mechanically maps weight to width.
06 · 一句话带走06 · One line to keep
注意力权重来自 Q-K 点积、缩放与 softmax;点击任一连线,就能把数值一路核对到最终线宽。Attention weight comes from Q–K dot product, scaling, and softmax. Select any line to audit its numbers all the way to final width.