Attention mixes positions. A complete decoder must also represent order and predict the next token.
Machine Learning in Engineering Science Fall 2026 · Week 07 · Hour 3 Chi-Hua Jonny Yu · NCKU / LAiMM


W07 · H3 · 16:00–17:00 · 19 October 2026
Attention mixes positions. A complete decoder must also represent order and predict the next token.
Machine Learning in Engineering Science Fall 2026 · Week 07 · Hour 3 Chi-Hua Jonny Yu · NCKU / LAiMM


W07 · H3 · Machine Learning in Engineering Science
Trace the complete computation, then test whether future tokens can affect earlier predictions.
Goal: explain a block and preserve a causal training experiment.


W07 · H3 · Machine Learning in Engineering Science
Unmasked attention alone is permutation-equivariant when positions are absent.
Attention(PX) = P Attention(X)


W07 · H3 · Machine Learning in Engineering Science
The teaching model adds learned position vectors; the original Transformer used sinusoidal encodings.
zₜ = token_embedding(idₜ) + position_embedding(t)


W07 · H3 · Machine Learning in Engineering Science
Each head routes information in its own learned query/key/value subspace.
D = H × dhead


W07 · H3 · Machine Learning in Engineering Science
Head outputs are joined and mixed by a learned output projection.
MultiHead = Concat(head₁,…,headH) WO


W07 · H3 · Machine Learning in Engineering Science
The same nonlinear MLP is applied independently at each position.
FFN(x) = W₂ GELU(W₁x + b₁) + b₂


W07 · H3 · Machine Learning in Engineering Science
A sublayer adds a learned update to its input representation.
y = x + Sublayer(x)


W07 · H3 · Machine Learning in Engineering Science
Our teaching decoder normalizes before each sublayer.
x ← x + Attention(LN(x))


W07 · H3 · Machine Learning in Engineering Science
Encoder self-attention can access all valid input positions.


W07 · H3 · Machine Learning in Engineering Science
Masked self-attention supports next-token prediction from a prefix.


W07 · H3 · Machine Learning in Engineering Science
Decoder queries can retrieve from the separate encoder outputs.


W07 · H3 · Machine Learning in Engineering Science
Shift targets one step ahead of inputs.
input: [0,1,2,3] target: [1,2,3,4]


W07 · H3 · Machine Learning in Engineering Science
The model should assign high probability to observed next-token targets.
L = −mean log p(yₜ | x≤ₜ)


W07 · H3 · Machine Learning in Engineering Science
The causal mask permits computing many training losses together.


W07 · H3 · Machine Learning in Engineering Science
One block, width 32, four heads, and eight symbols keep the experiment small.


W07 · H3 · Machine Learning in Engineering Science
Separate streams use different noise seeds but share the same synthetic process.


W07 · H3 · Machine Learning in Engineering Science
Every head produces a query-by-key grid for each example.
scores: (B, H, T, T)


W07 · H3 · Machine Learning in Engineering Science
The output has one vocabulary-logit vector per input position.
IDs: (B,T) → logits: (B,T,V)


W07 · H3 · Machine Learning in Engineering Science
Estimate the next state from the current state using transition counts.
P(next | current) = smoothed count / row total


W07 · H3 · Machine Learning in Engineering Science
Keep the checkpoint with lowest validation negative log-likelihood.



W07 · H3 · Machine Learning in Engineering Science
Rows are receiving positions; columns are source positions.



W07 · H3 · Machine Learning in Engineering Science
Change tokens after position 7; logits at positions 0–7 should remain identical.
Δearlier = max |old_logits − new_logits|


W07 · H3 · Machine Learning in Engineering Science
Permute inputs to unmasked attention without positional information.


W07 · H3 · Machine Learning in Engineering Science
Autoregressive decoding grows the prefix sequentially.


W07 · H3 · Machine Learning in Engineering Science
Dense attention pair counts grow as T² at fixed head count.
T=16: 256 pairs T=32: 1024 pairs


W07 · H3 · Machine Learning in Engineering Science
Streaming state, context length, data size, and compute budget all matter.


W07 · H3 · Machine Learning in Engineering Science
An agent also needs tools, state management, permissions, and a stopping rule.


W07 · H3 · Machine Learning in Engineering Science
Record data identity, configuration, baseline, checkpoint, and observed tests.


W07 · H3 · Machine Learning in Engineering Science
A causal decoder combines attention with position and feature transformations. Its predictions still need evidence.
prefix → masked decoder → next-token logits Check: baseline error + future-token intervention
← → navigate · N notes · R answer · O overview · F fullscreen