MarvinBertin / HiddenMarkovModel_TensorFlow

TensorFlow: Viterbi, Forward-Backward and Baum Welch with a Hidden Markov Model (HMM)
133 stars 50 forks source link

running forward backward AttributeError #1

Open iteimouri opened 7 years ago

iteimouri commented 7 years ago

It seems in running forward backward algorithm there are errors:

`AttributeError Traceback (most recent call last)

in () 2 model = HiddenMarkovModel_FB(trans, emi, p0) 3 ----> 4 results = model.run_forward_backward(obs_seq) 5 result_list = ["Forward", "Backward", "Posterior"] 6 /Users/xxx/Desktop/hmm/forward_bakward.pyc in run_forward_backward(self, obs_seq) 207 with tf.Session() as sess: 208 --> 209 forward, backward, posterior = self.forward_backward(obs_seq) 210 sess.run(tf.initialize_all_variables()) 211 return sess.run([forward, backward, posterior]) /Users/xxx/Desktop/hmm/forward_bakward.pyc in forward_backward(self, obs_seq) 188 189 # forward belief propagation --> 190 self._forward(obs_prob_seq) 191 192 # backward belief propagation /Users/xxx/Desktop/hmm/forward_bakward.pyc in _forward(self, obs_prob_seq) 119 prior_prob = tf.matmul(prev_prob, self.T) 120 # forward belief propagation --> 121 forward_score = tf.mul(prior_prob, tf.cast(obs_prob_seq[step, :], tf.float64)) 122 # Normalize score into a probability 123 forward_prob = tf.reshape(forward_score / tf.reduce_sum(forward_score), [-1]) AttributeError: 'module' object has no attribute 'mul'`
MarvinBertin commented 7 years ago

You're using the new version of TensorFlow. tf.mul was replaced to tf.multiply

iteimouri commented 7 years ago

I see, what version of TensorFlow did you used for this code? Because there are other errors occurring presumably due to the difference.

Rahza commented 7 years ago

@itei In case you couldn't solve your problem by now: v0.11 should work - I personally however just manually updated the code for newer versions, it's only function names and argument order that has changed. You may also try to use this upgrade script: https://www.tensorflow.org/install/migration#how_to_upgrade

iteimouri commented 7 years ago

Thanks @Rahza. Is there any chance you can upload the new version? That would be highly appreciated.

Rahza commented 7 years ago

@itei I have created a new fork: https://github.com/Rahza/HiddenMarkovModel_TensorFlow

All the code from the ipynb seems to work with the updated code. Note however that I did not extensively test it as unfortunately the library isn't suitable for my use case

kesmarag commented 7 years ago

@itei if you are interested to HMMs with Gaussian emission distributions, I have just released an implementation: https://github.com/kesmarag/gaussian-hmm-tf

iteimouri commented 7 years ago

Thanks @Rahza for the useful upgrade, now it works just fine.

iteimouri commented 7 years ago

Thanks @kesmarag for your implementation :)