# deel-ai/xplique architecture

> Architecture diagram of the GitHub repository deel-ai/xplique, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/deel-ai/xplique
- Repository: https://github.com/deel-ai/xplique

## Overview

1. Xplique is a Python explainability toolkit organized as a single distributable package, `xplique`, with a strong TensorFlow-first core and a narrower PyTorch compatibility layer. The repo is structured around four user-facing analytical domains: attributions, attribution metrics, concepts, and example-based explanations, plus feature visualization and plotting.

2. The shared foundation lives in `xplique.commons`, `xplique.types`, and `xplique.utils_functions`. These modules provide the cross-cutting abstractions that the explanation methods build on: model-call normalization, data conversion, operator composition, callable wrappers, and task-specific helpers for object detection and segmentation. This is the main internal boundary that keeps the higher-level explainers model-agnostic.

3. The attribution subsystem is the largest part of the library. `xplique.attributions` contains gradient-based, perturbation-based, and sampling-based methods such as Saliency, Grad-CAM, Integrated Gradients, LIME, Kernel SHAP, Occlusion, RISE, SmoothGrad, and global sensitivity methods like Sobol and HSIC. The important architectural pattern is that each explainer exposes a common “explain”/call interface and delegates common mechanics to `base.py`, `gradient_statistics`, and `global_sensitivity_analysis`.

4. Attribution methods are designed around task boundaries rather than a single prediction type. The README and docs show explicit support for classification, regression, object detection, and semantic segmentation, with some methods only valid for specific tasks. Internally this means the attribution layer must adapt target handling, mask generation, and model-output interpretation depending on the task.

5. The metrics subsystem in `xplique.metrics` consumes explanations as inputs and evaluates their quality against the model and dataset. It covers fidelity, stability, complexity, randomization, and representativity metrics, with implementations such as Deletion, Insertion, Average Drop/Increase/Gain, MuFidelity, MeGe, and model randomization. Architecturally, this is a downstream consumer of attribution outputs rather than a parallel explanation generator.

6. The concepts subsystem in `xplique.concepts` extracts human-interpretable concepts from models. `CAV` and `TCAV` operate on positive/negative concept datasets, while `CRAFT` is split into TensorFlow and PyTorch variants and uses a manager layer to coordinate concept extraction, importance estimation, and crop visualization. This module bridges model internals and external concept datasets, so its main boundary is between representation extraction and concept scoring.

7. The example-based subsystem in `xplique.example_based` explains a prediction by searching a dataset for relevant examples. It is divided into dataset harmonization/conversion utilities, projection methods, and search methods for similar examples, counterfactuals, semifactuals, and prototypes. The core data flow here is query sample + reference dataset -> embedding/projection or similarity space -> ranked example outputs.

8. Feature visualization lives in `xplique.features_visualizations` and is centered on optimization over inputs. It combines objectives, losses, regularizers, transformations, and preconditioning to synthesize inputs that maximize neurons, channels, layers, or custom objectives. This subsystem is optimizer-driven rather than model-output driven, so its main boundary is input synthesis rather than post-hoc interpretation.

9. `xplique.plots` is a presentation layer for results from the other subsystems. It includes image, tabular, timeseries, and metrics plotting helpers, indicating that outputs are expected to be rendered in multiple modalities, not just images. This module sits at the edge of the library and converts explanation/metric objects into human-readable visualizations.

10. PyTorch support is intentionally isolated in `xplique.wrappers.pytorch.TorchWrapper` and in the PyTorch-specific branches of several explainers/metrics. The README makes clear that TensorFlow remains the primary runtime, while PyTorch is supported through wrappers and selective method implementations. That makes the framework boundary explicit: the core abstractions normalize model access, and the wrapper adapts PyTorch models into that contract.

11. The tests mirror the package structure very closely, which is a useful indicator of the architecture. There are dedicated test suites for attributions, commons, concepts, example-based methods, feature visualizations, metrics, plots, wrappers, and utilities. This suggests each subsystem is intended to be independently verifiable and loosely coupled through shared abstractions.

12. Tooling and delivery are handled as a standard Python package with strong project hygiene. `pyproject.toml`, `tox.ini`, `Makefile`, and `.pre-commit-config.yaml` support packaging, linting, and local automation; GitHub Actions handle tests, linting, torch-specific checks, documentation deployment, and publishing to PyPI. Documentation is a major part of the repo, generated from `mkdocs.yml` and the `docs/` tree, with API pages organized exactly by subsystem.

