codekansas / codekansas.github.io

:computer: Personal blog
https://ben.bolte.cc/
MIT License
3 stars 1 forks source link

viterbi #4

Open utterances-bot opened 3 years ago

utterances-bot commented 3 years ago

Coding the Viterbi Algorithm in Numpy | Ben Bolte's Blog

https://ben.bolte.cc/viterbi

afogarty85 commented 3 years ago

Thanks for your work and time spent here! I tried to run your code but it seems to fail here:

---> 25     mu_new = max_vals * emission_probs[:, observed_state]
operands could not be broadcast together with shapes (2,) (3,) 
codekansas commented 3 years ago

@afogarty85 yep, seems that

max_seq, seq_prob = viterbi(
    transition_probs,
    emission_probs,
    init_hidden_probs,
    observed_states,
)

should've been

max_seq, seq_prob = viterbi(
    emission_probs,
    transition_probs,
    init_hidden_probs,
    observed_states,
)

per the function arguments. Just fixed this typo, thanks for pointing it out!