評價此頁

PackedSequence#

class torch.nn.utils.rnn.PackedSequence(data, batch_sizes=None, sorted_indices=None, unsorted_indices=None)[source]#

儲存已打包序列的資料和 batch_sizes 列表。

所有 RNN 模組都接受已打包序列作為輸入。

注意

此類的例項不應手動建立。它們應由 pack_padded_sequence() 等函式例項化。

Batch sizes 表示批次中每個序列步的元素數量,而不是傳遞給 pack_padded_sequence() 的可變序列長度。例如,給定資料 abcxPackedSequence 將包含資料 axbc,其中 batch_sizes=[2,1,1]

變數
  • data (Tensor) – 包含已打包序列的張量

  • batch_sizes (Tensor) – 包含每個序列步批次大小資訊的整數張量

  • sorted_indices (Tensor, optional) – 包含此 PackedSequence 如何從序列構建的整數張量。

  • unsorted_indices (Tensor, optional) – 包含如何恢復具有正確順序的原始序列的整數張量。

返回型別

自我

注意

data 可以位於任意裝置和任意 dtype 上。sorted_indicesunsorted_indices 必須是與 data 相同裝置上的 torch.int64 張量。

但是,batch_sizes 必須始終是 CPU torch.int64 張量。

此不變數在 PackedSequence 類中一直保持,並且 PyTorch 中所有構造 PackedSequence 的函式(即,它們僅傳入符合此約束的張量)。

batch_sizes: Tensor#

Alias for field number 1

count(value, /)#

返回值的出現次數。

data: Tensor#

Alias for field number 0

index(value, start=0, stop=9223372036854775807, /)#

返回值的第一個索引。

如果值不存在,則引發 ValueError。

property is_cuda: bool#

如果 self.data 儲存在 GPU 上,則返回 True。

is_pinned()[source]#

如果 self.data 儲存在固定記憶體中,則返回 True。

返回型別

布林值

sorted_indices: Optional[Tensor]#

欄位編號 2 的別名

to(dtype: dtype, non_blocking: bool = ..., copy: bool = ...) Self[source]#
to(device: Optional[Union[str, device, int]] = ..., dtype: Optional[dtype] = ..., non_blocking: bool = ..., copy: bool = ...) Self
to(other: Tensor, non_blocking: bool = ..., copy: bool = ...) Self

self.data 執行 dtype 和/或 device 轉換。

它具有與 torch.Tensor.to() 相似的簽名,但像 non_blockingcopy 這樣的可選引數應作為 kwargs 傳遞,而不是 args,否則它們將不適用於索引張量。

注意

如果 self.data 張量已具有正確的 torch.dtypetorch.device,則返回 self。否則,返回具有所需配置的副本。

unsorted_indices: Optional[Tensor]#

欄位編號 3 的別名