Skip to main content
Xplique


🦊 Xplique (pronounced \ɛks.plik\) is a Python toolkit dedicated to explainability, currently based on Tensorflow. The goal of this library is to gather the state of the art of Explainable AI to help you understand your complex neural network models.
Explore Xplique docs »

Attributions · Concept · Feature Visualization · Metrics

The library is composed of several modules, the Attributions Methods module implements various methods (e.g Saliency, Grad-CAM, Integrated-Gradients...), with explanations, examples and links to official papers. The Feature Visualization module allows to see how neural networks build their understanding of images by finding inputs that maximize neurons, channels, layers or compositions of these elements. The Concepts module allows you to extract human concepts from a model and to test their usefulness with respect to a class. Finally, the Metrics module covers the current metrics used in explainability. Used in conjunction with the Attribution Methods module, it allows you to test the different methods or evaluate the explanations of a model.


📚 Table of contents

🚀 Quick Start

Xplique requires a version of python higher than 3.6 and several libraries including Tensorflow and Numpy. Installation can be done using Pypi:

pip install xplique

Now that Xplique is installed, here are 4 basic examples of what you can do with the available modules.

Attributions Methods

let's start with a simple example, by computing Grad-CAM for several images (or a complete dataset) on a trained model.

from xplique.attributions import GradCAM

# load images, labels and model
# ...

explainer = GradCAM(model)
explanations = explainer.explain(images, labels)
# or just `explainer(images, labels)`

Attributions Metrics

In order to measure if the explanations provided by our method are faithful (it reflects well the functioning of the model) we can use a fidelity metric such as Deletion

from xplique.attributions import GradCAM
from xplique.metrics import Deletion

# load images, labels and model
# ...

explainer = GradCAM(model)
metric = Deletion(model, inputs, labels)

score_grad_cam = metric(explainer)

Concepts Extraction

Concerning the concept-based methods, we can for example extract a concept vector from a layer of a model. In order to do this, we use two datasets, one containing inputs containing the concept: positive_samples, the other containing other entries which do not contain the concept: negative_samples.

from xplique.concepts import Cav

# load a model, samples that contain a concept
# (positive) and samples who don't (negative)
# ...

extractor = Cav(model, 'mixed3')
concept_vector = extractor(positive_samples,
                           negative_samples)

Feature Visualization

Finally, in order to find an image that maximizes a neuron and at the same time a layer, we build two objectives that we combine together. We then call the optimizer which returns our images

from xplique.features_visualizations import Objective
from xplique.features_visualizations import optimize

# load a model...

neuron_obj = Objective.neuron(model, "logits", 200)
channel_obj = Objective.layer(model, "mixed3", 10)

obj = neuron_obj + 2.0 * channel_obj
images = optimize(obj)

🔥 Notebooks

📦 What's Included

Attribution Method Type of Model Source
Deconvolution TF Paper
Grad-CAM TF Paper
Grad-CAM++ TF Paper
Gradient Input TF Paper
Guided Backprop TF Paper
Integrated Gradients TF Paper
Kernel SHAP Callable Paper
Lime Callable Paper
Occlusion Callable Paper
Rise Callable Paper
Saliency TF Paper
SmoothGrad TF Paper
SquareGrad TF Paper
VarGrad TF Paper
Attribution Metrics Type of Model Property Source
MuFidelity TF Fidelity Paper
Deletion TF Fidelity Paper
Insertion TF Fidelity Paper
Average Stability TF Stability Paper
(WIP) MeGe
(WIP) ReCo
Concepts method Type of Model Source
Concept Activation Vector (CAV) TF Paper
Testing CAV TF Paper
(WIP) Robust TCAV
Feature Visualization (Paper) Type of Model Details
Neurons TF Optimizes for specific neurons
Layer TF Optimizes for specific layers
Channel TF Optimizes for specific channels
Direction TF Optimizes for specific vector
Fourrier Preconditioning TF Optimize in Fourier basis (see preconditioning)
Objective combination TF Allows to combine objectives
methods with TF need a Tensorflow model.

👍 Contributing

Feel free to propose your ideas or come and contribute with us on the Xplique toolbox! We have a specific document where we describe in a simple way how to make your first pull request: just here.

👀 See Also

This library is one approach of many to explain your model. We don't expect it to be the final solution; we create it to explore one point in the space of possibilities.

Other tools to explain your model include:

  • Lucid the wonderful library specialized in feature visualization from OpenAI.
  • Captum the Pytorch library for Interpretability research
  • Tf-explain that implement multiples attribution methods and propose callbacks API for tensorflow.
  • Alibi Explain for model inspection and interpretation

To learn more about Explainable AI in general, see:

🙏 Acknowledgments

This project received funding from the French ”Investing for the Future – PIA3” program within the Artificial and Natural Intelligence Toulouse Institute (ANITI). The authors gratefully acknowledge the support of the DEEL project.

👨‍🎓 Creator

This library was started as a side-project by Thomas FEL who is doing a thesis on explainability.

📝 License

The package is released under MIT license.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Xplique-0.2.0.tar.gz (55.8 kB view details)

Uploaded Source

Built Distribution

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

Xplique-0.2.0-py3-none-any.whl (87.8 kB view details)

Uploaded Python 3

File details

Details for the file Xplique-0.2.0.tar.gz.

File metadata

  • Download URL: Xplique-0.2.0.tar.gz
  • Upload date:
  • Size: 55.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6

File hashes

Hashes for Xplique-0.2.0.tar.gz
Algorithm Hash digest
SHA256 d729071e01ade41a54e6efca95772683a5a75c659fa18d58f50d48255738e25f
MD5 0835c11bc689859f1678555d5353e25d
BLAKE2b-256 cf9de229678d6846ef43760cde6ce50692fd6cc2a8fe0d6feebc4b9d4d2dad24

See more details on using hashes here.

File details

Details for the file Xplique-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: Xplique-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 87.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6

File hashes

Hashes for Xplique-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c23c873fc5619056a126ef3ea510b92f02275cb7abade523d987d4bcdc02fdd3
MD5 ccc8f225f882ad9e23b7544493f0b37a
BLAKE2b-256 647ba024274efbbfe38aeee8ee26159387943d1b7e061ad84355241c39c05045

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