尝试用另一张相同尺寸的张量遮盖张量,得到“索引1超出尺寸1的尺寸0的范围”

问题描述 投票:0回答:1
    attn_weights = F.softmax(self.attn(torch.cat((input, hidden_cat), 2)), dim=2)
    attn_weights[mask] = float('-inf')
    attn_applied = torch.bmm(attn_weights.transpose(0,1),encoder_outputs.transpose(0,1)).transpose(0,1)
    attn_output = torch.cat((input, attn_applied), 2)

因此,我试图将掩码中等于1的所有索引设置为负无穷大,但该行

attn_weights[mask] = float('-inf')

基普抛出此异常“索引1超出尺寸0的尺寸0的范围”,不能真正确定attn_weights和mask都发生了什么变化,即尺寸为1 x 2048 x 40。

pytorch mask attention-model
1个回答
0
投票

发现蒙版张量的dtype必须是torch.uint8或torch.bool,我将其设为torch.long

© www.soinside.com 2019 - 2024. All rights reserved.