kmkurn / pytorch-crf

(Linear-chain) Conditional random field in PyTorch.
https://pytorch-crf.readthedocs.io
MIT License
938 stars 151 forks source link

I meet a runtime error.. #6

Closed AdolHong closed 6 years ago

AdolHong commented 6 years ago

File "/Applications/bin/anaconda3/lib/python3.6/site-packages/torchcrf/init.py", line 113, in forward numerator = self._compute_joint_llh(emissions, tags, mask) File "/Applications/bin/anaconda3/lib/python3.6/site-packages/torchcrf/init.py", line 187, in _compute_joint_llh llh += emissions[i].gather(1, cur_tag.view(-1, 1)).squeeze(1) * mask[i] RuntimeError: invalid argument 1: input is not contiguous at /Users/soumith/code/builder/wheel/pytorch-src/torch/lib/TH/generic/THTensor.c:231

and I fix the bug under the suggestion by @apaszke , more details see link: https://discuss.pytorch.org/t/runtimeerror-input-is-not-contiguous/930

coveralls commented 6 years ago

Coverage Status

Coverage remained the same at 100.0% when pulling c6e5c4f4744538be01973f1435b78f235361bb9f on AdolHong:patch-1 into b200a38fbf628d08903ca2d4b6c3900cc1a27e7f on kmkurn:master.

AdolHong commented 6 years ago

I am sorry, maybe such change cannot fix my error..

because I found that my model cannot be optimized, loss become larger and larger ...

but I can not check out how I meet such error

kmkurn commented 6 years ago

@AdolHong Hi. Thank you for reporting!

It's weird that you have that "not contiguous" error. Could you please open an issue and post a minimal example to reproduce the error? As for the loss getting larger, note that pytorch-crf forward method computes the log likelihood, not the negative log likelihood, which is what you want as the loss. Are you sure you're already taking the negative? Again, this is probably better discussed in a separate issue. I am closing this PR for now.