Skip to main content

A library of neural solvers for fast and accurate inference over Probabilistic Models.

Project description

NeuPI: A Library for Neural Probabilistic Inference

NeuPI is a PyTorch-based library for solving inference tasks in Probabilistic Models (PMs) using neural network surrogates. It provides a modular framework for training neural models in a self-supervised fashion, where the Probabilistic Model itself provides the supervisory signal.

This approach eliminates the need for labeled training data, enabling neural networks to learn to solve tasks like Most Probable Explanation (MPE) by directly optimizing for the log-likelihood of their proposed solutions.

Documentation

Documentation is available at https://neupi.readthedocs.io/en/latest/. GitHub repository: https://github.com/Shivvrat/NeuPI.

Key Features

  • Self-Supervised Training: Train neural surrogates using only the PGM definition—no labeled data required.
  • Advanced Inference: Includes the ITSELF (Inference Time Self-Supervised Training) engine for test-time refinement, significantly improving inference accuracy.
  • Modular Architecture: A clean separation of components:
    • PGM Evaluators (MarkovNetwork, SumProductNetwork)
    • Neural Solvers (MLP)
    • Input Embedders (DiscreteEmbedder)
    • Trainers (SelfSupervisedTrainer)
    • Inference Engines (SinglePassInferenceEngine, ITSELF_Engine)
  • Extensible: Easily register your own custom components using the built-in factory system.
  • Efficient Backend: Utilizes a high-performance Cython backend for parsing .uai files.

Core Workflow

The core idea of NeuPI is to train a neural network to act as a fast approximator for a complex PM query. The workflow is as follows:

  1. Load a PM: This PM acts as the loss and evaluates the quality of solutions.
  2. Define a Neural Surrogate: This is the "solver," which learns to generate high-quality solutions.
  3. Train: Use the SelfSupervisedTrainer to train the solver. The loss is the negative log-likelihood of the solver's solutions, as computed by the PM.
  4. Infer: Use the trained model with an InferenceEngine to answer new queries.

Installation

First, ensure you have PyTorch installed (with a GPU version if you want to use it). Then, clone the repository and install the library and its dependencies.

# Clone the repository
git clone https://github.com/Shivvrat/NeuPI
cd NeuPI

# Install the library in editable mode
pip install -e .

Quick Start

Examples provided in the examples directory demonstrate:

1.  Computing the negative log-likelihood (loss) of a solution to a MPE query on a Markov Network (Probabilistic Graphical odels) and Sum-Product Network (Probabilistic Circuits).
2.  Training a neural solver to solve MPE queries on a Markov Network and Sum-Product Network.
3.  Performing inference with a trained neural solver on a Markov Network and Sum-Product Network.

Implemented Methods

The core components of NeuPI are directly linked to our published research. The following table maps the key classes in the library to the papers that introduce the primary concepts.

Type Method / Component Primary Reference(s) Description
Trainer + Loss SelfSupervisedTrainer Arya et al., AAAI 2024, Arya et al., NeurIPS 2024, Arya et al., AISTATS 2025 (SINE) The core training loop for learning a neural solver by minimizing the negative log-likelihood provided by a PGM/PC evaluator.
Embedding DiscreteEmbedder Arya et al., AAAI 2024, Arya et al., NeurIPS 2024 A feature engineering module that creates rich (discrete) input representations from variable assignments and bucket information (evidence, query, unobserved).
Inference SinglePassInferenceEngine Arya et al., AAAI 2024, Arya et al., AISTATS 2025 (SINE) A standard inference pipeline involving a single forward pass of the neural network to produce an MPE/MMAP solution.
Inference ITSELF_Engine Arya et al., NeurIPS 2024 Implements Inference Time Self-Supervised Learning Fine-tuning, an advanced engine that optimizes the model for each specific test instance to refine solution quality.
Discretizer KNearestDiscretizer Arya et al., AISTATS 2025 (SINE) A sophisticated discretization method that performs a beam search over the k-nearest binary vectors to find a high-quality discrete assignment.
Discretizer OAUAI Arya et al., AISTATS 2025 (SINE) A heuristic discretizer that uses an oracle to answer the query over the variables with the highest uncertainty (probabilities closest to 0.5).

Running Tests

To ensure all components are working correctly, run the test suite using pytest:

pytest

📖 Citation

If you use NeuPI in your research, please cite the following repository:

