Skip to main content

Unified XAI: An Explainable AI library for interpretable machine learning, Deep Learning and Artifical Intelligence.

Project description

Unified XAI

Production-Ready Explainable AI Library for Deep Learning

PyPI version Python License Documentation Tests

Code style: black

Documentation | Tutorials | API Reference | Paper


๐ŸŽฏ 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

๐Ÿ—บ๏ธ Roadmap

  • Support for Vision Transformers
  • Additional evaluation metrics
  • Model-specific explanations
  • Distributed computing support
  • AutoML integration
  • Mobile deployment

Made with โค๏ธ by the Satyam Singh

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

unified_xai-0.1.0.tar.gz (28.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

unified_xai-0.1.0-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

Details for the file unified_xai-0.1.0.tar.gz.

File metadata

  • Download URL: unified_xai-0.1.0.tar.gz
  • Upload date:
  • Size: 28.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for unified_xai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6bb585644ec18ce9cd800fca1954b4fb1517e0a5c0ba48fee08d3d18efe6f142
MD5 3bada3ecece0cc1a1e092f7ed27c3d8a
BLAKE2b-256 40513bd12a8f95c19aedc150699aa3b48ec0695119c003f265606afc099d5250

See more details on using hashes here.

File details

Details for the file unified_xai-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: unified_xai-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for unified_xai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 46f4a8b7543f4dcd07d70ce1b09b041f3659a5fb8c371cbc2a5fd06af1d9f7c8
MD5 821269d3f62ab43d3b909438a8eb0492
BLAKE2b-256 19718ff811411758eefa337ce1150167675039bfb5c20ab8395e5a04d785a8b7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page