How feedzai/timeshap works
TimeSHAP is a model-agnostic explainer for recurrent sequence models. A user supplies sequences, a background instance, and a callable model interface; local workflows produce pruning and event, feature, or cell attributions, while global workflows aggregate explanations across instances. The shared KernelSHAP-based engine supports these explanation stages, and plotting/report modules present their results. PyTorch and TensorFlow wrappers adapt model inputs and predictions. Edges reflect README documentation and SOURCE INDEX references; unsampled implementations are represented only where their capabilities or connections are documented.
Main entry points: pruning.py Pruning · event_level.py Event attribution · local_methods.py Local report · global_methods.py Global report
Components 22
Model interfaces
- PyTorch wrapper
src/timeshap/wrappers/torch_wrappers.py - TensorFlow wrapper
src/timeshap/wrappers/tf_wrappers.py - Wrapper base
src/timeshap/wrappers/base_wrapper.py
Attribution engine
- TimeSHAP kernel
src/timeshap/explainer/kernel/timeshap_kernel.py
Explanation workflows
- Pruning
src/timeshap/explainer/pruning.py - Event attribution
src/timeshap/explainer/event_level.py - Feature attribution
src/timeshap/explainer/feature_level.py - Cell attribution
src/timeshap/explainer/cell_level.py - Local report
src/timeshap/explainer/local_methods.py - Global report
src/timeshap/explainer/global_methods.py
Reports and plots
- Pruning plots
src/timeshap/plot/pruning.py - Event plots
src/timeshap/plot/event_level.py - Feature plots
src/timeshap/plot/feature_level.py - Cell plots
src/timeshap/plot/cell_level.py - Local report plots
src/timeshap/plot/local_report.py - Global report plots
src/timeshap/plot/global_report.py
Shared support
- SHAP compatibility
src/timeshap/utils/timeshap_legacy.py - Plot utilities
src/timeshap/plot/utils.py - Data utilities
src/timeshap/utils/utils.py - Model compatibility
src/timeshap/utils/compatibility.py
Other components
- Analyst
- Sequence model
Connections 31
- Analyst → Local report: requests local
README.md - Analyst → Global report: requests global
README.md - PyTorch wrapper → Wrapper base: extends
src/timeshap/wrappers/base_wrapper.py - PyTorch wrapper → Sequence model: predicts with
src/timeshap/wrappers/torch_wrappers.py - TensorFlow wrapper → Sequence model: adapts callable
README.md - Analyst → Sequence model: provides callable
README.md - Pruning → TimeSHAP kernel: uses
src/timeshap/explainer/pruning.py - Event attribution → TimeSHAP kernel: uses
src/timeshap/explainer/event_level.py - Feature attribution → TimeSHAP kernel: uses
src/timeshap/explainer/feature_level.py - Cell attribution → TimeSHAP kernel: uses
src/timeshap/explainer/cell_level.py - TimeSHAP kernel → SHAP compatibility: converts data
src/timeshap/explainer/kernel/timeshap_kernel.py - Local report → Pruning: calculates
src/timeshap/explainer/local_methods.py - Local report → Event attribution: calculates
src/timeshap/explainer/local_methods.py - Local report → Feature attribution: calculates
src/timeshap/explainer/local_methods.py - Local report → Local report plots: plots report
src/timeshap/explainer/local_methods.py - Global report → Pruning: aggregates
src/timeshap/explainer/global_methods.py - Global report → Event attribution: aggregates
src/timeshap/explainer/global_methods.py - Global report → Feature attribution: aggregates
src/timeshap/explainer/global_methods.py - Global report → Global report plots: plots report
src/timeshap/explainer/global_methods.py - Pruning → Pruning plots: results plotted by
README.md - Event attribution → Event plots: results plotted by
README.md - Feature attribution → Feature plots: results plotted by
README.md - Cell attribution → Cell plots: results plotted by
README.md - Event plots → Plot utilities: uses
src/timeshap/plot/event_level.py - Feature plots → Plot utilities: uses
src/timeshap/plot/feature_level.py - Local report plots → Pruning: renders
src/timeshap/plot/local_report.py - Global report plots → Event attribution: renders
src/timeshap/plot/global_report.py - PyTorch wrapper → Model compatibility: uses compatibility
src/timeshap/wrappers/__init__.py - Pruning → Data utilities: uses data helpers
src/timeshap/explainer/pruning.py - Event attribution → Data utilities: uses data helpers
src/timeshap/explainer/event_level.py - Feature attribution → Data utilities: uses data helpers
src/timeshap/explainer/feature_level.py