How to add padding mask to nn.TransformerEncoder module?
discuss.pytorch.org › t › how-to-add-padding-mask-toDec 08, 2019 · I think, when using src_mask, we need to provide a matrix of shape (S, S), where S is our source sequence length, for example, import torch, torch.nn as nn q = torch.randn(3, 1, 10) # source sequence length 3, batch size 1, embedding size 10 attn = nn.MultiheadAttention(10, 1) # embedding size 10, one head attn(q, q, q) # self attention
torch.nn.utils.rnn.pad_sequence — PyTorch 1.11.0 documentation
pytorch.org › torchThis function returns a Tensor of size T x B x * or B x T x * where T is the length of the longest sequence. This function assumes trailing dimensions and type of all the Tensors in sequences are same. sequences ( list[Tensor]) – list of variable length sequences. batch_first ( bool, optional) – output will be in B x T x * if True, or in T ...