Concept-Based Deep Learning Library for PyTorch.
Project description
🚀 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 asPyTorch 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.
Contributing
Contributions are welcome! Please check our contributing guidelines to get started.
Thanks to all contributors! 🧡
External Contributors
- Sonia Laguna, ETH Zurich (CH).
- Moritz Vandenhirtz, ETH Zurich (CH).
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:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytorch_concepts-1.0.0a3.tar.gz.
File metadata
- Download URL: pytorch_concepts-1.0.0a3.tar.gz
- Upload date:
- Size: 286.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba8c0f06e4c96cc6a383d9243238943456ec3c7fb7d107bf5a5f030d2d170298
|
|
| MD5 |
a7b020154dbcb733e3928aafd8def3e7
|
|
| BLAKE2b-256 |
79133b73fc699a78902890bf7da973b7c256527e0155e9aa1911ffc4074e5b34
|
File details
Details for the file pytorch_concepts-1.0.0a3-py3-none-any.whl.
File metadata
- Download URL: pytorch_concepts-1.0.0a3-py3-none-any.whl
- Upload date:
- Size: 355.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd4a4929126c4b0944e572dfe1100c9204fbd5cf96565572f7ddf530aed07ef5
|
|
| MD5 |
1a249bf614ca5f2b6bba66bede4d92bd
|
|
| BLAKE2b-256 |
d1722882047ee4d875b75ae18770226e73294d91b724400f9c8cb73481217510
|