2

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.

4

2 回答 2

1

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!

于 2019-02-11T17:10:58.827 回答
0

As @wpercy has mentioned in his comments, it is always a good idea to refer to the Github repository. I was boggling through this problem for the past 4 days. Just refer the Github repo, and check out the hierarchy yourself.

For example, for HiddenMarkovModel, search it in the 'Go to file' option in the Git GUI, and it showed that HiddenMarkovModel is actually a class in hidden_markov_model.py. So the correct import statement becomes from tensorflow_probability.python.distributions.hidden_markov_model import HiddenMarkovModel.

Similarly goes for other functions like from tensorflow_probability.python.distributions.categorical import Categorical

Check out https://github.com/tensorflow/probability/blob/master/tensorflow_probability/python/distributions/hidden_markov_model.py for further concerns.

于 2021-02-22T04:42:13.663 回答