A robust SHAP explainer wrapper for PyTorch Geometric models.
Project description
PyG-Captum-SHAP
A robust wrapper bridging the Euclidean sampling mechanisms of Captum with the non-Euclidean batching of PyTorch Geometric (PyG).
Designed specifically for molecular QSAR modelling, this library solves the dimension mismatch errors (e.g., Expected size 2, got 10) that occur when using Captum on Graph Neural Networks.
Key Features
- Dictionary-Shielded Wrapper: Protects structural tensors (
edge_index) from corruption during Captum sampling. - Multi-Input Support: Generate attributions for Nodes (Atoms), Edges (Bonds), and Global Molecular Features simultaneously.
- Automatic Reconstruction: On-the-fly reconstruction of block-diagonal graph batches for Captum's internal forward passes.
Installation
pip install pyg-captum-shap
Quick Start
from pyg_captum_shap import compute_shap_values
# Extract attributions for a specific molecule and task
results = compute_shap_values(
model=your_trained_model,
target_graph=molecule_graph_data,
target_task=0,
n_samples=25
)
# Access node, edge, and global SHAP values
node_importance = results['nodes'] # Shape: [N, F]
edge_importance = results.get('edges') # Optional
global_importance = results.get('global') # Optional
# node_attributions now contains the importance score for every atom in the graph
License
Distributed under the MIT License. Built on top of the Captum library by PyTorch.
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
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 pyg_captum_shap-0.1.5.tar.gz.
File metadata
- Download URL: pyg_captum_shap-0.1.5.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a2f90e297d13aca36436a5fce2fbe0b7d31796c29e2ec4de9d6014f25aa7484
|
|
| MD5 |
f000058469bd3c19d89bb334c914087e
|
|
| BLAKE2b-256 |
9e03c2fdd27a731504b4ee9eba52ead4369cb596624dede82c0320672055022f
|
File details
Details for the file pyg_captum_shap-0.1.5-py3-none-any.whl.
File metadata
- Download URL: pyg_captum_shap-0.1.5-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
684af58ccc7470b5cd7bc699d3fb1c48ecd5e6c6052dd9f3c5957219fcedf8e6
|
|
| MD5 |
25bec0056f67cc55198bb624d4bbe745
|
|
| BLAKE2b-256 |
4f6529c5f8d5cc0057cbb7b44a8848afdc91157d45033ddb08a3a9f25fae5cae
|