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

Label probabilities for the CRF layer #38

Open
ashim95 opened this issue Feb 18, 2019 · 4 comments
Open

Label probabilities for the CRF layer #38

ashim95 opened this issue Feb 18, 2019 · 4 comments

Comments

@ashim95
Copy link

ashim95 commented Feb 18, 2019

Hi,
Thanks for sharing this great implementation.
I know it is possible to get the label probabilities using forward backward algorithm in CRFs. I am finding some difficulties in implementing/modifying the default CRF implementation in tensorflow. For calculation of the partition function, they have only used the forward (message passing) algorithm. Do you have any experience or ideas about how the forward-backward algorithm could be implemented in tf?

@guillaumegenthial
Copy link
Owner

Hi @ashim95,
This is a very good point, to compute the marginals (per token tag probability) you would indeed need to modify the tensorflow CRF implementation and use the Foward / Backward algorithm.
I did not do it, so I cannot give you estimate of the complexity of the task, but it seems like the Forward cell is already implemented in tensorflow.

For reference, the crfsuite uses the F/B approach to compute the marginals it seems https://github.com/chokkan/crfsuite/blob/dc5b6c7b726de90ca63cbf269e6476e18f1dd0d9/lib/crf/src/crf1d_context.c

If you're up to it, we could collaborate and open a PR in Tensorflow adding this support.

Let me know.

@agarwalishan
Copy link

I have requested this feature on issues page of tensorflow.
https://github.com/tensorflow/tensorflow/issues/42178
Please comment there and try to upvote it so that they can add this functionality.

@ashim95
Copy link
Author

ashim95 commented Aug 10, 2020

Hi @agarwalishan
I would suggest you look into pytorch based implementations of CRF. Many of these output marginal probabilities. Even if you can not find such an implementation on github, it should be much easier to implement in pytorch than tensorflow.

@agarwalishan
Copy link

Thanks for the reply but I want tensorflow implementation only.

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