Shortcuts

Function torch::nn::utils::rnn::pad_packed_sequence

Function Documentation

inline std::tuple<Tensor, Tensor> torch::nn::utils::rnn::pad_packed_sequence(PackedSequence sequence, bool batch_first = false, double padding_value = 0.0, c10::optional<int64_t> total_length = torch::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 *, where T is the length of the longest sequence and B is the batch size. If batch_first is true, the data will be transposed into B 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 in B 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 length total_length. This method will throw error if total_length is less than the max sequence length in sequence.

Returns: Tuple of Tensor containing the padded sequence, and a Tensor containing the list of lengths of each sequence in the batch.

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources