当前位置:网站首页>torch. nn. utils. rnn. pad_ Detailed explanation of sequence() [pytoch getting started manual]

torch. nn. utils. rnn. pad_ Detailed explanation of sequence() [pytoch getting started manual]

2022-06-10 15:53:00 Classmate K

The function prototype

torch.nn.utils.rnn.pad_sequence(sequences, batch_first=False, padding_value=0.0)

The functionality

This function returns a size of T x B x * or B x T x * Tensor , among T Is the length of the longest sequence .

Parameters,

  • sequences (list[Tensor]): A list of variable length sequences ,shape=[batch_size, N],N Different lengths .
  • batch_first (bool, optional) : Default batch_size In the first dimension
  • padding_value (float, optional) : Fill the value of the , The default is 0.

Example

from torch.nn.utils.rnn import pad_sequence

a = torch.ones(25, 300)
b = torch.ones(22, 300)
c = torch.ones(15, 300)
pad_sequence([a, b, c]).size()

Output

torch.Size([25, 3, 300])
原网站

版权声明
本文为[Classmate K]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/161/202206101534027247.html