[error] RuntimeError: Expected object of scalar type Byte but got scalar type Int for sequence elmen

错误:
RuntimeError: Expected object of scalar type Byte but got scalar type Int for sequence elment 1 in sequence argument at position #1 'tensors'

 

出错位置:

valid = 1 - src.data.eq(padding_idx)

pad = Variable(torch.zeros(max_doc_len - doc_len, pad_dim, dtype=torch.int))

sent_input.append(torch.cat([valid, pad]).unsqueeze(0))          # (1,max_len,2*H) / [1, 100]

 

第一次尝试:

pad = Variable(torch.zeros(max_doc_len - doc_len, pad_dim, dtype=torch.byte))

不成功,因为没有这个数据类型

 

第二次尝试:

pad = Variable(torch.zeros(max_doc_len - doc_len, pad_dim, dtype=torch.uint8))

成功

 

同理,若遇到错误

RuntimeError: Expected object of scalar type Lo n g but got scalar type Int for sequence elment 1 in sequence argument at position #1 'tensors'

 

修改:

dtype=torch.int64(代表long)

 

参考链接:

https://www.jiqizhixin.com/articles/2019-06-18-10

https://www.wandouip.com/t5i239932/

最新回复(0)
/jishurgK_2Ba6OszroJshOi1FviD7Rkl98AyoX8QNoqUQ_3D_3D4795243
8 简首页