Welcome to the SymTorch Documentation

SymTorch logo. Visual example of SymbolicMLP.

SymTorch is an interpretability toolkit that uses symbolic regression to reveal the behaviour of black-box models.

Installation

SymTorch is available on PyPI:

pip install torch-symbolic

Overview

SymTorch combines PyTorch (neural networks) with PySR (symbolic regression) to automatically extract human-readable formulas from trained models. Instead of treating models as black boxes, it reveals the underlying mathematical relationships they’ve discovered.

The SymbolicModel Class

All functionality is accessed through the unified SymbolicModel class, which supports four operational modes:

  1. Layer-Level Mode - Wraps individual PyTorch layers within larger deep learning models - Discovers symbolic equations approximating the behavior of specific layers - Can switch between the original layer and symbolic equations during forward pass and training - See the Getting Started Demo

  2. Model-Agnostic Mode - Works with any callable function (PyTorch, TensorFlow, scikit-learn, or pure Python) - Approximates end-to-end model behavior with symbolic equations - Framework-independent approach to symbolic regression - Activated by passing a callable function to the constructor - See the Getting Started Demo

  3. SLIME Mode (Local Interpretability) - Model-agnostic approach to approximating behavior around specific data points - Symbolic extension of Local Interpretable Model-Agnostic Explanations (LIME) - Provides more expressive local explanations than linear models - Activated by passing SLIME=True and slime_params to distill() - See the SLIME Demo

  4. Pruning Capabilities - Automatically identifies and removes less important output dimensions - Works on a layer-level basis during training - Encourages models to learn simpler and more interpretable patterns - Activated by calling setup_pruning() before training - See the Pruning Demo

Contents

Documentation: