AI Anatomy Class · Part 5 · Mastering attention
51. No peeking at the future
Q. If you're supposed to guess the next word but can see it in advance, are you really learning anything?
- GPT guesses the next word (ch. 1). But in chapter 47's score table, 'I' is also looking at the words that come after it.
- In training, the whole sentence goes in at once. A word that sees the words after it is peeking at the answer, and learns nothing.
- So we pull down a curtain. Each word may see only itself and the words before it. Every cell above the diagonal is covered.
- Covered cells get the score −∞, an endlessly small number. e to the −∞ is 0, so after softmax those cells get 0%.
- Softmax each row again: 'I' gives 100% to itself, and 'walk' gives 97.2% to 'I' and 2.8% to itself.
- The row of 'school' doesn't change: every word it looks at is already before it. Chapter 49's mix (2.25, 1.52) stays the same too.
- This triangle curtain lets every position train at once without seeing the future. It's called the causal mask.
- Writing works the same way. It writes one word at a time (ch. 2), so the future it hasn't written yet can't be seen.
Chapter summary
- Seeing later words during training is peeking at the answer, so the future cells are covered.
- Change the covered scores to −∞ and their shares become 0% after softmax.
- Each word sees only itself and the words before it: the causal mask. The last word's row stays the same.