Skip to main content

Concept-Based Deep Learning Library for PyTorch.

Project description

PyC Logo

PyPI Total downloads Codecov Documentation Status

🚀 Getting Started - 📚 Documentation - 💻 User guide

[!CAUTION] Alpha software: PyC is currently under active development. Public APIs may change and be unstable between releases.

PyC is a library built upon PyTorch and Pytorch Lightning to easily implement interpretable and causally transparent deep learning models. The library provides primitives for annotated tensors, interpretable layers, interventions, interpretable probabilsitic graphical models, and APIs for running experiments at scale.

The name of the library stands for both

  • PyTorch Concepts: as concepts are essential building blocks for interpretable deep learning.
  • $P(y|C)$: as the main purpose of the library is to support sound probabilistic modeling of the conditional distribution of targets $y$ given concepts $C$.

Quick Start

Install PyC from PyPI:

pip install --pre pytorch-concepts[data]

Use pip install --pre pytorch-concepts for core-only (no data dependencies), or see full installation options for conda setup.

After installation, you can import it in your Python scripts as:

import torch_concepts as pyc

Follow our user guide to get started with building interpretable models using PyC!


PyC Software Stack

The library is organized to be modular and accessible at different levels of abstraction:

  • Conceptarium (No-code API): applications and benchmarking. These APIs allow to easily run large-scale experiments by interfacing only with configuration files. Built on top of Hydra and WandB.
  • High-level APIs: use out-of-the-box models. These APIs allow to instantiate models with 1 line of code. Models are available both as plain PyTorch modules (implementing forward, allowing custom training loops) and as PyTorch Lightning modules.
  • Mid-level APIs: interpretable probabilistic graphical models. These APIs allow to define variables (concepts and embeddings), connect them via conditional distributions parametrized by interpretable layers, and perform probabilistic inference on the resulting graphical model.
  • Low-level APIs: interpretable layers. These APIs allow to build architectures from basic interpretable layers in a plain PyTorch-like interface. These APIs also include annotated tensors, interventions, metrics, losses, and datasets.

PyC Software Stack


Contributing

Contributions are welcome! Please check our contributing guidelines to get started.

Thanks to all contributors! 🧡

External Contributors


Cite this Library

If you found this library useful for your research article, blog post, or product, we would be grateful if you would cite it using the following bibtex entry:

@software{pycteam2025concept,
    author = {Barbiero, Pietro and De Felice, Giovanni and Espinosa Zarlenga, Mateo and Ciravegna, Gabriele and Dominici, Gabriele and De Santis, Francesco and Casanova, Arianna and Debot, David and Giannini, Francesco and Diligenti, Michelangelo and Marra, Giuseppe},
    license = {Apache 2.0},
    month = {3},
    title = {{PyTorch Concepts}},
    url = {https://github.com/pyc-team/pytorch_concepts},
    year = {2025}
}

Reference authors: Pietro Barbiero, Giovanni De Felice, and Mateo Espinosa Zarlenga.


Funding

This project is supported by the following organizations:

FWO - Research Foundation Flanders      Hasler Foundation      SNSF - Swiss National Science Foundation

Project details


Download files

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

Source Distribution

pytorch_concepts-1.0.0a4.tar.gz (286.7 kB view details)

Uploaded Source

Built Distribution

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

pytorch_concepts-1.0.0a4-py3-none-any.whl (355.7 kB view details)

Uploaded Python 3

File details

Details for the file pytorch_concepts-1.0.0a4.tar.gz.

File metadata

  • Download URL: pytorch_concepts-1.0.0a4.tar.gz
  • Upload date:
  • Size: 286.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for pytorch_concepts-1.0.0a4.tar.gz
Algorithm Hash digest
SHA256 9c9080824c235d9bd08f5c900edb3aa422815d6a03e13b63f71a7b77ec544e80
MD5 5f40d4547042a5e80e0c21b8a0e3d8cc
BLAKE2b-256 27cc3eeaa9a353e77623d6cd3790b0bc63868d880b8b6b3dc7410aecb355f64a

See more details on using hashes here.

File details

Details for the file pytorch_concepts-1.0.0a4-py3-none-any.whl.

File metadata

File hashes

Hashes for pytorch_concepts-1.0.0a4-py3-none-any.whl
Algorithm Hash digest
SHA256 2ded8371da50f1dda825b654120f239b535479c9c602f32091ca7be7825cde01
MD5 76c74d3876a49954ab24aea6acaa4999
BLAKE2b-256 52f39bb3dcb92ef5b92c6026ddb6b6b9d4fdea5de83169b66a138422e2983a43

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