Learn AI Math

Attention Mask

What is Attention Mask?

In one sentence: An attention mask is a pattern that tells the model which positions it may or may not attend to.

It is a grid of allowed and blocked spots. Blocked spots get a huge negative score before softmax, so they end up with almost zero attention. Masks are used for causal generation and to skip padding tokens.

What does Attention Mask look like?

If a sentence is padded with empty tokens to fit a batch, the attention mask makes sure the model ignores them.

Why does Attention Mask matter?

Attention masks keep models from seeing things they should not see.

Last updated · Fact-checked by The AI Math

Linking to this page from a lesson or article?

Like this explanation? Get one every week.

The AI Math newsletter turns confusing AI news into plain English. No hype, no jargon walls.