Skip to main content

metabeta

Python 3.12 PyTorch uv PyPI Release checks Hugging Face License: CC BY-NC-SA 4.0

metabeta is an amortized model for Bayesian generalized linear mixed-effects models (GLMMs). Given a grouped dataset, a model formula, and an optional prior specification, it returns posterior samples for fixed effects, random effects, variance components, and correlations with the speed and batching capabilities of a PyTorch forward pass.

  • Supports Normal, Bernoulli, and Poisson outcomes.
  • Accepts convenient lme4-style formulas.
  • Conditions on prior family and hyperparameters at inference time.
  • Supports batched prior-sensitivity analysis in one sample() call.
  • Includes diagnostics for posterior contraction and prediction accuracy.
  • Ships the pretrained inference API, plotting helpers, diagnostics, and demo notebooks.
  • Keeps simulation, training, reference-method evaluation, and experiment scripts in the source repository for research workflows.

Pretrained checkpoints are hosted on Hugging Face and are downloaded automatically on first use.

Quick start

Install the pretrained-model inference package from PyPI:

pip install metabeta

For local development, install from source with uv:

git clone https://github.com/adkipnis/metabeta.git
cd metabeta
uv sync
uv pip install -e .

The default PyPI install is for pretrained-model inference. To reproduce training runs, generate synthetic datasets, benchmark against reference methods, or extend the package, clone the repository and install the optional research dependencies:

git clone https://github.com/adkipnis/metabeta.git
cd metabeta
uv sync --extra research --group simulation --dev
uv pip install -e ".[research]"

Run posterior inference on a grouped dataframe:

import statsmodels.api as sm
from metabeta.models.api import Api

mb = Api.from_pretrained("normal")
df = sm.datasets.get_rdataset("sleepstudy", "lme4").data
result = mb.sample(df, formula="Reaction ~ Days + (Days | Subject)", n_samples=1000)
print(mb.posteriorSummary(result))

With n_samples >= 64, sample also refines the flow posterior by Independence Metropolis-Hastings (the default, refine=True). The chain uses the flow as its proposal, so the refined posterior does not hinge on network accuracy alone; per-dataset acceptance rates and a suggested pool size are reported in result.safeguards. If the suggestion exceeds the n_samples you requested, rerun with the larger value (or pass refine=False to keep the raw flow posterior).

See demos/intro.ipynb for the full sleepstudy walkthrough and demos/priors.ipynb for an exemplary prior-sensitivity analysis.

From simulation to deployment

Each pretrained model is built through the same pipeline, from a dataset simulator to a checkpoint that can be loaded by the public API.

  1. Define the model family. Choose the likelihood, GLMM dimensions, group structure, covariate styles, and prior families covered by a checkpoint.
  2. Generate training data. Simulate hierarchical datasets and posterior reference targets across the configured design space.
  3. Format inputs. Convert grouped tabular data into padded tensors, masks, and prior encodings shared by training and inference.
  4. Train amortized posteriors. Use set-transformers (to learn low-dimensional permutation-invariant summaries of the datasets) and conditional coupling flows to approximate posteriors for fixed effects, variance parameters, correlations, and group-wise random effects.
  5. Validate behavior. Check parameter recovery, credible interval coverage, simulation-based calibration, posterior predictive accuracy and run comparisons against reference methods.
  6. Package checkpoints. Bundle weights, configs, routing metadata, and preprocessing expectations into a joint checkpoint.
  7. Deploy through the API. Load joint checkpoints with Api.from_pretrained(...) for convenient posterior estimation and diagnostics.

Repository map

Path Contents
metabeta/analytical/ GLMM analytical fits and helpers
metabeta/configs/ model and preset configuration files
metabeta/datasets/ preprocessing and source-specific dataset fetchers
metabeta/evaluation/ parameter recovery, coverage, SBC, posterior predictive checks and summary metrics
metabeta/models/ model API, set transformers, normalizing flows
metabeta/plotting/ plot functions for posterior samples, recovery, calibration, and runtime
metabeta/posthoc/ post-hoc refinement of the flow posterior (IMH, importance sampling) and NUTS warm-start helpers
metabeta/simulation/ synthetic hierarchical data generation and reference fitting with PyMC
metabeta/training/ training entry point and checkpoint loop
metabeta/utils/ config, dataloading, routing, IO, and shared helper code
experiments/ reproducible experiment scripts grouped by package area
tests/ pytest suite for models, simulation, evaluation, datasets, and utils
demos/ demo notebooks

Metadata

Release files for metabeta 0.5.0

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

Source distribution (sdist)

Source distribution for metabeta 0.5.0
File Size Uploaded
metabeta-0.5.0.tar.gz 3.4 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for metabeta 0.5.0
File Interpreter ABI Platform
metabeta-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 3.7 MB

Release files / metabeta-0.5.0.tar.gz

Download URL metabeta-0.5.0.tar.gz
Size 3.4 MB
Tags Source
SHA-256 checksum
How to use checksums
352a752de28f2569edcdedd66465f7003f0dc77e8d8a5a4c071c910230a55fef
BLAKE2b-256 checksum
How to use checksums
d1951820cc6ecc564f2cb970705183c8174dfe655f661e648a10532afd57db69
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 14, 2026.

Transparency log

Release files / metabeta-0.5.0-py3-none-any.whl

Download URL metabeta-0.5.0-py3-none-any.whl
Size 318.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
651fb9aade0c264a9b5e4556ca78cc4e5601576307f797e9d1d28c92223ff406
BLAKE2b-256 checksum
How to use checksums
bbf0687f46d55799f4752598a717d25d8f76241ec9795edd45c69de69c8c9827
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 14, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files

0.4.3

2 release files

0.4.2

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