How to turn list of varying length tensor into a tensor
It seems that I cannot create tensor with varying length on any dimension.
Shihan_su
smth
These two functions help you pack (already) padded sequences and pad (already) packed sequences. I think the purpose is not to help you pad sequences, but to save some spaces. Check out the following example:
ZeweiChu
apaszke
ecolss
smth
As illustrated in the release notes, PackedSequence holds data and a list of sequence sizes of a packed sequence batch. Then why would we have to first pad the seq to equal length manually and then pass it to pack_padded func to generate this PackedSequence object? Wouldn’t it be easier to just construct the object directly from the original seq without manual padding?
ecolss
lgelderloos
I’m not following up on this, but I agree with you on this.
ecolss
nilbot
For anyone wondering if PyTorch has created a function that takes a list of tensors and pads them to be the same length, the following function does the trick: Example: <SCODE>>>> import torch
>>> l = [torch.Tensor([1., 2.]), torch.Tensor([3.])]
>>> torch.nn.utils.rnn.pad_sequence(l, batch_first=True, padding_value=0)
tensor([[1., 2.],
        [3., 0.]])
<ECODE>
RylanSchaeffer