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.

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](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 Models) 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.

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-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

neupi-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

neupi-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

neupi-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

neupi-0.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

File details

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

File metadata

File hashes

Hashes for neupi-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 929f57642a87c434d86af03df9bf177aa33bd8c3bc902cfd553c4dc13a3b6815
MD5 f7188a4a0c2839bfe33defa4f1f9518e
BLAKE2b-256 0c37931dabb203dc15be7b8d204683d80303c793104ef31430772394d388e966

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for neupi-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b18d1de80850c20e5cecda9cbbf29f786b54a24750514a3a4b0e9788fa5fd168
MD5 87cbf2542b9168b0ed02a3c23afc60f6
BLAKE2b-256 171692731d5bb84cd5db2847a41e3ae29a299cfbfd9b74d56846aec27fe74280

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for neupi-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 378a206f93a3d2394acc08f7635ce3c01389f659b7305488ceaf56e4f90c5432
MD5 d479d156bdb64a334c05d35a3453fe72
BLAKE2b-256 5fbcfae1816cb33bf1321e3934f45b963abdfb6d7fb2c50c862fd8a87621424e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for neupi-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 25b6ecbe52fbc122027b6c11f9783880f452cb38add61301ee70c88742896f5e
MD5 2c6c36919745921546cb38e2e6b04466
BLAKE2b-256 e8188006fe7e12da19ecdf31209452d3521dd1e3808d606a5edcb470aa31d6d9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for neupi-0.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8c3342f4fb1d10b546e6891f379974c15e64506de1468e304e3d544f53658ba4
MD5 abdcc384eef0aa1c0f0b576ef30f91bc
BLAKE2b-256 2977555b468c3699ed1d67e29deb44f0f35c686c6df073cc94885745945c8eed

See more details on using hashes here.

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