Skip to main content

bayesflow-irt

GitHub release PyPI version License: MIT Python 3.11+

A BayesFlow add-on for amortized Bayesian inference in Item Response Theory (IRT) models: train a network once on simulated response matrices, then draw posteriors for new data sets without refitting, for any number of items and persons within the trained range.

What is included

  • Variable-size simulators and adapters for the 1PL, 2PL, PCM, and GPCM models
  • MatrixEquivariantIRTSummary, a summary network that is exchangeable over both items and persons (Hartford-style matrix blocks)
  • EquivariantIRTApproximator for per-item posterior inference
  • Person scoring, metadata sidecars for trained models, and memory controls for large n_persons
  • Optional: calibration-aware training (CalibratedIRTApproximator) and hyperparameter-optimization hooks (bayesflow_irt.hpo)

Installation

The package is not on PyPI yet. Install it from a clone:

git clone https://github.com/matthiaskloft/bayesflow-irt.git
cd bayesflow-irt
pip install -e ".[torch]"

Extras: dev (tests), examples (plotting and Jupyter), card (model-card plots), hpo (bayesflow-hpo, from PyPI), numba (faster response sampling), and calibration (bayesflow-calibration-loss, which will be released separately; until then this extra cannot be installed). The tensorflow and jax backend extras are also available.

Set the Keras backend before importing keras, bayesflow, or bayesflow_irt:

export KERAS_BACKEND=torch          # PowerShell: $env:KERAS_BACKEND = "torch"

Quick start

import bayesflow as bf
from bayesflow_irt import (
    EquivariantIRTApproximator,
    MatrixEquivariantIRTSummary,
    Prior,
    make_2pl_adapter,
    make_2pl_simulator,
)

simulator = make_2pl_simulator(
    n_items=(10, 25),
    n_persons=(100, 250),
    prior_a=Prior("lognormal", loc=0.0, scale=0.3),
    prior_b=Prior("normal", loc=0.0, scale=2.0),
)
adapter = make_2pl_adapter(simulator, internal_parameterization="loading")

approximator = EquivariantIRTApproximator(
    adapter=adapter,
    inference_network=bf.networks.FlowMatching(),
    summary_network=MatrixEquivariantIRTSummary(embed_dim=64),
)
approximator.compile(optimizer="adam")
approximator.fit(simulator=simulator, epochs=10, num_batches=32, batch_size=64)

batch = simulator.sample((4,))
posterior = approximator.sample(num_samples=200, conditions=batch)

The public functions and classes are documented in their docstrings.

Examples

examples/train_1pl_minimal.py is a minimal end-to-end script (simulate, adapt, train, sample, save). Pretrained checkpoints are not distributed yet; example notebooks will follow with them.

For longer runs, scripts/train_irt.py runs the same training pipeline from a JSON config and writes only files:

python scripts/train_irt.py --config scripts/configs/smoke_1pl.json

scripts/configs/ has a quick smoke test (smoke_1pl.json) and a fixed-size 2PL run (2pl_fixed.json).

On Windows, run Jupyter with a kernel that imports torch first (scripts/ipykernel_torch_preload.py); otherwise loading pyzmq before torch can crash with WinError 1114.

Status

Version 0.1.0, under active development; the API may change between minor versions. Planned: pretrained checkpoints with model cards, and example notebooks.

Development

pip install -e ".[dev,torch]"
pytest tests/
ruff check src/

See CONTRIBUTING.md and CHANGELOG.md.

License and citation

MIT, see LICENSE. To cite the software, see CITATION.cff. The methods the package implements are cited in references.md.

Metadata

Release files for bayesflow-irt 0.1.1

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

Source distribution (sdist)

Source distribution for bayesflow-irt 0.1.1
File Size Uploaded Provenance
bayesflow_irt-0.1.1.tar.gz 537.0 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for bayesflow-irt 0.1.1
File Interpreter ABI Platform
bayesflow_irt-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 869.5 kB

Release files / bayesflow_irt-0.1.1.tar.gz

Download URL bayesflow_irt-0.1.1.tar.gz
Size 537.0 kB
Tags Source
SHA-256 checksum
How to use checksums
422d4cedaebaa717ea6655d94ee9f95649033bb563fa07ae01268b70418ddbe5
BLAKE2b-256 checksum
How to use checksums
a457048c054d120bed458f743f10332e9bd7bb2847d96c83fd4dbba6f5b4732b
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 Oct 20, 2026.

Transparency log

Release files / bayesflow_irt-0.1.1-py3-none-any.whl

Download URL bayesflow_irt-0.1.1-py3-none-any.whl
Size 332.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cbee5e65f052cc8d68044c2ea4af9d94df3315c6127892545b8812d8cbed40e1
BLAKE2b-256 checksum
How to use checksums
fee2b3b1813c4cdc6157d967fcfa2bff3f5217cf9ebf8d7ab6f68cb879a4e48a
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 Oct 20, 2026.

Transparency log

Security for bayesflow-irt 0.1.1

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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for bayesflow_irt-0.1.1.tar.gz

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 Oct 20, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files Full provenance

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