Interview Q&A / AI & Generative AI

IntermediateQuick answer1 min readUpdated 3 Oct 2026

What is a causal mask in a decoder-only model?

SHORT ANSWER

A causal mask blocks each token from attending to later tokens, so position n sees only positions up to n. It matches generation, where future tokens do not exist yet, and lets training predict every position in parallel without cheating.

Explain it simply

Imagine writing an exam answer with the later pages covered by a sheet of paper. You can look back at what you wrote but not ahead.

During training the whole sentence is given at once for speed, and the model must predict each next token. If token 3 could see token 4, it would just copy it. The causal mask sets the attention scores for all future positions to a very negative number before softmax, so their weights become zero.

At generation time the future truly does not exist, so training and generation behave the same way. This is also why such a model builds text left to right and why earlier keys and values can be cached and reused.

Example

text
Attention allowed (1 = can look, 0 = blocked):
        t1 t2 t3 t4
  t1     1  0  0  0
  t2     1  1  0  0
  t3     1  1  1  0
  t4     1  1  1  1

What to say in the interview

"The causal mask is a lower-triangular mask applied to attention scores so a token only attends to itself and earlier tokens. It prevents leakage of the answer during parallel training and matches autoregressive generation."

#transformers#causal-mask#decoder

Related questions

Practise more AI & Generative AI questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open AI & Generative AI quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.