@article{arya2025neupi,
  title={NeuPI: A Library for Neural Probabilistic Inference},
  author={Arya, Shivvrat and Rahman, Tahrima and Gogate, Vibhav},
  link={https://github.com/Shivvrat/NeuPI},
  year={2025}
}

In addition, cite the relevant papers that introduce the core methods implemented in NeuPI:

  • Single-Pass Inference and Marginal MAP inference in probabilistic circuits:
@article{aryaNeuralNetworkApproximators2024,
  title = {Neural {{Network Approximators}} for {{Marginal MAP}} in {{Probabilistic Circuits}}},
  author = {Arya, Shivvrat and Rahman, Tahrima and Gogate, Vibhav},
  year = {2024},
  month = mar,
  journal = {Proceedings of the AAAI Conference on Artificial Intelligence},
  volume = {38},
  number = {10},
  pages = {10918--10926},
  issn = {2374-3468},
  doi = {10.1609/aaai.v38i10.28966},
  urldate = {2024-03-27},
  copyright = {Copyright (c) 2024 Association for the Advancement of Artificial Intelligence},
  langid = {english},
}
  • Single-Pass Inference and neural embedding techniques for Constrained MPE:
@inproceedings{aryaLearningSolveConstrained2024,
  title = {Learning to {{Solve}} the {{Constrained Most Probable Explanation Task}} in {{Probabilistic Graphical Models}}},
  booktitle = {Proceedings of {{The}} 27th {{International Conference}} on {{Artificial Intelligence}} and {{Statistics}}},
  author = {Arya, Shivvrat and Rahman, Tahrima and Gogate, Vibhav},
  year = {2024},
  month = apr,
  pages = {2791--2799},
  publisher = {PMLR},
  issn = {2640-3498},
  urldate = {2024-04-21},
  langid = {english},
}
  • ITSELF engine and the general framework for MPE inference over Probabilistic Models:
@inproceedings{aryaNeuralNetworkApproach2024,
  title = {A Neural Network Approach for Efficiently Answering Most Probable Explanation Queries in Probabilistic Models},
  booktitle = {The {{Thirty-eighth Annual Conference}} on {{Neural Information Processing Systems}}},
  author = {Arya, Shivvrat and Rahman, Tahrima and Gogate, Vibhav Giridhar},
  year = {2024},
  month = nov,
  urldate = {2024-11-17},
  langid = {english},
}
  • Single-Pass Inference and better embedding and discretization techniques in probabilistic graphical models:
@inproceedings{aryaSINEScalableMPE2025,
  title = {{{SINE}}: {{Scalable MPE}} Inference for Probabilistic Graphical Models Using Advanced Neural Embeddings},
  shorttitle = {{{SINE}}},
  booktitle = {The 28th {{International Conference}} on {{Artificial Intelligence}} and {{Statistics}}},
  author = {Arya, Shivvrat and Rahman, Tahrima and Gogate, Vibhav Giridhar},
  year = {2025},
  month = feb,
  urldate = {2025-06-22},
  langid = {english},
}

License

This project is licensed under the MIT License. See the LICENSE file for details.

Disclaimer

This code was written for research purposes and therefore might not strictly adhere to established coding practices and guidelines. View and use at your own risk!

Acknowledgments

This work was supported in part by the DARPA Perceptually-Enabled Task Guidance (PTG) Program under contract number HR00112220005, by the DARPA Assured Neuro Symbolic Learning and Reasoning (ANSR) Program under contract number HR001122S0039, by the National Science Foundation grant IIS-1652835 and by the AFOSR award FA9550-23-1-0239.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

neupi-1.0.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

neupi-1.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

neupi-1.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

neupi-1.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

neupi-1.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

neupi-1.0.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

File details

Details for the file neupi-1.0.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for neupi-1.0.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 31ad5bf2fb20e61143e04897afbc23be7edf199146e81696bddd170e8e0c233e
MD5 eec12fe02048d810cbb540bc33ab9bf4
BLAKE2b-256 a7b85e27a555936b87e974b238053b72aab096f3467dda86321ccd31addd45fa

See more details on using hashes here.

Provenance

The following attestation bundles were made for neupi-1.0.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on Shivvrat/NeuPI

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file neupi-1.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for neupi-1.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 58439742bbd1310cb49d2d78d0e657269f26145eac168fa53860df2718c76689
MD5 6fbf5eac0943949b23f4670afa66d78c
BLAKE2b-256 9866a9486dead474ca4745ff7c8f044ce5586996efd42f5ffadc6d808f7f5a43

See more details on using hashes here.

Provenance

The following attestation bundles were made for neupi-1.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on Shivvrat/NeuPI

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file neupi-1.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for neupi-1.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c4b76a8e4f58969a58d50e32c9836ab6b42a447f5ac0112d95cdf593d9e1e6bc
MD5 e469a83d5692b466277989ca5e6b22b5
BLAKE2b-256 f7d50317c1590bfd52a92dc5389784b7e1b880ade9650b62f7634a2c2ad36816

See more details on using hashes here.

Provenance

The following attestation bundles were made for neupi-1.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on Shivvrat/NeuPI

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file neupi-1.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for neupi-1.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d32f941658356be57a854481d29740af72002e4055bb39684e912dfc32f55c02
MD5 0ee22da203fbc05ee06519f42c758d57
BLAKE2b-256 ef2781c3855dee0014805fb3258ea48a329ad6c870e128af7b72b6254fb0a190

See more details on using hashes here.

Provenance

The following attestation bundles were made for neupi-1.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on Shivvrat/NeuPI

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file neupi-1.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for neupi-1.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9195ae728d3008d1d3db9f94678a4af4c2d73254f4a834ec6652fa9028a24c39
MD5 3887291b77a965cbe6dbe6ea82c8a5f1
BLAKE2b-256 29c2f735a591f15f5b0efe976e58bf57e7b59f2c692d9a8d13fddbe26726452d

See more details on using hashes here.

Provenance

The following attestation bundles were made for neupi-1.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on Shivvrat/NeuPI

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file neupi-1.0.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for neupi-1.0.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7ef85d7886541e6ba738b3e9e3d731245d3ff466225cde2f36ee38c8e3e94aa8
MD5 66f0d6b3a1434506e6dc36e46e982c80
BLAKE2b-256 0c310ef366e2b15250cf2f8bc1fae719b7e2672802b31a27e405c18c5a47d66f

See more details on using hashes here.

Provenance

The following attestation bundles were made for neupi-1.0.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on Shivvrat/NeuPI

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page