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

Another implementation of CRF #4646

Closed
wants to merge 9 commits into from

Conversation

linxihui
Copy link
Contributor

@linxihui linxihui commented Dec 8, 2016

This implementation has two modes for optimization:
1. (join mode) optimized by maximizing join likelihood, which is optimal in theory of statistics.
Note that in this case, CRF must be the output/last layer.
2. (marginal mode) return marginal probabilities on each time step and optimized via composite
likelihood (product of marginal likelihood), i.e., using categorical_crossentropy loss.
Note that in this case, CRF can be either the last/output layer or an intermediate layer (not clear now whether there is a valuable application).

For prediction (test phrase), one can choose either Viterbi best path (class indices) or marginal
probabilities if probabilities are needed.

This implementation also supports masking, specifying activation functions (or more accurate, restrict range of chain energy) and accepts either onehot or sparse target.

NOTE: this PR requires PR #4899

@EderSantana
Copy link
Contributor

would you please add unit test and an example? New users would benefit with a good use case to know this layer exists. It would also help to know how to properly apply it.

@linxihui
Copy link
Contributor Author

linxihui commented Dec 8, 2016

@EderSantana yup, will do it soon. I made this just because there is another PR (#4621) for CRF, and I think it may be valuable to compare.

@linxihui linxihui force-pushed the implement-crf branch 5 times, most recently from 80c37b4 to e640e12 Compare January 3, 2017 18:23
@linxihui
Copy link
Contributor Author

linxihui commented Jan 4, 2017

@EderSantana @fchollet Sorry for the delay. Unit tests and an example is added. The check fail because of some other tests test_optimizers.py. Can you take a look? Or should I just change the threshold in the accuracy checking? Also, I find that quite a few other tests in the master branch fail, mostly convolution layers.

@EderSantana
Copy link
Contributor

the failure is only in theano under python 2.7 and unrelated to this current PR
@fchollet did anything change there recently?

@linxihui
Copy link
Contributor Author

linxihui commented Jan 5, 2017

@EderSantana it's weird. Now it passes tests. Though there is a seed setting in test_optimizers.py, some other unexpected randomness might exist.


# use learn_mode = 'join', test_mode = 'viterbi'
crf = CRF(10)
model.add(crf(Embed))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @linxihui, 'Embed' seems to be undefined.
I think this line should be model.add(crf) (followed by test_crf.py#L34)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@himkt You're right. Thanks for pointing out. Now fixed.

@fchollet
Copy link
Collaborator

Closing outdated PR. If you still care about the content of the PR, please submit a new PR to master, updated for the Keras 2.0 API.

@fchollet fchollet closed this Mar 15, 2017
@himkt
Copy link

himkt commented Mar 17, 2017

@linxihui Is there any plan about this PR in future ? I think this PR is great work (I wanna use CRF!). I want to help if there are something I can support.

@linxihui linxihui mentioned this pull request Apr 12, 2017
@linxihui
Copy link
Contributor Author

@himkt See #6226

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

Successfully merging this pull request may close these issues.

4 participants