How to begin learning probabilistic programming?


Can anyone help me with some resources to learn probabilistic programming with pyro? I do not have any background on probabilistic programming. I skimmed through the tutorials and examples in but it seems they assume a background in probabilistic programming concepts.


The tutorials, especially the language intro tutorials, are designed for users with no background in probabilistic programming. Part 2 of the intro tutorials has recently been updated to make it more accessible:

Do you think there are parts of the tutorials we could clarify?

If you prefer videos and slides, see this forum post: Pyro Tutorial Videos (MLTrain@UAI2018). Another good introduction to probabilistic programming is the online textbook Probabilistic Models of Cognition, which also assumes no background knowledge.


I think Pyro (and TF Probability) could benefit from a port of Probabilistic Models of Cognition (PMC). I first worked through PMC when it was released many years ago. Although I’d taught some intro material on Bayesian Networks, PMC and Church was my first introduction to PPL. I also found it helpful to read Bayesian Models of Cognition while working through PMC. Most of the statistical and PPL concepts in PMC were new to me (an old symbolic AI researcher, now working in clinical informatics), yet I found it very accessible and eye-opening. I was able to use Church to demonstrate how PPL might help with biomedical informatics applications for clinical decision support and clinical guidelines. Since then, I’ve been monitoring PPL research in hopes of applying PPL to complex real-world problems in biomedical informatics.

In that context, I have begun to explore Pyro and TF probability, however, I am finding the tutorial material and docs for both somewhat impenetrable, despite my comfort with Church. It appears that those who have written the tutorials are so steeped in this area that they assume a newbie to PPL has much more background than I suspect most will have.

After looking at the Pyro intro material and some examples, I decided to take a different tack: I would recreate PMC using Pyro (and possibly later TF probability). I got as far as Chapter 2 of PMC where it introduces the Infer operator from WebPPL. I cannot tell at all if Pyro has a similar operator. The docs didn’t help here all that much, though I’m now suspecting that NUTS plus sample(trace) is the equivalent to Infer + sample in WebPPL.

I suspect that part of my problem is that WebPPL and Pyro are very different in their approaches, or at least are presented differently. WebPPL overall seems like a higher level language that more directly expresses PPL concepts. WebPPL also comes with a nice viz function that greatly simplifies seeing the output of models.

I also think that some of the difficulty I’m having is due to the tutorial material and the selection of inference methods in the material. For instance, I don’t think it’s a good idea to introduce PPL to newbies by using SVI. The MCMC, NUTS approach is a bit more accessible, since it doesn’t need a guide distribution. However, even here, the example for NUTS is not explained at all. For instance, it is going to take some time for me to understand (and find the docs for) what mcmc_run.marginal(‘beta’).empirical(‘beta’) means. This is the sort of line that a tutorial/documentation needs to explain.

My intention right now is to continue to work through PMC in Pyro and make the notebooks, probably with missing sections, available through GitHub so that others can fill in gaps or correct my mistakes. I’ve also started to write a visualization function similar to that in WebPPL.


@toddrjohnson Thanks for your sharing!

I have raised an issue at github about missing docs for your reported methods. If you detect some places else which we missed, please make an issue in github. We’ll try to clarify them.


I would be interested in your notebooks.
Do you have them already on GitHub?


Unfortunately, I’ve not gotten very far yet. You can see some of my progress here: Is there an equivalent Pyro construct for WebPPL's Infer Operator?

To better understand Pyro, I then tried to use the user defined geometric function for inference, but so far I’ve not been able to get this to work in Pyro either using SVI or MCMC+NUTS. This is despite trying several variations of each and reading through several Pyro tutorials, the docs, and parts of the Pyro code. Based on the responses in the above link, I suspect that PMC may be difficult to do in Pyro, because in order to produce efficient inference, Pyro requires a lot more guidance on the part of the programmer. Those efficiency goals increase Pyro’s cognitive load over WebPPL and Church.

I also suspect that I am missing the conceptual framework needed to use Pyro. At this point the documentation is pretty terse and the tutorials are not really designed to convey that conceptual model (at least not enough for me). In some cases, I think the tutorials are misleading. For example, the first tutorial has a section titled “Universality: Stochastic Recursion, Higher-order Stochastic Functions, and Random Control Flow”, which makes it sound like Pyro easily supports all of those features for inference; however, so far, this doesn’t seem to be the case. For instance, the geometric function defined in that section does not return a tensor, so gives an error when used in inference. That’s a minor problem, but can mislead a new person. However, so far I’ve not been able to do inference with a function such as geometric that can create a different number of samples on a given call. One of the tutorials addresses this by fixing the number of samples ahead of time, but that negates the flexibility and ease of use of the recursive function.

Now it is quite possible that I’m wrong on all or some of this. I’ve certainly not stepped through all the examples, so I may be missing one that gives me the key to understanding the conceptual underpinnings of Pyro. I read the Bingham, et al. Pyro paper, but that doesn’t really go into the nuts and bolts needed to use Pyro.

I plan to continue to work on this, but I’m afraid that I may not make much progress with the current docs and tutorial material. Another idea is to do what I can do on each PMC lesson and just make it available with stubs, incomplete code, and questions for others to contribute to.