Unified XAI
Production-Ready Explainable AI Library for Deep Learning
Documentation | Tutorials | API Reference
🎯 Overview
Unified XAI is a comprehensive, production-ready library for explaining deep learning models across multiple frameworks and modalities. It provides a unified API for various explainability methods, making it easy to understand, debug, and improve your AI models.
✨ Key Features
- 🔄 Framework Agnostic: Seamless support for PyTorch, TensorFlow, Keras, and ONNX
- 📊 Multiple Modalities: Image, text, tabular, time-series, and multimodal data
- 🎨 Rich Visualizations: Interactive plots, heatmaps, and dashboards
- 📈 Comprehensive Metrics: Faithfulness, stability, complexity evaluations
- ⚡ High Performance: Optimized implementations with caching and parallelization
- 🔧 Production Ready: Type hints, extensive testing, and robust error handling
- 🚀 Easy to Use: Simple API with sensible defaults
- 📦 Extensible: Plugin architecture for custom methods
🚀 Quick Start
Installation
# Basic installation
pip install unified-xai
# With specific framework support
pip install unified-xai[torch] # PyTorch support
pip install unified-xai[tf] # TensorFlow support
pip install unified-xai[all] # All frameworks
# Development installation
pip install unified-xai[dev]
# With dashboard support
pip install unified-xai[dashboard]
Basic Usage
import torch
from unified_xai import XAIAnalyzer, XAIConfig
from unified_xai.config import Framework, Modality
# Load your model
model = torch.load('your_model.pth')
# Configure XAI
config = XAIConfig(
framework=Framework.PYTORCH,
modality=Modality.IMAGE
)
# Initialize analyzer
analyzer = XAIAnalyzer(model, config)
# Generate explanation
explanation = analyzer.explain(
input_data,
method='integrated_gradients',
target=class_idx
)
# Visualize
fig = analyzer.visualize(explanation, original_input=input_data)
📚 Supported Methods
Gradient-Based Methods
- ✅ Vanilla Gradient
- ✅ Integrated Gradients
- ✅ SmoothGrad
- ✅ Grad-CAM / Grad-CAM++
- ✅ Guided Backpropagation
- ✅ DeepLIFT
Perturbation-Based Methods
- ✅ LIME (Local Interpretable Model-agnostic Explanations)
- ✅ SHAP (SHapley Additive exPlanations)
- ✅ Occlusion Sensitivity
- ✅ Meaningful Perturbations
Attention-Based Methods
- ✅ Attention Rollout
- ✅ Attention Flow
- ✅ LRP (Layer-wise Relevance Propagation)
Example-Based Methods
- ✅ Influence Functions
- ✅ Prototype Selection
- ✅ Counterfactual Explanations
🎯 Use Cases
Computer Vision
# Explain image classification
explanation = analyzer.explain(image, method='gradcam')
# Compare multiple methods
comparison = analyzer.compare_methods(
image,
methods=['gradcam', 'integrated_gradients', 'lime'],
metrics=['faithfulness', 'complexity']
)
Natural Language Processing
# Explain text classification
config = XAIConfig(framework=Framework.PYTORCH, modality=Modality.TEXT)
analyzer = XAIAnalyzer(bert_model, config)
explanation = analyzer.explain(
text_tokens,
method='integrated_gradients'
)
Tabular Data
# Explain tabular predictions
config = XAIConfig(modality=Modality.TABULAR)
analyzer = XAIAnalyzer(model, config)
explanation = analyzer.explain(
tabular_data,
method='shap',
background_data=train_data
)
📊 Evaluation Metrics
Unified XAI provides comprehensive metrics to evaluate explanation quality:
# Evaluate explanation
metrics = analyzer.evaluator.evaluate(
explanation,
input_data,
metrics=['faithfulness', 'stability', 'complexity', 'sensitivity']
)
# Compare methods quantitatively
rankings = analyzer.compare_methods(
input_data,
methods=['gradcam', 'lime', 'shap'],
metrics=['faithfulness', 'stability']
)
🎨 Visualization Dashboard
Launch interactive dashboard for exploration:
# Command line
unified-xai dashboard --model path/to/model --port 8080
# Or in Python
from unified_xai.dashboard import launch_dashboard
launch_dashboard(model, port=8080)
🏗️ Architecture
unified-xai/
├── core/ # Core abstractions and base classes
├── methods/ # Explanation method implementations
│ ├── gradient/ # Gradient-based methods
│ ├── perturbation/ # Perturbation-based methods
│ ├── attention/ # Attention-based methods
│ └── example/ # Example-based methods
├── frameworks/ # Framework-specific adapters
├── visualization/ # Visualization utilities
├── metrics/ # Evaluation metrics
├── utils/ # Helper utilities
└── dashboard/ # Web dashboard
🔧 Configuration
Unified XAI supports various configuration options:
# From file
config = XAIConfig.from_file('config.yaml')
# Programmatic
config = XAIConfig(
framework=Framework.PYTORCH,
modality=Modality.IMAGE,
gradient_config={
'normalize': True,
'smooth_samples': 50
},
visualization_config={
'cmap': 'RdBu_r',
'overlay': True
}
)
Example config.yaml:
framework: pytorch
modality: image
batch_size: 32
device: cuda
gradient_config:
normalize: true
smooth_samples: 50
lime_config:
num_samples: 1000
num_features: 10
visualization_config:
cmap: RdBu_r
alpha: 0.7
🧪 Testing
# Run all tests
pytest
# Run with coverage
pytest --cov=unified_xai
# Run specific test module
pytest tests/test_methods.py
# Run benchmarks
pytest tests/benchmarks/ --benchmark-only
📖 Documentation
Full documentation is available at https://unified-xai.readthedocs.io
🤝 Contributing
We welcome contributions! Please see our Contributing Guide for details.
# Setup development environment
git clone https://github.com/yourusername/unified-xai.git
cd unified-xai
pip install -e ".[dev]"
pre-commit install
# Run checks before committing
make lint
make test
make docs
📊 Benchmarks
Performance comparisons across different methods and frameworks:
| Method | PyTorch (ms) | TensorFlow (ms) | Accuracy |
|---|---|---|---|
| Integrated Gradients | 45 | 52 | 0.94 |
| LIME | 890 | 920 | 0.89 |
| SHAP | 340 | 380 | 0.91 |
| Grad-CAM | 23 | 28 | 0.87 |
🎓 Citation
If you use Unified XAI in your research, please cite:
@software{unified_xai,
title = {Unified XAI: A Production-Ready Explainable AI Library},
author = {Satyam Singh},
year = {2025},
url = {https://github.com/SatyamSingh8306/unified-xai}
}
📝 License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
🙏 Acknowledgments
- Thanks to all contributors and the open-source community
- Inspired by Captum, SHAP, LIME, and other XAI libraries
- Supported by [Your Organization]
📬 Contact
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: satyamsingh7734@gmail.com
- Twitter: @unified_xai
🗺️ Roadmap
- Support for Vision Transformers
- Additional evaluation metrics
- Model-specific explanations
- Distributed computing support
- AutoML integration
- Mobile deployment
Metadata
Release files for unified-xai 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| unified_xai-0.1.1.tar.gz | 28.7 kB | Without provenance | Details for unified_xai-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| unified_xai-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for unified_xai-0.1.1-py3-none-any.whl |
Total release size: 46.1 kB
Release files / unified_xai-0.1.1.tar.gz
| Download URL | unified_xai-0.1.1.tar.gz |
|---|---|
| Size | 28.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
740d9119f1d7a4f09a062146841a1869c2f4af3899a0fda85ce98b3c02ac0eab
|
|
BLAKE2b-256 checksum How to use checksums |
760f27918d9de6f50c1fc13b9049decfa38cb297c91da58a2f09687f4c8e6cab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.1
|
Release files / unified_xai-0.1.1-py3-none-any.whl
| Download URL | unified_xai-0.1.1-py3-none-any.whl |
|---|---|
| Size | 17.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a43f1116991a89af6603cf546028a5ff7788562b208652a8d727c09f9dbf421f
|
|
BLAKE2b-256 checksum How to use checksums |
c2d85efff8be016a59c6d2b5e582c50540005f258132309a7b0edd66b6656345
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.1
|
Security for unified-xai 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.