pyro-ppl / pyro

Deep universal probabilistic programming with Python and PyTorch
http://pyro.ai
Apache License 2.0
8.5k stars 981 forks source link

Tutorial on Viterbi Algorithm for Markov Models #1802

Open createmomo opened 5 years ago

createmomo commented 5 years ago

The tutorial of DMM (Deep Markov Model) is great! https://pyro.ai/examples/dmm.html#

I think there may be much more people, not only me, would like to see how to use the model to infer the most likely latent state sequence that has the maximum likelihood by using the Viterbi decoder. In addition, the decoder is implemented in the Pyro style.

I can only found the infer_discrete in the document. But it looks not straight forward how to use this function to do the Viterbi algorithm on a Markov model, given a transition and an emission distribution.

I could use Pytorch to implement one for myself. But I believe, there could be one much better way to implement it using Pyro. Thus, it would be great if you could add an official implementation of this algorithm for infer sequential labels, or add one more code snippet at the end of this tutorial to show how to use the infer_discrete function to do the algorithm.

Many thanks,

fritzo commented 5 years ago

You can access the Viterbi algorithm by setting temperature=0 in infer_discrete. See the example in the infer_discrete documentation. You're welcome to turn that little example into a more full-fledged tutorial, especially if you have good demo problem in mind.

bcjonescbt commented 5 years ago

Upvote here. For those of us without a lot of Pyro experience, there are a lot of bridges to cross to infer the state sequence. Something showing a more substantial example that correctly uses infer_discrete would be very helpful, particularly with enumeration involved. The example in the linked block is pretty light.

fritzo commented 5 years ago

I'll try to get to this soon. In particular I'd like to show how to train with DiscreteHMM then predict with infer_discrete.

adamcweiner commented 3 years ago

Are there any updates on this? I've built my own HMM but haven't been able to get state assignments (or state assignment probabilities) with infer_discrete or a full_guide which are recommended here.

fritzo commented 3 years ago

@adamcweiner As pointed out by dave on the forum you can check out the enumeration tutorial.