liveBook · Manning

Mask

A mask is a representation or mechanism that selectively identifies, includes, excludes, reveals, or obscures specified parts of data, a system, or a computation.

How 9 Manning books explain it

GPU Programming with Triton

A mask is a per-element boolean predicate that enables or suppresses selected elements of a GPU memory operation.

How it is used
Protects Triton loads and stores when fixed-size blocks or tiles extend beyond valid data.
How deep it goes
Explains predicate construction, masked load and store behavior, multidimensional broadcasting, and replacement values for subsequent computations.
Examples
Works through a partially covered matrix tile and a fused softmax with negative-infinity replacement.
What you can do after
Apply it via Triton to guard boundary accesses and select replacement values appropriate to the computation.

Read how GPU Programming with Triton explains mask →

Deep Learning with PyTorch, Second Edition

How it is used
Selects editable image regions, segmentation pixels, or sample subsets for classification metrics.
How deep it goes
Explains mask meanings and metric operations with pipeline examples, while using pretrained models rather than implementing inpainting or Segment Anything from scratch.
Examples
Uses a horse-to-zebra edit, astronaut segmentation, and CT nodule masks to illustrate pixel selection.
What you can do after
Apply masks via diffusers and Segment Anything, and use Boolean masks to calculate classification metrics.

Read how Deep Learning with PyTorch, Second Edition explains mask →

Inside Deep Learning: Math, Algorithms, Models

The use of masks to ignore invalid or padded elements when processing batched variable-length data.

How it is used
Keeps padded items from affecting attention and context averages in batches of variable-length inputs.
How deep it goes
Works through Boolean mask construction, attention-score suppression, and valid-item averaging, including an empty-bag division safeguard.
Examples
Uses zero-filled items in a five-bag tensor, a masked attention network, and merged nuclei pixel labels.
What you can do after
Build it from scratch with PyTorch to identify padded items and exclude them from attention and context averages.

Read how Inside Deep Learning: Math, Algorithms, Models explains mask →

Graph Neural Networks in Action

A mask is a Boolean array or tensor that selects a subset of data elements.

How it is used
Selects labeled nodes for training while keeping other node subsets distinct in semi-supervised graph learning.
How deep it goes
Defines Boolean masks and works through their construction, embedding filtering, and use in a GNN training loop.
Examples
Uses complementary NumPy masks for a 20% labeled subset and a PyTorch `train_mask` to select predictions.
What you can do after
Build it from scratch with NumPy masks, then apply a PyTorch training mask to compute loss on labeled nodes.

Read how Graph Neural Networks in Action explains mask →

Build a Large Language Model (From Scratch)

A training-time method that prevents the model from attending to certain input positions, such as padding tokens.

How it is used
Uses masking during batched instruction fine-tuning to exclude padding and optionally prompt tokens from attention or loss.
How deep it goes
Implements padding, shifted targets, -100 replacement, and loss behavior, but leaves instruction masking optional.
Examples
Demonstrates masked target tensors, GPT end-of-text padding, and an exercise comparing instruction masking with unmasked training.
What you can do after
Apply masking via a custom PyTorch collate function and verify that ignored targets leave cross-entropy unchanged.

Read how Build a Large Language Model (From Scratch) explains mask →

Build a Text-to-Image Generator (from Scratch)

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

How it is used
Constrains decoder self-attention so sequence predictions cannot use future positions.
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.

Read how Build a Text-to-Image Generator (from Scratch) explains mask →

CSS in Depth, Second Edition

Masking is a CSS visual technique that selectively reveals or hides portions of an element using a mask image.

How it is used
Creates irregular silhouettes, fades, and selective visibility when rectangular rendering or border-radius is insufficient.
How deep it goes
Explains the opacity principle, demonstrates image and gradient masks, and catalogs related properties without descending into rendering internals.
Examples
Uses a star-shaped image mask, a fading linear gradient, a radial vignette, and repeating-gradient stripes.
What you can do after
Build masked images, tune their placement and repetition, create gradient fades, and diagnose invisible or misaligned masks.

Read how CSS in Depth, Second Edition explains mask →

Deep Learning with R, Third Edition

Masking is the exclusion of designated sequence positions from downstream neural-network computations.

How it is used
Excludes padding tokens from recurrent computations so sequence predictions use meaningful tokens.
How deep it goes
Explains implicit embedding-layer masking and its effect on LSTM output, while deferring explicit mask construction.
Examples
Uses padded movie-review sequences and an R/Keras Embedding–bidirectional LSTM classifier.
What you can do after
Apply it via Keras by reserving zero for padding and enabling mask_zero on an Embedding layer.

Read how Deep Learning with R, Third Edition explains mask →

Deep Learning with Python, Third Edition

A technique for marking padded or irrelevant sequence positions so later layers ignore them.

How it is used
Uses masks in padded text sequences so recurrent classifiers ignore padding when producing final predictions.
How deep it goes
Explains implicit zero-based masking and optional explicit masks, without detailing custom mask construction.
Examples
Demonstrates a padded movie review ending in “awful” and a Keras Embedding-to-Bidirectional-LSTM model.
What you can do after
Operate/configure Keras sequence models that ignore zero-valued padding or accept explicit masks.

Read how Deep Learning with Python, Third Edition explains mask →

Also covered in

What to know first

Related concepts

Questions about mask

What is mask?

A mask is a representation or mechanism that selectively identifies, includes, excludes, reveals, or obscures specified parts of data, a system, or a computation.

Which Manning books explain mask?

GPU Programming with Triton, Deep Learning with PyTorch, Second Edition, Inside Deep Learning: Math, Algorithms, Models, Graph Neural Networks in Action, Build a Large Language Model (From Scratch), Build a Text-to-Image Generator (from Scratch), CSS in Depth, Second Edition, Deep Learning with R, Third Edition and 1 more.

What should I know before learning mask?

Manning books that teach mask usually introduce language model, accuracy, softmax and backpropagation first.

What is the difference between mask and crop?

A mask is a representation or mechanism that selectively identifies, includes, excludes, reveals, or obscures specified parts of data, a system, or a computation. Cropping is an image-processing operation that selects a subregion of an image and excludes the portions outside it.

What kinds of mask are there?

Kinds of mask include response mask.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.