Main entry points: [`xplique/plots/__init__.py`](https://github.com/deel-ai/xplique/blob/master/xplique/plots/__init__.py) (Plots), [`xplique/attributions/__init__.py`](https://github.com/deel-ai/xplique/blob/master/xplique/attributions/__init__.py) (Attributions), [`xplique/attributions/base.py`](https://github.com/deel-ai/xplique/blob/master/xplique/attributions/base.py) (Attr base), [`xplique/commons/__init__.py`](https://github.com/deel-ai/xplique/blob/master/xplique/commons/__init__.py) (Commons)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Core foundation"]
  node_xplique_commons["Commons<br/>core abstractions<br/>[__init__.py]"]
  node_xplique_types["Types<br/>type defs<br/>[__init__.py]"]
  node_xplique_utils["Utilities<br/>task helpers<br/>[__init__.py]"]
  node_xplique_torch["Torch wrapper<br/>runtime adapter<br/>[pytorch.py]"]
end

subgraph group_explainers["Explanation engines"]
  node_attributions_api["Attributions<br/>explanation api<br/>[__init__.py]"]
  node_attr_base["Attr base<br/>attribution core<br/>[base.py]"]
  node_grad_stats["Grad stats<br/>gradient methods<br/>[__init__.py]"]
  node_gsa["GSA<br/>global sensitivity<br/>[__init__.py]"]
  node_metrics_api["Metrics<br/>evaluation api<br/>[__init__.py]"]
  node_metrics_base["Metric base<br/>metric core<br/>[base.py]"]
  node_concepts_api["Concepts<br/>concept api<br/>[__init__.py]"]
  node_concepts_base["Concept base<br/>concept core<br/>[base.py]"]
  node_craft_mgr["CRAFT mgr<br/>concept pipeline<br/>[craft_manager.py]"]
  node_example_api["Examples<br/>example-based api<br/>[__init__.py]"]
  node_example_base["Example base<br/>example core"]
  node_projections["Projections<br/>embedding space<br/>[__init__.py]"]
  node_search["Search<br/>retrieval methods<br/>[__init__.py]"]
end

subgraph group_synthesis["Input synthesis"]
  node_featviz_api["Feature viz<br/>synthesis api<br/>[__init__.py]"]
  node_featviz_opt["Optimizer<br/>synthesis core<br/>[optim.py]"]
end

subgraph group_presentation["Presentation"]
  node_plots_api["Plots<br/>presentation api<br/>[__init__.py]"]
end

node_xplique_torch -->|"adapts to"| node_xplique_commons
node_xplique_utils -->|"extends"| node_xplique_commons
node_xplique_types -->|"supports"| node_xplique_commons
node_attributions_api -->|"routes through"| node_attr_base
node_attr_base -->|"depends on"| node_xplique_commons
node_grad_stats -->|"specializes"| node_attr_base
node_gsa -->|"specializes"| node_attr_base
node_attributions_api -->|"exposes"| node_grad_stats
node_attributions_api -->|"exposes"| node_gsa
node_metrics_api -->|"routes through"| node_metrics_base
node_metrics_base -->|"consumes"| node_attributions_api
node_concepts_api -->|"routes through"| node_concepts_base
node_craft_mgr -->|"coordinates"| node_concepts_base
node_example_api -->|"routes through"| node_example_base
node_example_base -->|"uses"| node_projections
node_example_base -->|"uses"| node_search
node_featviz_api -->|"drives"| node_featviz_opt
node_plots_api -->|"renders"| node_attributions_api
node_plots_api -->|"renders"| node_metrics_api
node_plots_api -->|"renders"| node_example_api
node_plots_api -->|"renders"| node_concepts_api
node_plots_api -->|"renders"| node_featviz_api

click node_xplique_commons "https://github.com/deel-ai/xplique/blob/master/xplique/commons/__init__.py"
click node_xplique_types "https://github.com/deel-ai/xplique/blob/master/xplique/types/__init__.py"
click node_xplique_utils "https://github.com/deel-ai/xplique/blob/master/xplique/utils_functions/__init__.py"
click node_xplique_torch "https://github.com/deel-ai/xplique/blob/master/xplique/wrappers/pytorch.py"
click node_attributions_api "https://github.com/deel-ai/xplique/blob/master/xplique/attributions/__init__.py"
click node_attr_base "https://github.com/deel-ai/xplique/blob/master/xplique/attributions/base.py"
click node_grad_stats "https://github.com/deel-ai/xplique/blob/master/xplique/attributions/gradient_statistics/__init__.py"
click node_gsa "https://github.com/deel-ai/xplique/blob/master/xplique/attributions/global_sensitivity_analysis/__init__.py"
click node_metrics_api "https://github.com/deel-ai/xplique/blob/master/xplique/metrics/__init__.py"
click node_metrics_base "https://github.com/deel-ai/xplique/blob/master/xplique/metrics/base.py"
click node_concepts_api "https://github.com/deel-ai/xplique/blob/master/xplique/concepts/__init__.py"
click node_concepts_base "https://github.com/deel-ai/xplique/blob/master/xplique/concepts/base.py"
click node_craft_mgr "https://github.com/deel-ai/xplique/blob/master/xplique/concepts/craft_manager.py"
click node_example_api "https://github.com/deel-ai/xplique/blob/master/xplique/example_based/__init__.py"
click node_example_base "https://github.com/deel-ai/xplique/blob/master/xplique/example_based/base_example_method.py"
click node_projections "https://github.com/deel-ai/xplique/blob/master/xplique/example_based/projections/__init__.py"
click node_search "https://github.com/deel-ai/xplique/blob/master/xplique/example_based/search_methods/__init__.py"
click node_featviz_api "https://github.com/deel-ai/xplique/blob/master/xplique/features_visualizations/__init__.py"
click node_featviz_opt "https://github.com/deel-ai/xplique/blob/master/xplique/features_visualizations/optim.py"
click node_plots_api "https://github.com/deel-ai/xplique/blob/master/xplique/plots/__init__.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_xplique_commons,node_xplique_types,node_xplique_utils,node_xplique_torch toneBlue
class node_attributions_api,node_attr_base,node_grad_stats,node_gsa,node_metrics_api,node_metrics_base,node_concepts_api,node_concepts_base,node_craft_mgr,node_example_api,node_example_base,node_projections,node_search toneAmber
class node_featviz_api,node_featviz_opt toneMint
class node_plots_api toneRose
```

## Components

### Core foundation

Shared abstractions, type helpers, and runtime adapters used across explainers.

- [Commons](https://github.com/deel-ai/xplique/blob/master/xplique/commons/__init__.py): core abstractions · Model-call normalization, data conversion, operators, and callable wrappers. · `xplique/commons/__init__.py`
- [Types](https://github.com/deel-ai/xplique/blob/master/xplique/types/__init__.py): type defs · Shared custom types and runtime contracts. · `xplique/types/__init__.py`
- [Utilities](https://github.com/deel-ai/xplique/blob/master/xplique/utils_functions/__init__.py): task helpers · Task-specific helpers for object detection and segmentation. · `xplique/utils_functions/__init__.py`
- [Torch wrapper](https://github.com/deel-ai/xplique/blob/master/xplique/wrappers/pytorch.py): runtime adapter · PyTorch-to-core adapter that normalizes model access. · `xplique/wrappers/pytorch.py`

### Explanation engines

Primary analytical subsystems that generate explanations or scores.

- [Attributions](https://github.com/deel-ai/xplique/blob/master/xplique/attributions/__init__.py): explanation api · User-facing attribution entrypoint spanning gradient, perturbation, and sampling methods. · `xplique/attributions/__init__.py`
- [Attr base](https://github.com/deel-ai/xplique/blob/master/xplique/attributions/base.py): attribution core · Common explain/call mechanics shared by attribution methods. · `xplique/attributions/base.py`
- [Grad stats](https://github.com/deel-ai/xplique/blob/master/xplique/attributions/gradient_statistics/__init__.py): gradient methods · SmoothGrad, VarGrad, and related gradient-statistics explainers. · `xplique/attributions/gradient_statistics/__init__.py`
- [GSA](https://github.com/deel-ai/xplique/blob/master/xplique/attributions/global_sensitivity_analysis/__init__.py): global sensitivity · Sobol and HSIC attribution machinery with samplers, estimators, and perturbations. · `xplique/attributions/global_sensitivity_analysis/__init__.py`
- [Metrics](https://github.com/deel-ai/xplique/blob/master/xplique/metrics/__init__.py): evaluation api · Downstream quality metrics for explanations. · `xplique/metrics/__init__.py`
- [Metric base](https://github.com/deel-ai/xplique/blob/master/xplique/metrics/base.py): metric core · Shared evaluation scaffolding for fidelity, stability, complexity, and randomization. · `xplique/metrics/base.py`
- [Concepts](https://github.com/deel-ai/xplique/blob/master/xplique/concepts/__init__.py): concept api · User-facing concept extraction and scoring entrypoint. · `xplique/concepts/__init__.py`
- [Concept base](https://github.com/deel-ai/xplique/blob/master/xplique/concepts/base.py): concept core · Shared concept-extraction and scoring abstractions. · `xplique/concepts/base.py`
- [CRAFT mgr](https://github.com/deel-ai/xplique/blob/master/xplique/concepts/craft_manager.py): concept pipeline · Coordinates concept extraction, importance estimation, and crop visualization. · `xplique/concepts/craft_manager.py`
- [Examples](https://github.com/deel-ai/xplique/blob/master/xplique/example_based/__init__.py): example-based api · User-facing similar-example, counterfactual, semifactual, and prototype methods. · `xplique/example_based/__init__.py`
- [Example base](https://github.com/deel-ai/xplique/blob/master/xplique/example_based/base_example_method.py): example core · Shared query-to-dataset explanation workflow. · `xplique/example_based/base_example_method.py`
- [Projections](https://github.com/deel-ai/xplique/blob/master/xplique/example_based/projections/__init__.py): embedding space · Projection and harmonization layer for reference data and queries. · `xplique/example_based/projections/__init__.py`
- [Search](https://github.com/deel-ai/xplique/blob/master/xplique/example_based/search_methods/__init__.py): retrieval methods · Nearest-neighbor, prototype, and counterfactual search strategies. · `xplique/example_based/search_methods/__init__.py`

### Input synthesis

Optimization-driven feature visualization pipeline.

- [Feature viz](https://github.com/deel-ai/xplique/blob/master/xplique/features_visualizations/__init__.py): synthesis api · Optimization-driven input synthesis entrypoint. · `xplique/features_visualizations/__init__.py`
- [Optimizer](https://github.com/deel-ai/xplique/blob/master/xplique/features_visualizations/optim.py): synthesis core · Objectives, losses, regularizers, transformations, and preconditioning. · `xplique/features_visualizations/optim.py`

### Presentation

Plotting and reporting layer for explanation outputs.

- [Plots](https://github.com/deel-ai/xplique/blob/master/xplique/plots/__init__.py): presentation api · Rendering helpers for images, tables, timeseries, and metrics. · `xplique/plots/__init__.py`

## Connections

- Torch wrapper → Commons: adapts to · PyTorch models are normalized into the shared model interface.
- Utilities → Commons: extends · Task helpers build on the shared callable and conversion utilities.
- Types → Commons: supports · Type definitions back the core contracts used throughout the package.
- Attributions → Attr base: routes through · The attribution API delegates common execution to the base layer.
- Attr base → Commons: depends on · Attribution methods rely on common model and data abstractions.
- Grad stats → Attr base: specializes · Gradient-statistics explainers reuse the attribution base mechanics.
- GSA → Attr base: specializes · Global-sensitivity methods share the attribution base contract.
- Attributions → Grad stats: exposes · Gradient-statistics methods are part of the public attribution surface.
- Attributions → GSA: exposes · Global sensitivity methods are part of the public attribution surface.
- Metrics → Metric base: routes through · Metric entrypoints delegate to shared evaluation scaffolding.
- Metric base → Attributions: consumes · Metrics evaluate explanation outputs produced by attribution methods.
- Concepts → Concept base: routes through · Concept methods share a common concept-extraction foundation.
- CRAFT mgr → Concept base: coordinates · CRAFT management builds on the concept base abstractions.
- Examples → Example base: routes through · Example-based methods share the query-and-search workflow.
- Example base → Projections: uses · Example explanations often project data into a comparison space.
- Example base → Search: uses · Ranked example selection is handled by search strategies.
- Feature viz → Optimizer: drives · Feature visualization is optimization-driven around objectives and regularization.
- Plots → Attributions: renders · Plots visualize explanation outputs from the analytical subsystems.
- Plots → Metrics: renders · Plots also present evaluation metrics.
- Plots → Examples: renders · Plots cover example-based explanation outputs as well.
- Plots → Concepts: renders · Plots can present concept-analysis results.
- Plots → Feature viz: renders · Plots support synthesized feature-visualization outputs.
