Function torch::nn::utils::rnn::pad_packed_sequence¶
Defined in File rnn.h
Function Documentation¶
-
inline std::tuple<Tensor, Tensor> torch::nn::utils::rnn::pad_packed_sequence(const PackedSequence &sequence, bool batch_first = false, double padding_value = 0.0, std::optional<int64_t> total_length = std::nullopt)¶
Pads a packed batch of variable length sequences.
It is an inverse operation to
pack_padded_sequence
.The returned Tensor’s data will be of size
T x B x *
, whereT
is the length of the longest sequence andB
is the batch size. Ifbatch_first
is true, the data will be transposed intoB x T x *
format.Batch elements will be ordered decreasingly by their length.
Arguments: sequence (PackedSequence): batch to pad batch_first (bool, optional): if
true
, the output will be inB x T x *
format. padding_value (double, optional): values for padded elements. total_length (int64_t, optional): if specified, the output will be padded to have lengthtotal_length
. This method will throw error iftotal_length
is less than the max sequence length insequence
.Returns: Tuple of Tensor containing the padded sequence, and a Tensor containing the list of lengths of each sequence in the batch.