Skip to main content

The laplace package facilitates the application of Laplace approximations for entire neural networks, subnetworks of neural networks, or just their last layer. The package enables posterior approximations, marginal-likelihood estimation, and various posterior predictive computations. It also includes function-space estimators selected through Laplace with subset_of_weights="all" and hessian_structure="gp": ELLA uses functional_approximation="nystrom", while VaLLA uses functional_approximation="variational".

There is also a corresponding paper, Laplace Redux — Effortless Bayesian Deep Learning, which introduces the library, provides an introduction to the Laplace approximation, reviews its use in deep learning, and empirically demonstrates its versatility and competitiveness. Please consider referring to the paper when using our library:

@inproceedings{laplace2021,
  title={Laplace Redux--Effortless {B}ayesian Deep Learning},
  author={Erik Daxberger and Agustinus Kristiadi and Alexander Immer
          and Runa Eschenhagen and Matthias Bauer and Philipp Hennig},
  booktitle={{N}eur{IPS}},
  year={2021}
}

The code to reproduce the experiments in the paper is also publicly available; it provides examples of how to use our library for predictive uncertainty quantification, model selection, and continual learning.

Installation

To install laplace with pip, run the following:

pip install laplace-torch

To use changes in this repository before they appear in a published release, clone the repository and install it from the checkout:

pip install -e .

Additionally, if you want to use the asdfghjkl backend, please install it via:

pip install git+https://git@github.com/wiseodd/asdl@asdfghjkl

Simple usage

In the following example, a pre-trained model is loaded, then the Laplace approximation is fit to the training data (using a diagonal Hessian approximation over all parameters), and the prior precision is optimized with cross-validation "gridsearch". After that, the resulting LA is used for prediction with the "probit" predictive for classification.

from laplace import Laplace

# Pre-trained model
model = load_map_model()

# User-specified LA flavor
la = Laplace(model, "classification",
             subset_of_weights="all",
             hessian_structure="diag")
la.fit(train_loader)
la.optimize_prior_precision(
    method="gridsearch",
    pred_type="glm",
    link_approx="probit",
    val_loader=val_loader
)

# User-specified predictive approx.
pred = la(x, pred_type="glm", link_approx="probit")

Contributing

Pull requests are very welcome. Please follow the guidelines in https://aleximmer.github.io/Laplace/devs_guide

Metadata

Release files for laplace-torch 0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for laplace-torch 0.3
File Size Uploaded
laplace_torch-0.3.tar.gz 93.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for laplace-torch 0.3
File Interpreter ABI Platform
laplace_torch-0.3-py3-none-any.whl Python 3 none any Details

Total release size: 199.0 kB

Release files / laplace_torch-0.3.tar.gz

Download URL laplace_torch-0.3.tar.gz
Size 93.6 kB
Tags Source
SHA-256 checksum
How to use checksums
ba4315b9692b3065470e5e5a1e4a917edb8b40141e5eea4b6a4044ec79b087c7
BLAKE2b-256 checksum
How to use checksums
d2ac77b0ca59f820e41b4541b82c894846e5b6296fdb2b3d207587319db10c71
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.10 {"installer":{"name":"uv","version":"0.12.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Omarchy","version":"4.0.4","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / laplace_torch-0.3-py3-none-any.whl

Download URL laplace_torch-0.3-py3-none-any.whl
Size 105.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
297867a130aa35d73799916101b3ad2bfa1f2585430d5618c0503a925e989033
BLAKE2b-256 checksum
How to use checksums
bceaad111b4807fb27c0d19c57ae2aaf3b102c7fbc05c28a5d37f7014710b852
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.10 {"installer":{"name":"uv","version":"0.12.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Omarchy","version":"4.0.4","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.3 This release

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page