1Q · 6 × 16 (one head)
K · 6 × 16
S = Q K⊤ / √16
K · 6 × 16
S = Q K⊤ / √16
Scores
BOSmarta
BOS0.8-0.31.10.2-0.90.4
m1.20.6-0.20.90.1-0.7
a0.31.60.5-0.41.00.2
r-0.50.61.90.4-0.30.8
t0.2-0.10.71.70.5-0.6
a0.40.3-0.20.61.80.9
BOSmarta
BOS0.8-0.31.10.2-0.90.4
m1.20.6-0.20.90.1-0.7
a0.31.60.5-0.41.00.2
r-0.50.61.90.4-0.30.8
t0.2-0.10.71.70.5-0.6
a0.40.3-0.20.61.80.9
2+ causal mask
BOSmarta
BOS0.8−∞−∞−∞−∞−∞
m1.20.6−∞−∞−∞−∞
a0.31.60.5−∞−∞−∞
r-0.50.61.90.4−∞−∞
t0.2-0.10.71.70.5−∞
a0.40.3-0.20.61.80.9
BOSmarta
BOS0.8−∞−∞−∞−∞−∞
m1.20.6−∞−∞−∞−∞
a0.31.60.5−∞−∞−∞
r-0.50.61.90.4−∞−∞
t0.2-0.10.71.70.5−∞
a0.40.3-0.20.61.80.9
3softmax → weights
BOSmarta
BOS1.0000000
m.65.350000
a.17.62.21000
r.06.17.63.1400
t.11.08.18.49.150
a.11.10.06.13.43.18
BOSmarta
BOS1.0000000
m.65.350000
a.17.62.21000
r.06.17.63.1400
t.11.08.18.49.150
a.11.10.06.13.43.18
V · 6 × 16 (one head)
BOS
m
a
r
t
a
BOS
m
a
r
t
a
out = weights · V (6 × 16)
BOS
m
a
r
t
a
BOS
m
a
r
t
a
4Row “r”: out(r) = Σ weight × value
BOS 0.06 × v(“BOS”)
m 0.17 × v(“m”)
a 0.63 × v(“a”)
r 0.14 × v(“r”)
“t” and the last “a” are in the future: weight 0.
BOS 0.06 × v(“BOS”)
m 0.17 × v(“m”)
a 0.63 × v(“a”)
r 0.14 × v(“r”)
“t” and the last “a” are in the future: weight 0.
58 heads · each 6 × 16
concatenate
back to 6 × 128
back to 6 × 128
× Wo⊤ (128 × 128)
mixes what the heads found
mixes what the heads found
+ residual
new x = x + attention output
new x = x + attention output
rows add up to 1
the same happens in all 8 heads, in parallel