pythontensorflowhidden-markov-modelstensorflow-probability

How to use HiddenMarkovModel from tensorflow probability?


I am following this tutorial:

https://github.com/tensorflow/probability/blob/master/tensorflow_probability/examples/jupyter_notebooks/Multiple_changepoint_detection_and_Bayesian_model_selection.ipynb

in it it has code that references and uses a HiddenMarkovModel class in tfp. the code that does this in the tutorial is here:

import tensorflow_probability as tfp
from tensorflow_probability import distributions as tfd

hmm = tfd.HiddenMarkovModel(
  initial_distribution=tfd.Categorical(
      logits=batch_initial_state_logits),
  transition_distribution=tfd.Categorical(probs=batch_transition_probs),
  observation_distribution=tfd.Poisson(trainable_rates),
  num_steps=len(observed_counts))

However when I get to this line I get the following error:

AttributeError: module 'tensorflow_probability.python.distributions' has no attribute 'HiddenMarkovModel'

Checking the documentation for distributions in tfp here:

https://www.tensorflow.org/probability/api_docs/python/tfp/distributions

I see there is no class called HiddenMarkovModel so I am wondering what I am doing wrong to be unable to get this class that the tutorial uses? This is an official tutorial so i can't imagine it is just "wrong" and no HiddenMarkovModel class exists.


Solution

  • The current stable version, 0.5, was released a while ago. The API docs match that version. We are in the process of preparing 0.6 for release, which has HMM. In the mean time you can install tfp-nightly instead, to get the latest goodness. You should then be sure to uninstall the one you have (pip uninstall tensorflow-probability) and similarly install tf-nightly in place of TensorFlow stable. HTH! Thanks for using tfp!