Skip to content

Causal masking

The complete sentence is available to the computer. Does that mean every token in the model can read all of it?

Compare the cat sat on the mat with the cat sat on the bed. You will measure the next-token prediction at the earlier word sat, rather than at the end of either sentence.

The interactive experiment uses JavaScript. If it does not appear, enable JavaScript or reload. You can also read how attention works.

The model computes a next-token distribution at every input position. A causal mask prevents each position from attending to later positions in every layer. Here you test that restriction using two inputs with identical prefixes and positions, and different suffixes.

This restriction applies during the forward pass. It does not mean later words were absent from training data, or that changing an earlier word cannot affect predictions later in the sentence. Read the attention chapter for the equations, or write masked attention yourself.

Spotted a mistake, a confusing explanation or a broken widget? Report a problem with this page

Methods & evidence · Run locally

Free for noncommercial use. Text CC BY-NC-SA 4.0, code PolyForm Noncommercial. Source on GitHub · How to contribute