pytorch nn.EmbeddingBag中的偏移是什么意思?

pytorch nn.EmbeddingBag中的偏移是什么意思?,pytorch,Pytorch,我知道偏移量有两个数字时的含义,但当有两个以上的数字时,它意味着什么,例如: weight = torch.FloatTensor([[1, 2, 3], [4, 5, 6]]) embedding_sum = nn.EmbeddingBag.from_pretrained(weight, mode='sum') print(list(embedding_sum.parameters())) input = torch.LongTensor([0,1]) offsets = torch.Long

我知道偏移量有两个数字时的含义,但当有两个以上的数字时,它意味着什么,例如:

weight = torch.FloatTensor([[1, 2, 3], [4, 5, 6]])
embedding_sum = nn.EmbeddingBag.from_pretrained(weight, mode='sum')
print(list(embedding_sum.parameters()))
input = torch.LongTensor([0,1])
offsets = torch.LongTensor([0,1,2,1])

print(embedding_sum(input, offsets))
结果是:

[Parameter containing:
tensor([[1., 2., 3.],
        [4., 5., 6.]])]
tensor([[1., 2., 3.],
        [4., 5., 6.],
        [0., 0., 0.],
        [0., 0., 0.]])
谁能帮我?

如图所示

它使用,这将
偏移量
参数解释为

偏移量(长传感器,可选)–仅在输入为1D时使用。偏移量确定输入中每个行李(序列)的起始索引位置

在:

如果输入为形状(N)的1D,则将其视为多个行李(序列)的串联。偏移量要求为1D张量,包含输入中每个行李的起始索引位置因此,对于形状(B)的偏移,输入将被视为具有B个袋子。空袋子(即,具有0长度)将具有由零填充的返回向量

最后一条语句(“空包(即长度为0)将返回由零填充的向量。”)解释了结果张量中的零向量

return F.embedding(
    input, self.weight, self.padding_idx, self.max_norm,
    self.norm_type, self.scale_grad_by_freq, self.sparse)