jiesutd / NCRFpp

NCRF++, a Neural Sequence Labeling Toolkit. Easy use to any sequence labeling tasks (e.g. NER, POS, Segmentation). It includes character LSTM/CNN, word LSTM/CNN and softmax/CRF components.
Apache License 2.0
1.89k stars 446 forks source link

RuntimeError: invalid argument 0: Tensors must have same number of dimensions: got 3 and 2 #3

Closed ghost closed 6 years ago

ghost commented 6 years ago

Hi,Thank you for this perfect code,and I have learned a lot from this code.But when I run this code,I get one problem : Traceback (most recent call last): File "main.py", line 438, in <module> train(data, save_model_dir, seg) File "main.py", line 265, in train batch_charrecover, batch_label, mask) File "/Users/fengxiachong/Desktop/PyTorchSeqLabel-master/model/bilstmcrf.py", line 33, in neg_log_likelihood_loss scores, tag_seq = self.crf._viterbi_decode(outs, mask) File "/Users/fengxiachong/Desktop/PyTorchSeqLabel-master/model/crf.py", line 162, in _viterbi_decode partition_history = torch.cat(partition_history).view(seq_len, batch_size, -1).transpose(1, RuntimeError: invalid argument 0: Tensors must have same number of dimensions: got 3 and 2 at /Users/soumith/minicondabuild3/conda-bld/pytorch_1518371252923/work/torch/lib/TH/generic/THTensorMath.c:2888 could you please help me?

jiesutd commented 6 years ago

Hi @charleyFeng , I am not sure about where the problem is based on this simple error message. If you use the correct data input, I guess the problem may be caused by the version of PyTorch. Please make sure you use the PyTorch 0.3.0

If you are using right version, then further debug is needed.

ghost commented 6 years ago

My torch version is 0.3.1.post2.

jiesutd commented 6 years ago

Then you may seperate the error sentence into several lines to see where does this error message come from (I guess it comes from function cat or view). Then for the error function, you may check its input shape and output shape to see if they are compatible

ghost commented 6 years ago

Ok,Thank you,I will check what you have mentioned,and if any result,I will post here.

ghost commented 6 years ago

I just add one line partition = partition.view(partition.size()[0], partition.size()[1], 1)in function _viterbi_decode in the for loop,now it can run,thank you very much.

jiesutd commented 6 years ago

cool!

Shuailong commented 6 years ago

partition = partition.unsqueeze(-1) works also.

nthoangcute commented 6 years ago

partition = partition.unsqueeze(-1) works also.

Your method is not working.

GaYounKoh commented 2 years ago

Hi sir, I'm student learning ML/DL. Today, I got a same error msg from my torch code. Could you plz tell me what's the code file belongs to this issue?