LoslegenKostenlos starten

Designing a mask for self-attention

To ensure that the decoder can learn to predict tokens, it's important to mask future tokens when modeling the input sequences. You'll build a mask in the form of a triangular matrix of True and False values, with False values in the upper diagonal to exclude future tokens.

Diese Übung ist Teil des Kurses

<Kurs>Transformer Models with PyTorch</Kurs>
Kurs ansehen

Übungsanweisungen

  • Create a Boolean matrix, tgt_mark to mask future tokens in the attention mechanism of the decoder body.

Interaktive praktische Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

seq_length= 3

# Create a Boolean matrix to mask future tokens
tgt_mask = (1 - torch.____(
  torch.____(1, ____, ____), diagonal=____)
).____()

print(tgt_mask)
Code bearbeiten und ausführen