addons icon indicating copy to clipboard operation
addons copied to clipboard

Capability to get probabilities for each tag in crf_decode

Open agarwalishan opened this issue 4 years ago • 5 comments

Describe the feature and the current behavior/state. I am talking about this specific repository. https://www.tensorflow.org/addons/api_docs/python/tfa/text/crf_decode For now crf_decode function returns the tag indices with highest probability and a score for the whole sequence. But the crf_decode do not returns the probabilities for every tag for each token in sequence like we get in softmax. So I request to please add this capability because probabilities of tags help us know the confidence score and many more things.

Relevant information

  • Are you willing to contribute it (yes/no): yes
  • Are you willing to maintain it going forward? (yes/no): no
  • Is there a relevant academic paper? (if so, where): no
  • Is there already an implementation in another framework? (if so, where): I guess in pytorch
  • Was it part of tf.contrib? (if so, where): yes, tf.contrib.crf.crf_decode

Which API type would this fall under (layer, metric, optimizer, etc.) It will fall under 'text'

Who will benefit with this feature? I believe many developers around the globe are looking for this feature.

Any other info. Confidence scores for any model are very important for further decisions and modifications.

agarwalishan avatar Aug 10 '20 12:08 agarwalishan

Hi, we implemented the probability for each tag here: https://github.com/RasaHQ/rasa/blob/master/rasa/utils/tensorflow/crf.py

Ghostvv avatar Jan 14 '21 13:01 Ghostvv

Regarding to returns the probabilities for every tag for each token in sequence. Do you means you want the emission probability of each words?

if so, I think you can use tfa.layers.CRF to get the potentials (as logits).

In following sample code:

layer = tfa.layers.CRF(4, use_boundary=False)
decoded_sequence, potentials, sequence_length, chain_kernel = layer(inputs)

potentials is the thing you want.

howl-anderson avatar Aug 28 '21 16:08 howl-anderson

yeah, but potentials are not probabilities. CRF also takes into account transition probabilities

Ghostvv avatar Oct 18 '21 08:10 Ghostvv

there is an open PR for that: https://github.com/tensorflow/addons/pull/1935

Ghostvv avatar Oct 18 '21 08:10 Ghostvv

@Ghostvv Thank you for the information you provided. I will do some investigation on the PR. Then, hopefully, do some work based on that.

howl-anderson avatar Oct 18 '21 08:10 howl-anderson

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

seanpmorgan avatar Mar 01 '23 04:03 seanpmorgan