Padding and Masks for Different Sequence Lengths

Batching sequences of different lengths can add padding positions. A mask can tell operations which positions count as actual input.

Source
Anbloq
Language
English
Created
Updated
Chapters
2
Reading time
1 min
In this article2 chapters
  1. Trace two lengths
  2. Test the masked interface

Trace two lengths

Sequences of lengths two and four can both occupy four slots, with the first mask marking only its first two. An average over all four slots would dilute the short sequence under a simple zero-padding rule. See missing inputs.

Test the masked interface

Compare a sequence alone with the same sequence in a padded batch under the model's expected semantics. Axis selection helps identify where masking must apply.[1]

References

  1. Ian Goodfellow, Yoshua Bengio and Aaron Courville, Deep Learning ↩