-
Notifications
You must be signed in to change notification settings - Fork 611
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Conditional Random Field (CRF) layer #377
Add Conditional Random Field (CRF) layer #377
Conversation
* Rename crf_ops* -> crf* * The RNN cells inherit `AbstractRNNCell` instead of `Layer` * Remove used `training` variable * Add docstring for RNN Cells
All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the ℹ️ Googlers: Go here for more info. |
cc639b3
to
d8d98a8
Compare
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
@gabrieldemarmiesse I am working on using the |
Thanks a lot @howl-anderson I hope it helped. |
Any update here? |
@albertnanda I encountered some problems during the implementation and are trying to solve them. |
I moved some code around in this PR, and I made #1363 which has less hacks. @howl-anderson , @Squadrick, please take a look when you can. @howl-anderson , I've put you as author of the first commit. |
While The @gabrieldemarmiesse Your approach seems to have introduced hacks that lead to multiple impacts on the API user: two models to track and fake targets to input. From an end user perspective, I would be hesitant to leave this to be handled externally. |
@bodak we can't use private APIs in code used by users. If at the next release, this attribute disapears, we get an attribute error and we have to redo all the work of this pull request to find another pattern that works for CRF. Or worst case scenario, the behavior changes silently (for example tensorflow decide to enforce that we can't use tensors or variables not declared in the signature in the loss), and all users get wrong numerical results/horrible error messages and we spend a lot of time understanding what is going on. To in the end fall back to #1363 because it's the only way that is garanteed to last since we don't use private APIs. I agree with you that it leads to more confusing code for end users, but they'll have more flexibility and stability. For example, in the implementation proposed in #1363, the user is not forced to have the CRF layer be the last layer of the model. If users don't like the pattern of having two models or passing the labels as inputs, they're free to use only one model and do a custom training loop. Making a custom training loop is getting easier and easier nowadays. |
Hi, huge thanks to you for making this effort and building a CRF layer for tensorflow 2. For my application I require the probabilities or confidences for the class predictions in order to conduct a majority vote. As far as I understand, if I use the variable but as expected this doubled the prediction time. |
Hi @mhartig, output the probabilities or confidences for the prediction is a good feature. After the CRF layer is merged, I can implement it. |
I have tried to modify the output of the CRF layer myself, unfortunately I'm not very familiar with the underlying structure of tf.keras and the context in which the class methods are called. The output shape seems to be restricted in more than one place, but it is very hard to see exactly where the expected output shape needs to be changed in order to return for example a tensor of shape (batch_size, sequence length, number_of_classes + 1) and dtype float32 instead of a tensor of shape (batch_size, sequence_length) and dtype int32. |
…ature/crf_layers
…into feature/crf_layers
@mhartig Since this CRF layer implement is not merged, so I am not planning to implement this feature now. But if I get enough free time, I willing to help you with this. |
Any update? |
@NLP-ZY waiting for tensorflow/tensorflow#37818 |
any example of how to implement this crf layer? |
@soumayan Currently, it's waiting for other PR. Doc will be added to the repo when it's ready. |
@howl-anderson when I'm installing tensorflow_addons package from your github repository using !pip install git+https://github.com/howl-anderson/addons.git I'm getting error-- |
@soumayan You should download it and built it to a wheel package. https://github.com/tensorflow/addons has docs for how to build from source. |
excuse me,how to get accuray while training?I can‘t find crf_accuracy.py @howl-anderson |
@zhoushaoxiang I removed it for more focus on CRF itself. I am planning to add metric functions (just like the ACC function ) after the CRF implement merged. |
@howl-anderson , I'll close this pull request in favor of #1733 which has an API as clean as this one, is flexible and can be serialized, the whole package without using any private api. |
related to: #314 #22
depend on: #314
What's include
How to use it
The document is coming soon.
Progress
[x] Layer class for CRF
[x] Test cases
Limitation
Roadmap (next version)
constraints
: an optional list of allowed transitions (from_tag_id, to_tag_id). Learned from AllenNLP