Spec-Zone.ru › PyTorch 1

torch.nn.utils.rnn.pad_sequence

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

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 size L x * and if batch_first is False, and T x B x * otherwise.

B is batch size. It is equal to the number of elements in sequences. T is length of the longest sequence. L is length of the sequence. * is any number of trailing dimensions, including none.

Пример

>>> 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()
torch.Size([25, 3, 300])

Примечание

This 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]) – список последовательностей переменной длины.
  • batch_first (bool, optional) – выходной тензор будет в B x T x * если True, или в T x B x * в противном случае. По умолчанию: False.
  • padding_value (float, optional) – значение для заполненных элементов. По умолчанию: 0.
Возвращаемое значение:

Tensor размера T x B x * если batch_first является False. Tensor размера B x T x * в противном случае

Тип возвращаемого значения:

Tensor

© 2024, PyTorch Contributors
PyTorch has a BSD-style license, as found in the LICENSE file.
https://pytorch.org/docs/1.13/generated/torch.nn.utils.rnn.pad_sequence.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API