{"id":16639514,"url":"https://github.com/borchero/natural-posterior-network","last_synced_at":"2025-09-06T13:32:57.376Z","repository":{"id":41959784,"uuid":"451514431","full_name":"borchero/natural-posterior-network","owner":"borchero","description":"Official Implementation of \"Natural Posterior Network: Deep Bayesian Predictive Uncertainty for Exponential Family Distributions\" (ICLR, 2022)","archived":false,"fork":false,"pushed_at":"2023-04-05T11:19:04.000Z","size":1102,"stargazers_count":82,"open_issues_count":1,"forks_count":14,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-06-02T19:42:23.442Z","etag":null,"topics":["bayesian-deep-learning","deep-learning","machine-learning","pytorch","uncertainty-estimation"],"latest_commit_sha":null,"homepage":"https://arxiv.org/abs/2105.04471","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/borchero.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-24T15:14:05.000Z","updated_at":"2025-05-29T13:36:03.000Z","dependencies_parsed_at":"2024-12-09T16:21:24.663Z","dependency_job_id":"792a7305-1122-4e91-8d58-6ff3890a66cb","html_url":"https://github.com/borchero/natural-posterior-network","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/borchero/natural-posterior-network","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/borchero%2Fnatural-posterior-network","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/borchero%2Fnatural-posterior-network/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/borchero%2Fnatural-posterior-network/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/borchero%2Fnatural-posterior-network/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/borchero","download_url":"https://codeload.github.com/borchero/natural-posterior-network/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/borchero%2Fnatural-posterior-network/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273912612,"owners_count":25189969,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-06T02:00:13.247Z","response_time":2576,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bayesian-deep-learning","deep-learning","machine-learning","pytorch","uncertainty-estimation"],"created_at":"2024-10-12T07:06:18.677Z","updated_at":"2025-09-06T13:32:56.744Z","avatar_url":"https://github.com/borchero.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Natural Posterior Network\n\nThis repository provides the official implementation of the Natural Posterior Network (NatPN) and\nthe Natural Posterior Ensemble (NatPE) as presented in the following paper:\n\n[Natural Posterior Network: Deep Bayesian Predictive Uncertainty for Exponential Family Distributions](https://arxiv.org/abs/2105.04471)\u003cbr\u003e\nBertrand Charpentier*, Oliver Borchert*, Daniel Zügner, Simon Geisler, Stephan Günnemann\u003cbr\u003e\n_International Conference on Learning Representations (ICLR), 2022_\n\n[Paper](https://arxiv.org/abs/2105.04471) | [Video](https://youtu.be/qMtpK0ECD8c)\n\n![Model Overview](./images/model.png)\n\n## Features\n\nThe implementation of NatPN that is found in this repository provides the following features:\n\n- High-level estimator interface that makes NatPN as easy to use as Scikit-learn estimators\n- Simple bash script to train and evaluate NatPN\n- Ready-to-use [PyTorch Lightning](https://www.pytorchlightning.ai) data modules with 8 of the 9\n  datasets used in the paper\\*\n\nIn addition, we provide a\n[public Weights \u0026 Biases project](https://wandb.ai/borchero/natural-posterior-network). This\nproject will be filled with training and evaluation runs that allow you (1) to inspect the\nperformance of different NatPN models and (2) to download the model parameters. See the\n[example notebook](./examples/pretrained.ipynb) for instructions on how to use such a pretrained\nmodel.\n\n_\\*The Kin8nm dataset is not included as it has disappeared from the\n[UCI Repository](http://archive.ics.uci.edu/ml/index.php)._\n\n## Installation\n\nPrior to installation, you may want to install all dependencies (Python, CUDA, Poetry). If you are\nrunning on an AWS EC2 instance with Ubuntu 20.04, you can use the provided bash script:\n\n```bash\nsudo bash bin/setup-ec2.sh\n```\n\nIn order to use the code in this repository, you should first clone the repository:\n\n```bash\ngit clone git@github.com:borchero/natural-posterior-network.git natpn\n```\n\nThen, in the root of the repository, you can install all dependencies via\n[Poetry](https://python-poetry.org):\n\n```bash\npoetry install\n```\n\n## Quickstart\n\n### Shell Script\n\nTo simply train and evaluate NatPN on a particular dataset, you can use the `train` shell script.\nFor example, to train and evaluate NatPN on the Sensorless Drive dataset, you can run the following\ncommand in the root of the repository:\n\n```bash\npoetry run train --dataset sensorless-drive\n```\n\nThe dataset gets downloaded automatically the first time this command is called. The performance\nmetrics of the trained model is printed to the console and the trained model is discarded. In order\nto track both the metrics and the model parameters via [Weights \u0026 Biases](https://wandb.ai), use\nthe following command:\n\n```bash\npoetry run train --dataset sensorless-drive --experiment first-steps\n```\n\nTo list all options of the shell script, simply run:\n\n```bash\npoetry run train --help\n```\n\nThis command will also provide explanations for all the parameters that can be passed.\n\n### Estimator\n\nIf you want to use NatPN from your code, the easiest way to get started is to use the\nScikit-learn-like estimator:\n\n```python\nfrom natpn import NaturalPosteriorNetwork\n```\n\nThe documentation of the estimator's `__init__` method provides a comprehensive overview of all the\nconfiguration options. For a simple example of using the estimator, refer to the\n[example notebook](./examples/estimator.ipynb).\n\n### Module\n\nIf you need even more customization, you can use `natpn.nn.NaturalPosteriorNetworkModel` directly.\nThe `natpn.nn` package provides plenty of documentation and allows to configure your NatPN model as\nmuch as possible.\n\nFurther, the `natpn.model` package provides PyTorch Lightning modules which allow you to train,\nevaluate, and fine-tune models.\n\n## Running Hyperparameter Searches\n\nIf you want to run hyperparameter searches on a local Slurm cluster, you can use the files provided\nin the [sweeps](./sweeps) directory. To run the grid search, simply execute the file:\n\n```bash\npoetry run python sweeps/\u003cfile\u003e\n```\n\nTo make sure that your experiment is tracked correctly, you should also set the `WANDB_PROJECT`\nenvironment variable in a place that is read by the slurm script (found in `sweeps/slurm`).\n\nFeel free to adapt the scripts to your liking to run your own hyperparameter searches.\n\n## Citation\n\nIf you are using the model or the code in this repository, please cite the following paper:\n\n```bibtex\n@inproceedings{natpn,\n    title={{Natural} {Posterior} {Network}: {Deep} {Bayesian} {Predictive} {Uncertainty} for {Exponential} {Family} {Distributions}},\n    author={Charpentier, Bertrand and Borchert, Oliver and Z\\\"{u}gner, Daniel and Geisler, Simon and G\\\"{u}nnemann, Stephan},\n    booktitle={International Conference on Learning Representations},\n    year={2022}\n}\n```\n\n## Contact Us\n\nIf you have any questions regarding the code, please\n[contact us via mail](mailto:borchero@in.tum.de?cc=charpent@in.tum.de\u0026subject=Natural%20Posterior%20Network%20GitHub).\n\n## License\n\nThe code in this repository is licensed under the [MIT License](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fborchero%2Fnatural-posterior-network","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fborchero%2Fnatural-posterior-network","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fborchero%2Fnatural-posterior-network/lists"}