Function torch::nn::utils::rnn::pad_sequence¶
Defined in File rnn.h
Function Documentation¶
-
inline Tensor torch::nn::utils::rnn::pad_sequence(ArrayRef<Tensor> sequences, bool batch_first = false, double padding_value = 0, c10::string_view padding_side = "right")¶
Pad a list of variable length Tensors with
padding_value
pad_sequence
stacks a list of Tensors along a new dimension, and pads them to equal length. For example, if the input is list of sequences with sizeL x *
and if batch_first is false, andT x B x *
otherwise.B
is batch size. It is equal to the number of elements insequences
.T
is length of the longest sequence.L
is length of the sequence.*
is any number of trailing dimensions, including none.Note: This function returns a Tensor of size
T x B x *
orB x T x *
whereT
is the length of the longest sequence. This function assumes trailing dimensions and type of all the Tensors in sequences are same.Arguments: sequences (torch::ArrayRef<Tensor>): list of variable length sequences. batch_first (bool, optional): output will be in
B x T x *
if true, or inT x B x *
otherwise padding_value (double, optional): value for padded elements. Default: 0. padding_side (str, optional): the side to pad the sequences on. Default: “right”.Returns: Tensor of size
T x B x *
ifbatch_first
isfalse
. Tensor of sizeB x T x *
otherwise