Viterbi解码的cat操作中,tensor维度不一致
wangruicn opened this issue · comments
Traceback (most recent call last):
File "/home/rui/workspace/lattice-lstm/LatticeLSTM-master/main.py", line 459, in
train(data, save_model_dir, seg)
File "/home/rui/workspace/lattice-lstm/LatticeLSTM-master/main.py", line 286, in train
batch_charlen, batch_charrecover, batch_label, mask)
File "/home/rui/workspace/lattice-lstm/LatticeLSTM-master/model/bilstmcrf.py", line 32, in neg_log_likelihood_loss
scores, tag_seq = self.crf._viterbi_decode(outs, mask)
File "/home/rui/workspace/lattice-lstm/LatticeLSTM-master/model/crf.py", line 159, in _viterbi_decode
partition_history = torch.cat(partition_history,0).view(seq_len, batch_size,-1).transpose(1,0).contiguous() ## (batch_size, seq_len. tag_size)
RuntimeError: invalid argument 0: Tensors must have same number of dimensions: got 2 and 3 at /pytorch/torch/lib/THC/generic/THCTensorMath.cu:102
在对partition_history执行cat操作时,输入的tensor list维度不一致。
partition_history中,第一个tensor是 [batch_size, tag_size, 1]:
partition = inivalues[:, START_TAG, :].clone().view(batch_size, tag_size, 1) # bat_size * to_target_size
partition_history.append(partition)
而在for中,torch.max返回的partition形状为 [batch_size,tag_size],与第一个tensor维度不一致,导致cat操作失败
cur_values = cur_values + partition.contiguous().view(batch_size, tag_size, 1).expand(batch_size, tag_size, tag_size)
partition, cur_bp = torch.max(cur_values, 1)
partition_history.append(partition)
请问如何修改
You need to confirm your PyTorch version. Currently it only support the PyTorch 0.3.0
我的PyTorch版本是0.3.1。可能在0.3的子版本间有一些细微差别。
将
partition = inivalues[:, START_TAG, :].clone().view(batch_size, tag_size, 1)
修改为
partition = inivalues[:, START_TAG, :].clone().view(batch_size, tag_size)
后看起来似乎正常了
Great!
Thank u
i have changed 2 parts as u mentioned above. but it still cannot work as expected. oops.
现在到了pytorch0.4.1了=。=mul() received an invalid combination of arguments - got(list), but expected one of:"Tensor""Number"
我的PyTorch版本是0.3.1。可能在0.3的子版本间有一些细微差别。
将partition = inivalues[:, START_TAG, :].clone().view(batch_size, tag_size, 1)
修改为
partition = inivalues[:, START_TAG, :].clone().view(batch_size, tag_size)
后看起来似乎正常了
你好,我改了之后为什么还有这样的错?
RuntimeError: invalid argument 1: the number of sizes provided must be greater or equal to the number of dimensions in the tensor at /pytorch/torch/lib/THC/generic/THCTensor.c:326
现在到了pytorch0.4.1了=。=mul() received an invalid combination of arguments - got(list), but expected one of:"Tensor""Number"
请问你解决了这个问题
删掉crf.py的第75行、第96行、第143行里的参数“1”,就能正常运行了
删掉crf.py的第75行、第96行、第143行里的参数“1”,就能正常运行了
你好,最近刚开始研究这份代码,请问能加个联系方式请教交流下吗?
提前感谢!!我的qq是1607247596,谢谢!
删掉crf.py的第75行、第96行、第143行里的参数“1”,就能正常运行了
删掉后好像不起作用