kmkurn / pytorch-crf

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

CRF library does not work as expected #62

Closed vijay120 closed 2 years ago

vijay120 commented 4 years ago

I am using pytorch-crf to resolve tagging issues in NER, where the I-entity tag gets predicted after O (eg. O, I-person_name) or before B-entity tags (eg. I-person_name, B-person_name). Even after using pytorch-cr, I still am seeing decoded tags with the same errors as before.

I inspected the transitions, start_transitions and end_transition attributes of the CRF library (https://github.com/kmkurn/pytorch-crf/blob/master/torchcrf/__init__.py), and found that the library does not update any of these variables. They seem to be randomly initialized and then called for scoring, but these state transition variables are never updated.

Can you please provide a better understanding on why this is case, and probably provide some input on why these tag errors keep happening in-spite of using the CRF layer.

Thanks and Sincerely, Vijay Ramakrishnan

kmkurn commented 4 years ago

Hi, I tested it and the variables' gradients were computed properly, so they should be updated. Can you provide a simple example where the they are not?