-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Handling unbalanced datasets in the CRF tagger #4619
Comments
Let me add to this: In case you develop a general way of giving class weights to |
@matt-gardner Thanks for the feedback! @dirkgr I believe it is possible to create a task for this problem. Do you have any idea how we can add weights? @matt-gardner In case there is any tip on how we can add this weight without changing the official code, I await feedback! |
I did a quick Google of this problem, and unless I missed something, no major library has weighted CRFs. That tells me that a) it would be very cool if AllenNLP did, and b) it's not easy. I did find this paper referenced a few times: https://perso.uclouvain.be/michel.verleysen/papers/ieeetbe12gdl.pdf They give the math, but not code, on how to do it. I'd recommend copying the existing |
I glanced over the paper and it seems relatively straight-forward, but it would definitely take some refactoring of the But this definitely interests me, so if no one else decides to work on it, I might eventually do it. |
I implemented and experimentally compared three weighting strategies for CRF in AllenNLP. One of the strategies was the one proposed by Lannoy et al. (this paper was mentioned above by @dirkgr). The other strategies are two straightforward approaches based on weighting emission and/or transition scores. I performed these experiments because I wasn't convinced by the theoretical basis of Lannoy et al.'s method. And the experimental results (although the setup was quite limited) corroborate my concerns with this method. The results show that Lannoy et al.'s approach presents a kind of inconsistent behaviour, which makes the method hard to be used in practice in my opinion. If someone is willing to review a PR with a weighted CRF method, I can submit one soon. I just need some feedback about which strategy is better or whether it would be interesting to have the three strategies available. As mentioned in the end of the report, I think the best approach for AllenNLP would be the emission-based one. It's the simplest method among the three and presents a nice behaviour. In my current implementation (allennlp and allennlp-model), I included a I also included a new version of the |
Sounds like we should have two PRs: One with the improved |
Thank you for your comment, @dirkgr ! It is definitely not a huge amount of code. I will polish the code (there are some unnecessary duplicated code chunks) and submit the two PRs. |
I'm using an unbalanced Corpus NER and I would like to add weights to the entities in the training step via
nn.CrossEntropyLoss
, I would like to know which .py file can I call my own lib and pass the weights to the model ???Some tutorials point to:
allennlp/allennlp/nn/util.py
Line 628 in 052353e
Version Allennlp: 0.9.0
Script:
The text was updated successfully, but these errors were encountered: