Skip to content

Commit

Permalink
Add notebook with Pyro model (#111)
Browse files Browse the repository at this point in the history
* Add notebook demo with pyro

* Fix pyro README render

* Refix README render

* Rerefix README render

* README title

* Update READMEs

* Fix links in README

* Update docs

* Add pyro convergence diagnostics to examples

* Add link to diagnostics

* Describe marginals

* Update examples/pyro_pima_indians_sghmc.ipynb

Co-authored-by: KaelanDt <[email protected]>

* Update docs/tutorials/index.md

Co-authored-by: KaelanDt <[email protected]>

* Add explainer to notebook

---------

Co-authored-by: KaelanDt <[email protected]>
  • Loading branch information
SamDuffield and KaelanDt authored Aug 13, 2024
1 parent 1a7eeba commit 87e0af0
Show file tree
Hide file tree
Showing 5 changed files with 520 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

General purpose python library for uncertainty quantification with [`PyTorch`](https://github.com/pytorch/pytorch).

- [x] **Composable**: Use with [`transformers`](https://huggingface.co/docs/transformers/en/index), [`lightning`](https://lightning.ai/), [`torchopt`](https://github.com/metaopt/torchopt), [`torch.distributions`](https://pytorch.org/docs/stable/distributions.html) and more!
- [x] **Composable**: Use with [`transformers`](https://huggingface.co/docs/transformers/en/index), [`lightning`](https://lightning.ai/), [`torchopt`](https://github.com/metaopt/torchopt), [`torch.distributions`](https://pytorch.org/docs/stable/distributions.html), [`pyro`](https://pyro.ai/) and more!
- [x] **Extensible**: Add new methods! Add new models!
- [x] **Functional**: Easier to test, closer to mathematics!
- [x] **Scalable**: Big model? Big data? No problem!
Expand Down
6 changes: 6 additions & 0 deletions docs/tutorials/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,9 @@ data, with some interesting takeaways.
[Variational continual learning](https://arxiv.org/abs/1710.10628) notebook for a simple
regression task that's easy to visualize.


[<img style="float: right; width: 6em" src="https://storage.googleapis.com/posteriors/pyro_posteriors.png">](https://github.com/normal-computing/posteriors/blob/main/examples/pyro_pima_indians_vi.ipynb)

- [`pyro_pima_indians_sghmc`](https://github.com/normal-computing/posteriors/blob/main/examples/pyro_pima_indians_sghmc.ipynb):
An accessible notebook demonstrating the use of `posteriors` with a [`pyro`](https://pyro.ai)-defined Bayesian logistic regression model, as well as convergence diagnostics from [`pyro`](https://pyro.ai).

6 changes: 5 additions & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ on a series of books from the [pg19](https://huggingface.co/datasets/pg19) datas
- [`imdb`](imdb/): Investigates [cold posterior effect](https://proceedings.mlr.press/v119/wenzel20a/wenzel20a.pdf)
for a range of approximate Bayesian methods on [IMDB](https://www.tensorflow.org/api_docs/python/tf/keras/datasets/imdb/load_data)
data.
- ['pyro_pima_indians`](pyro_pima_indians/): Uses `pyro` to define a Bayesian logistic
- [`pyro_pima_indians`](pyro_pima_indians/): Uses `pyro` to define a Bayesian logistic
regression model for the [Pima Indians Diabetes Database](https://www.kaggle.com/uciml/pima-indians-diabetes-database).
Compares `posteriors` methods against `pyro` and `blackjax`.
See [`pyro_pima_indians_vi.ipynb`](pyro_pima_indians_vi.ipynb) for a more accessible lightweight notebook.
- [`yelp`](yelp/): Compares a host of `posteriors` methods (highlighting the easy
exchangeability) on a sentiment analysis task adapted from the [Hugging Face tutorial](https://huggingface.co/docs/transformers/training#train-in-native-pytorch).
- [`continual_regression`](continual_regression.ipynb): [Variational continual learning](https://arxiv.org/abs/1710.10628)
Expand All @@ -23,6 +24,9 @@ to infer the skills of Premier League football teams.
- [`lightning_autoencoder.py`](lightning_autoencoder.py): Easily adapt the autoencoder
example from the [Lightning tutorial](https://lightning.ai/docs/pytorch/stable/starter/introduction.html)
to use UQ methods with `posteriors` and logging + device handling with `lightning`.
- [`pyro_pima_indians_sghmc.ipynb`](pyro_pima_indians_sghmc.ipynb): A more accessible
notebook demonstrating the use of `posteriors` with a `pyro` defined Bayesian logistic regression model.
As well as convergence diagnostics from `pyro`.


Further information is available within the specific example directories or files.
Expand Down
5 changes: 4 additions & 1 deletion examples/pyro_pima_indians/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# Using `posteriors` with `pyro`
# Using `posteriors` with `pyro` on the Pima Indians Dataset

In this example, we show how to use `posteriors` with [`pyro`](https://pyro.ai/) to define a Bayesian logistic regression model for the [Pima Indians Diabetes Database](https://www.kaggle.com/uciml/pima-indians-diabetes-database). The model can then be used to automatically generate
a `log_posterior` function that can be directly passed to `posteriors`.

This specific model is small with 8 dimensions and 768 data points.

The code in this folder involves running over multiple seeds and collecting time and KSD metrics.
A more accessible notebook demonstrating the use of `posteriors` with `pyro` can be found in [examples/pyro_pima_indians_sghmc.ipynb](../pyro_pima_indians_sghmc.ipynb).


## Results

Expand Down
Loading

0 comments on commit 87e0af0

Please sign in to comment.