User Guide

Welcome to the pyc_logo PyC User Guide! This guide will help you get started with PyTorch Concepts and build interpretable deep learning models.

Explore Based on Your Background

pyc_logo PyC is designed to accommodate users with different backgrounds and expertise levels. Pick the best entry point based on your experience:

Pure torch user?

Start from the Low-Level API to build models from basic interpretable layers.

Interpretable Layers and Interventions
Probabilistic modeling user?

Start from the Mid-Level API to build custom probabilistic models.

Interpretable Probabilistic Models
Causal modeling user?

Start from the Mid-Level API to build Structural Equation Models for causal inference.

Structural Equation Models
Just want to use state-of-the-art models out-of-the-box?

Start from the High-Level API to use pre-defined models with one line of code.

Out-of-the-box Models
No experience with programming?

Use conceptarium_logo Conceptarium, a no-code framework built on top of pyc_logo PyC for running large-scale experiments on concept-based models.

Conceptarium

Quick Start Example

Here’s a minimal example using the low-Level API:

import torch
import torch_concepts as pyc

# Create a concept bottleneck model
model = torch.nn.ModuleDict({
    'encoder': pyc.nn.LinearZC(
        in_features=64,
        out_features=10
    ),
    'predictor': pyc.nn.LinearCC(
        in_features_endogenous=10,
        out_features=5
    ),
})

# Forward pass
x = torch.randn(32, 64)
concepts = model['encoder'](input=x)
predictions = model['predictor'](endogenous=concepts)

For complete examples with training, interventions, and evaluation, see the individual API guides above.

Additional Resources

Examples

Check out complete examples for real-world use cases.

Need Help?