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

crf_losses.py as in keras_contrib? #2363

Closed
ahmad-alismail opened this issue Jan 23, 2021 · 9 comments
Closed

crf_losses.py as in keras_contrib? #2363

ahmad-alismail opened this issue Jan 23, 2021 · 9 comments

Comments

@ahmad-alismail
Copy link

Hello, I want to ask if you there is an alternative crf_losses.py as in keras_contrib in tensorflow_addons?

@Harsh188
Copy link
Contributor

Hi @afi1289,

I believe that we have a crf layer however we do not have an alternative for crf losses.

@ahmad-alismail
Copy link
Author

Thank you for your reply @Harsh188
Could you add crf_losses.py to losses, crf_accuracies.py to metrics? thats will help a lot (especially for beginners like me) by implementing BiLSTM-CRF models which initially implemented using keras-contrib.
Thank you in advance!

@kankajan814
Copy link

Hi @Harsh188 ,
I agree with @afi1289 , please add them

@bhack
Copy link
Contributor

bhack commented Jan 23, 2021

You can check https://github.com/xuxingya/tf2crf

I don't know if @xuxingya Is interested to contribute here.

@jonpsy
Copy link
Contributor

jonpsy commented Jan 24, 2021

If you won't mind, I'd like to take a stab at this. I've found a repo which implements CRF Loss.

CRF Loss: https://github.com/howl-anderson/tf_crf_layer/blob/master/tf_crf_layer/loss/crf_loss.py
CRF Accuracy: https://github.com/howl-anderson/tf_crf_layer/blob/master/tf_crf_layer/metrics/crf_accuracy.py

A bit of polish, and should make for a good PR, I suppose?

EDIT:
More resources: https://github.com/mtreviso/linear-chain-crf

@jonpsy
Copy link
Contributor

jonpsy commented Jan 27, 2021

Okay, I did some research on this. Thing is, the loss function doesn't solely depend on y_true and y_pred but also the internal variables. So, we can't use eager tensor for y_pred(since keras.contrib uses _keras_history to access internal variables, more at this issue: tensorflow/tensorflow#37119

@afi1289 Further investigations revealed that, you could add a custom wrapper around our CRF class for loss as is shown here, sample tutorial here.

@ashutosh1919
Copy link
Contributor

@afi1289 , can this be closed as part of #1999 ?

@howl-anderson
Copy link
Contributor

If you won't mind, I'd like to take a stab at this. I've found a repo which implements CRF Loss.

CRF Loss: https://github.com/howl-anderson/tf_crf_layer/blob/master/tf_crf_layer/loss/crf_loss.py
CRF Accuracy: https://github.com/howl-anderson/tf_crf_layer/blob/master/tf_crf_layer/metrics/crf_accuracy.py

A bit of polish, and should make for a good PR, I suppose?

I am the author of this repo, and I happy to bring back the CRF accuracy feature to TFA. I will submit a PR for it when it is ready.

constraints in the AllenNLP (https://docs.allennlp.org/main/api/modules/conditional_random_field/) is awesome feature too. It also exits in my repo (in a different branch). I hope I can bring it to the TFA in the future.

@seanpmorgan
Copy link
Member

TensorFlow Addons is transitioning to a minimal maintenance and release mode. New features will not be added to this repository. For more information, please see our public messaging on this decision:
TensorFlow Addons Wind Down

Please consider sending feature requests / contributions to other repositories in the TF community with a similar charters to TFA:
Keras
Keras-CV
Keras-NLP

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

No branches or pull requests

8 participants