【发布时间】:2020-10-25 17:45:19
【问题描述】:
我想在pytorch中使用torch.nn.utils.rnn.pack_padded_sequence来解决这个问题,但是我不知道当torch变量在最后一维的大小不同时如何获取?
torch.nn.utils.rnn.pack_padded_sequence(input, lengths, batch_first=False, enforce_sorted=True)
input can be of size T x B x * where T is the length of the longest sequence (equal to lengths[0]), B is the batch size, and * is any number of dimensions (including 0)
如果我运行以下代码,我会得到错误。
x_torch = torch.from_numpy(np.ones((2, 3)))
y_torch = torch.from_numpy(np.ones((2, 5)))
ans_torch = torch.cat([x_torch, y_torch], dim = 0)
# ouput
RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 0. Got 3 and 5 in dimension 1 at c:\a\w\1\s\windows\pytorch\aten\src\th\generic/THTensorMoreMath.cpp:1333
救命!
【问题讨论】:
标签: python nlp pytorch data-mining torch