liveBook · Manning

Mask

As explained in Build a Text-to-Image Generator (from Scratch)

A mechanism that selectively blocks information from specified sequence positions during model computation.

A mask selectively blocks sequence positions during computation. In decoder self-attention, it prevents each position from accessing future tokens, preserving the previously known context required for sequential prediction. section 2.1.2

The mechanism serves the decoder in three connected stages:

  • Place the mask in the decoder’s first sublayer, the masked multi-head self-attention layer. section 2.1.2
  • Restrict attention so a prediction at one position depends only on previously known elements. section 2.1.2
  • Support autoregressive tasks such as machine translation and text generation while the decoder produces one token at a time. section 2.1.2
Figure 2.6 The structure of the decoder in the transformer

Use the decoder architecture to locate masked self-attention before cross-attention and the feed-forward network. section 2.1.2

How Build a Text-to-Image Generator (from Scratch) covers it

How deep it goes
Explains purpose and architectural placement, while deferring detailed masking mechanics.
Examples
Uses German-to-English translation and one-token-at-a-time text generation as concrete applications.
What you can do after
Understand how masking preserves valid sequential dependencies during decoder prediction.
How it connects
Connects masking with decoder self-attention, multi-head attention, cross-attention, machine translation, and text generation.

Also explained in

Compare how 7 books explain mask →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Text-to-Image Generator (from Scratch). The section links point to the parts of the book it draws on.