out = torch.matmul(alpha,V)
报错:RuntimeError: both arguments to matmul need to be at least 1D, but they are 0D and 1D
原因:print alpha.shape, 结果为 torch.Size([]), 是一个
0d
tensor。
Matrix multiplication 需要 1d
tensor。
解决: unsqueeze输入使其维度匹配:
out =torch.matmul(alpha.unsqueeze(dim=0).permute(1,0), V.unsqueeze(dim=0))