Skip to content
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

Future of CRF layer #28

Open
ivyleavedtoadflax opened this issue Mar 31, 2020 · 8 comments
Open

Future of CRF layer #28

ivyleavedtoadflax opened this issue Mar 31, 2020 · 8 comments
Assignees

Comments

@ivyleavedtoadflax
Copy link
Contributor

ivyleavedtoadflax commented Mar 31, 2020

The CRF causes some problems, namely:

  • It depends on keras_contribs.CRF which:
    • Is not compatible (afaik) with tensorflow 2.0 (which is where the latest version of keras lives).
    • Prevents deep_reference_parser being published on pypi (it doesn't allow static dependencies)
  • Requires logic to rebuild the model prior to predictions in the same way that the model is built for training, rather than just loading the complete model from a file.

Replacing the CRF some other output would ameliorate these problems. Note that it is already possible to remove it right now by specifying output="softmax" rather than "crf" when building the model with deep_reference_parser.build_model(). A softmax output will almost certainly perform worse than a CRF though.

@ivyleavedtoadflax
Copy link
Contributor Author

Looks like CRF is available in tf 2.0 https://www.tensorflow.org/addons/api_docs/python/tfa/text/crf

@ivyleavedtoadflax
Copy link
Contributor Author

ivyleavedtoadflax commented Apr 2, 2020

Here's an example, but note that the CRF module is now in tfa.text.crf, not contrib: https://github.com/OpenNMT/OpenNMT-tf/blob/master/opennmt/models/sequence_tagger.py

@ivyleavedtoadflax
Copy link
Contributor Author

Ahh it is implemented for tf but not for tf.keras, though looks like it could be coming: tensorflow/addons#377 (review)

@ivyleavedtoadflax
Copy link
Contributor Author

This has been merged: tensorflow/addons#1999

@chaalic
Copy link

chaalic commented Dec 4, 2020

Hello, when using CRF layer with BI-LSTM for an NER task, i get the following error :
crf_loss *
crf, idx = y_pred._keras_history[:2]

AttributeError: 'Tensor' object has no attribute '_keras_history'

I get that it's a problem in the loss function, but I don't know how to get past it. Could you please help if you have found a solution ?

@ivyleavedtoadflax
Copy link
Contributor Author

Hi @chaalic is this code you are running outside of the deep reference parser?

@chaalic
Copy link

chaalic commented Dec 7, 2020

Yes it's for another task of named entity recognition, but the model i'm using is the same : bilstm with CRF.

@ivyleavedtoadflax
Copy link
Contributor Author

Ah OK. If you post some more of your code here we may be able to spot something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants