Closed r0mainK closed 2 years ago
Hi, thank you for the PR! Really appreciate it. However my hands are a bit full at the moment, and this is not a small PR, so it might take a while before I can review. But from skimming the code:
reset_parameters
to keep it aligned with PyTorch's convention where each layer has that method (which is still the case last time I checked)Thanks again for the PR!
No problem, I'm not in a rush :)
I'll remove both commits, indeed I hadn't seen that the reset_parameters
was idiomatic, I had checked only the superclass nn.Module
but not the actual instances !
Hey !
So first off thanks for the repo, it really helped having a tested CRF in pytorch. I spent the past couple cycles improving your code, and thought I would PR. Here is the list of changes I PR ed here (high level, we can talk of each commit during the review):
reset_parameters
because it is like creating a new layer, I removed_compute_score
and_compute_normalize
to have only one loop, and because separating thr code made it harder to understand, and I removed_viterbi_decode
because it was uselessValueError
andassert
were competing for validating inputs, but there was a ton of redundance and ValueError were more informative, so I removed all the asserts. I also added a check on the mask, and moved some code around for efficiencyThere is also some minor changes, like adding pytorch to the setup.py. I think the commits are well split so it should be no problem to review. I tested on my computer with pytorch 1.0, 1.1 and 1.4, all work.
PS: I tried to keep your coding style as much as possible, but I would recommend removing the line comments. Your code is good enough so that is impedes comprehension in my opinion.
EDIT: Added optimization of numerator computation