why do we “pack” the sequences in pytorch?

后端 未结 5 1217
名媛妹妹
名媛妹妹 2020-11-30 17:21

I was trying to replicate How to use packing for variable-length sequence inputs for rnn but I guess I first need to understand why we need to \"pack\" the sequence.

<
5条回答
  •  青春惊慌失措
    2020-11-30 18:02

    Adding to Umang's answer, I found this important to note.

    The first item in the returned tuple of pack_padded_sequence is a data (tensor)- tensor containing packed sequence. The second item is a tensor of integers holding information about the batch size at each sequence step.

    What's important here though is the second item (Batch sizes) represents the number of elements at each sequence step in the batch, not the varying sequence lengths passed to pack_padded_sequence.

    For instance, given data abc and x the :class:PackedSequence would contain data axbc with batch_sizes=[2,1,1].

提交回复
热议问题