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

Really need example or docs to implement CRF layer in Tensorflow Keras. #2237

Closed
ngoquanghuy99 opened this issue Nov 12, 2020 · 6 comments
Closed
Labels

Comments

@ngoquanghuy99
Copy link

ngoquanghuy99 commented Nov 12, 2020

I'm confused about lots of PRs or Issues and I haven't got the solution yet!
Please provide a clear doc or example to deal with it or someone help me to add CRF layer to this BiLSTM network, i'd appreciate it!

input = Input(shape=(max_length,))
word_embedding_size = 100
model = Embedding(input_dim=vocab_size, output_dim=word_embedding_size, input_length=max_length)(input)
model = Bidirectional(LSTM(units=word_embedding_size, 
                           return_sequences=True, 
                           dropout=0.5, 
                           recurrent_dropout=0.5, 
                           kernel_initializer=k.initializers.he_normal()))(model)
model = LSTM(units=word_embedding_size * 2, 
             return_sequences=True, 
             dropout=0.5, 
             recurrent_dropout=0.5, 
             kernel_initializer=k.initializers.he_normal())(model)
model = TimeDistributed(Dense(tag_size, activation="relu"))(model)
@bhack bhack added the crf label Nov 12, 2020
@andreacimino
Copy link

I have been struggling too, it would be nice to have a minimal example.
With the keras-contrib package I was able to make it work without any issues.

@ngoquanghuy99
Copy link
Author

I have been struggling too, it would be nice to have a minimal example.
With the keras-contrib package I was able to make it work without any issues.

I'm not able to add CRF layer by using keras-contrib package (since it was deprecated), though i solved the problem!

@andreacimino
Copy link

I have been struggling too, it would be nice to have a minimal example.
With the keras-contrib package I was able to make it work without any issues.

I'm not able to add CRF layer by using keras-contrib package (since it was deprecated), though i solved the problem!

Hello,

I tried to follow the the tests provided in the keras addons package, and did not manage to add the layer.
Could you please tell us why you closed the issue?
Could you please post (as mentioned) a very basic way to add a CRF layer to a LSTM (as in the first comment) ? The documentation and the examples are lacking this information.

Thank you.

@ngoquanghuy99
Copy link
Author

I have been struggling too, it would be nice to have a minimal example.
With the keras-contrib package I was able to make it work without any issues.

I'm not able to add CRF layer by using keras-contrib package (since it was deprecated), though i solved the problem!

Hello,

I tried to follow the the tests provided in the keras addons package, and did not manage to add the layer.
Could you please tell us why you closed the issue?
Could you please post (as mentioned) a very basic way to add a CRF layer to a LSTM (as in the first comment) ? The documentation and the examples are lacking this information.

Thank you.

Sorry, i was thinking you'd solve the problem by using 'keras-contrib' package.
As far as i know, it was deprecated last year, here. They moved it to tensorflow/addons then removed it later. Now everyone sends bunch of pull requests (absolutely confusing).
By the way, my solution is to use tf2crf
or this way #1769

@ngoquanghuy99 ngoquanghuy99 reopened this Nov 15, 2020
@Harsh188
Copy link
Contributor

@ngoquanghuy99 If you are interested in helping create a CRF tutorial for addons please consider checking out #337. I've been unsuccessful in implementing CRF for a minimal tutorial since I'm fairly inexperienced with it.

@luozhouyang
Copy link

hey guys, have a look to luozhouyang/keras-crf, which is a more elegant and convenient CRF built on tensorflow-addons.

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

No branches or pull requests

5 participants