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

Implement Conditional Random Field #22

Closed
seanpmorgan opened this issue Jan 18, 2019 · 26 comments · Fixed by #314
Closed

Implement Conditional Random Field #22

seanpmorgan opened this issue Jan 18, 2019 · 26 comments · Fixed by #314
Assignees
Labels
help wanted Needs help as a contribution text

Comments

@seanpmorgan
Copy link
Member

Per the RFC, we need to move CRF from contrib to addons:

This will involve moving the code and modifying test cases to run in TF2.

@a6802739
Copy link

@seanpmorgan, may I give some help on this?

@seanpmorgan
Copy link
Member Author

Absolutely! Please let us know if you run into any issues. As noted in the other issue, one thing to note is that the RNN cells are unified under Keras RNN in TF2.

@a6802739
Copy link

@seanpmorgan, thanks for your help, I will ping you if I met some issues.

@seanpmorgan seanpmorgan removed the crf label Mar 21, 2019
@a6802739
Copy link

@seanpmorgan, Sorry for late interaction. So what I should do now is move CRF from contrib to the directory addons/tensorflow_addons, and change the corresponding test in tensorflow, right?

@seanpmorgan
Copy link
Member Author

Hmmm move the code and change the tests/code in addons to match the TF2 syntax would be how I would word that.

@a6802739
Copy link

a6802739 commented Mar 31, 2019

@seanpmorgan, Thanks for you help, and could you please give me some PR reference that I could follow?

As my understanding, I should move the code to addons and add crf_test.py within adding/crf and guarantee the unit test style match the TF2 syntax, for example using test.TestCase and add py_test in BUILD file, right?

And how I should deal with the function defined in contrib/crf, should I use class to implement a wrapper or just move the code directly?

I'm appreciate for your kind comments.

@seanpmorgan
Copy link
Member Author

Hi @a6802739

As my understanding, I should move the code to addons and add crf_test.py within adding/crf and guarantee the unit test style match the TF2 syntax, for example using test.TestCase and add py_test in BUILD file, right?

Yes that is correct.

And how I should deal with the function defined in contrib/crf, should I use class to implement a wrapper or just move the code directly?

This is where I'm confused. You'll need to move the code from contrib, but then modify it to use the unifed RNN class in TF2. This will come with some changes to the code so that it runs correctly. To be honest, this is not the most straightforward of all the issues we need help with. It might be easier to move something that already has an example PR we can point you to. For example moving an optimizer and then you can match how LazyAdam was moved.

@a6802739
Copy link

a6802739 commented Apr 3, 2019

@seanpmorgan , Thanks for you kind help, I will have a try then. Could you please point me the example PR and the ongoing issue about optimizer.

@armando-fandango armando-fandango self-assigned this Apr 5, 2019
@HuggingLLM
Copy link

How is it going on about this issue? I want to use tf.keras(2.0), but there is no CRF Layer, so that I can only use keras & keras_contrib.

@seanpmorgan
Copy link
Member Author

Hi @NLP-ZY thanks for bumping this. CRF is a highly requested feature and we'll make sure it's implemented prior to a TF2 release.

Relevant issue: tensorflow/tensorflow#26167

@Squadrick
Copy link
Member

@seanpmorgan I'll work on this.

@Squadrick Squadrick self-assigned this Jun 11, 2019
@howl-anderson
Copy link
Contributor

If need help, I familiar with CRF and I can help with the coding and testing.

@seanpmorgan
Copy link
Member Author

IMO this should go under tfa.text. Any objections to that?

@Squadrick
Copy link
Member

Yup, I was thinking the same.

@Squadrick Squadrick added the text label Jun 11, 2019
@HuggingLLM
Copy link

@seanpmorgan Thanks for your reply!

@Squadrick
Copy link
Member

@howl-anderson Some of my tests are failing because they're off from the actual values. I have my code here. I'll take a look at it later today, but if you want you could take a crack at it.

@howl-anderson
Copy link
Contributor

@Squadrick Sure

@seanpmorgan
Copy link
Member Author

@invencode @soloice @nlp-zy We're having internal discussion about how we want to expose the CRF functionality in Addons. Would it be sufficient to only expose it as a Keras Layer, or do you have use cases were the lower level op calls would be used?

@HuggingLLM
Copy link

@seanpmorgan The CRF layer in keras is good enough for me in the moment.

@howl-anderson
Copy link
Contributor

The CRF layer of the tf.addons I'm working on is basically ready, but the code still needs more testing to ensure correctness and robustness. Will be submitted in the next one or two weeks.

@seanpmorgan
Copy link
Member Author

@howl-anderson Does your implementation use the code in #314 or is it standalone? Would you mind submitting a WIP PR so we can better plan?

@howl-anderson
Copy link
Contributor

@seanpmorgan The current implementation of my CRF layer use functions from #314 . I will submit it as a WIP PR soon. I will keep you informed.

@howl-anderson
Copy link
Contributor

@seanpmorgan For keep you informed, WIP PR #377 is for the CRF layer.

@napsternxg
Copy link
Contributor

IMO this should go under tfa.text. Any objections to that?

Sorry to restart the discussion on this. Thanks for including CRF in TF 2.0 addons. However, it should be noted that CRF is a general methodology for any type of sequence tagging task where the prediction has to be made on each item of the sequence. This includes videos, audio, text, and even graph traversals.
I don't think putting it under text is the best approach.

@foxik
Copy link

foxik commented Oct 17, 2019

Maybe adding it directly to tfa.layers? But personally I do not care if it is tfa.layers or tfa.text, given that span labeling of text seems to be one of the most common application of linear CRF.

@napsternxg
Copy link
Contributor

I think tfa.layers is a better place. I don't have an issue either, just thought that in the earlier contrib module it was not under text, hence, this change might cause discovery bias towards users in non-text domain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Needs help as a contribution text
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants