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。
发现蒙版张量的dtype必须是torch.uint8或torch.bool,我将其设为torch.long