Skip to content

probprog/anglican-infcomp-examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Inference Compilation: Examples

This is a Leiningen project containing several example probabilistic programs for compiled inference. Check out the main project page and a more detailed tutorial.

Contents

  1. Gaussian
  2. Gaussian Mixture Model with fixed number of clusters
  3. Gaussian Mixture Model with variable number of clusters
  4. Wikipedia's Captcha
  5. Facebook's Captcha
  6. Gorilla REPL Notebooks

1. Gaussian

This is a minimal example used to test if everything is running.

Compilation

Start the compilation server:

lein run -- \
--mode compile \
--namespace queries.gaussian

Then run the following to train the neural network:

python -m pyprob.compile

Inference

Start the inference server:

python -m pyprob.infer

Then run inference:

lein run -- \
--mode infer \
--namespace queries.gaussian \
--infer-query-args-value [2.3] \
--infer-number-of-samples 10

2. Gaussian Mixture Model with fixed number of clusters

Compiled artifact for this probabilistic program was used to produce plots in Figure 4 in the paper.

Compilation

Start the compilation server:

lein run -- \
--mode compile \
--namespace queries.gmm-fixed-number-of-clusters \
--compile-combine-observes-fn combine-observes-fn \
--compile-combine-samples-fn combine-samples-fn \
--compile-query-args-value "[$(python src/helpers/io/csv2edn.py resources/gmm-data/gmm.csv) {:mu-0 [0 0] :Sigma-0 [[0.1 0] [0 0.1]]}]"

Then run the following to train the neural network:

python -m pyprob.compile \
--obsEmb cnn2d6c \
--obsEmbDim 20 \
--lstmDim 20 \

Inference

Start the inference server:

python -m pyprob.infer

Then run inference:

lein run -- \
--mode infer \
--namespace queries.gmm-fixed-number-of-clusters \
--infer-observe-embedder-input-value "$(python src/helpers/io/csv2hst.py resources/gmm-data/gmm.csv)" \
--infer-query-args-value "[$(python src/helpers/io/csv2edn.py resources/gmm-data/gmm.csv) {:mu-0 [0 0] :Sigma-0 [[0.1 0] [0 0.1]]}]"

3. Gaussian Mixture Model with variable number of clusters

Compiled artifact for this probabilistic program was used to produce plots in Figure 2 in the paper.

Compilation

Start the compilation server:

lein run -- \
--mode compile \
--namespace queries.gmm-variable-number-of-clusters \
--compile-combine-observes-fn combine-observes-fn \
--compile-combine-samples-fn combine-samples-fn \
--compile-query-args-value "[$(python src/helpers/io/csv2edn.py resources/gmm-data/gmm.csv) {:mu-0 [0 0] :Sigma-0 [[0.1 0] [0 0.1]]}]"

Then run the following to train the neural network:

python -m pyprob.compile \
--obsEmb cnn2d6c \
--obsEmbDim 256 \
--lstmDim 256

Inference

Start the inference server:

python -m pyprob.infer

Then run inference:

lein run -- \
--mode infer \
--namespace queries.gmm-variable-number-of-clusters \
--infer-observe-embedder-input-value "$(python src/helpers/io/csv2hst.py resources/gmm-data/gmm.csv)" \
--infer-query-args-value "[$(python src/helpers/io/csv2edn.py resources/gmm-data/gmm.csv) {:mu-0 [0 0] :Sigma-0 [[0.1 0] [0 0.1]]}]"

The code and data for clustering detector hits of images from the PASCAL VOC 2007 dataset to reproduce Figure 2 of the paper are in examples/plots/gmm-variable-number-of-clusters/detector-hits-clustering. We used Hakan Bilen's and Abhishek Dutta's MatConvNet implementation of the Fast R-CNN detector. We are very grateful to Hakan for showing us how to use their code.

4. Wikipedia's Captcha

Compiled artifact for this probabilistic program was used to break Wikipedia's Captcha, which was described in Section 4.2 of the paper.

Compilation

Start the compilation server:

lein run -- \
--mode compile \
--namespace queries.captcha-wikipedia

Then run the following to train the neural network:

python -m pyprob.compile \
--obsEmb cnn2d6c \
--obsEmbDim 1024 \
--lstmDim 512

Inference

Start the inference server:

python -m pyprob.infer

Then run inference:

lein run -- \
--mode infer \
--namespace queries.captcha-wikipedia \
--infer-query-args-value "[$(python src/helpers/io/png2edn.py resources/wikipedia-dataset/agavelooms.png)]"

5. Facebook's Captcha

Compiled artifact for this probabilistic program was used to break Facebook's Captcha, which was described in Section 4.2 of the paper.

Compilation

Start the compilation server:

lein run -- \
--mode compile \
--namespace queries.captcha-facebook

Then run the following to train the neural network:

python -m pyprob.compile \
--obsEmb cnn2d6c \
--obsEmbDim 1024 \
--lstmDim 512

Inference

Start the inference server:

python -m pyprob.infer

Then run inference:

lein run -- \
--mode infer \
--namespace queries.captcha-facebook \
--infer-query-args-value "[$(python src/helpers/io/png2edn.py resources/facebook-dataset/2MsLet.png)]"

6. Gorilla REPL Notebooks

Gorilla REPL is a Jupyter-like, notebook-style Clojure REPL. All above examples have a corresponding Gorilla REPL version. To open the notebooks, run

lein gorilla

and open the link shown. To load a worksheet, click the button on the top-right corner and select Load a worksheet. Then, use Shift+Enter to successively evaluate the code blocks.

About

Examples for anglican-infcomp

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •