dianna

DIANNA: Deep Insight And Neural Network Analysis.

Modern scientific challenges are often tackled with (Deep) Neural Networks (DNN). Despite their high predictive accuracy, DNNs lack inherent explainability. Many DNN users, especially scientists, do not harvest DNNs power because of lack of trust and understanding of their working.

Meanwhile, the eXplainable AI (XAI) methods offer some post-hoc interpretability and insight into the DNN reasoning. This is done by quantifying the relevance of individual features (image pixels, words in text, etc.) with respect to the prediction. These “relevance heatmaps” indicate how the network has reached its decision directly in the input modality (images, text, speech etc.) of the data.

There are many Open Source Software (OSS) implementations of these methods, alas, supporting a single DNN format and the libraries are known mostly by the AI experts. The DIANNA library supports the best XAI methods in the context of scientific usage providing their OSS implementation based on the ONNX standard and demonstrations on benchmark datasets. Representing visually the captured knowledge by the AI system can become a source of (scientific) insights.

See https://github.com/dianna-ai/dianna

Subpackages

Submodules

Package Contents

Functions

explain_timeseries(→ numpy.ndarray)

Explain timeseries data given a model and a chosen method.

explain_image(→ numpy.ndarray)

Explain an image (input_data) given a model and a chosen method.

explain_text(→ list)

Explain text (input_text) given a model and a chosen method.

explain_tabular(, **kwargs) → numpy.ndarray)

Explain tabular (input_text) given a model and a chosen method.

_get_explainer(method, kwargs, modality)

Attributes

__author__

__email__

__version__

dianna.__author__ = 'DIANNA Team'[source]
dianna.__email__ = 'dianna-ai@esciencecenter.nl'[source]
dianna.__version__ = '1.5.0'[source]
dianna.explain_timeseries(model_or_function: collections.abc.Callable | str, input_timeseries: numpy.ndarray, method: str, labels: collections.abc.Iterable[int], **kwargs) numpy.ndarray[source]

Explain timeseries data given a model and a chosen method.

Parameters:
  • model_or_function (callable or str) – The function that runs the model to be explained _or_ the path to a ONNX model on disk.

  • input_timeseries (np.ndarray) – Timeseries data to be explained

  • method (str) – One of the supported methods: RISE, LIME or KernelSHAP

  • labels (Iterable(int)) – Labels to be explained

  • kwargs – key word arguments

Returns:

One heatmap per class.

Return type:

np.ndarray

dianna.explain_image(model_or_function: collections.abc.Callable | str, input_image: numpy.ndarray, method: str, labels: collections.abc.Iterable[int], **kwargs) numpy.ndarray[source]

Explain an image (input_data) given a model and a chosen method.

Parameters:
  • model_or_function (callable or str) – The function that runs the model to be explained _or_ the path to a ONNX model on disk.

  • input_image (np.ndarray) – Image data to be explained

  • method (str) – One of the supported methods: RISE, LIME or KernelSHAP

  • labels (Iterable(int)) – Labels to be explained

  • kwargs – These keyword parameters are passed on

Returns:

An array containing the heat maps for each class.

Return type:

np.ndarray

dianna.explain_text(model_or_function: collections.abc.Callable | str, input_text: str, tokenizer, method: str, labels: collections.abc.Iterable[int], **kwargs) list[source]

Explain text (input_text) given a model and a chosen method.

Parameters:
  • model_or_function (callable or str) – The function that runs the model to be explained _or_ the path to a ONNX model on disk.

  • input_text (str) – Text to be explained

  • tokenizer – Tokenizer class with tokenize and convert_tokens_to_string methods, and mask_token attribute

  • method (str) – One of the supported methods: RISE or LIME

  • labels (Iterable(int)) – Labels to be explained

  • kwargs – These keyword parameters are passed on

Returns:

List of tuples (word, index of word in raw text, importance for target class) for each class.

Return type:

list

dianna.explain_tabular(model_or_function: collections.abc.Callable | str, input_tabular: numpy.ndarray, method: str, labels=(1,), **kwargs) numpy.ndarray[source]

Explain tabular (input_text) given a model and a chosen method.

Parameters:
  • model_or_function (callable or str) – The function that runs the model to be explained _or_ the path to a ONNX model on disk.

  • input_tabular (np.ndarray) – Tabular data to be explained

  • method (str) – One of the supported methods: RISE, LIME or KernelSHAP

  • labels (Iterable(int), optional) – Labels to be explained

  • kwargs – These keyword parameters are passed on

Returns:

An array containing the heat maps for each class.

Return type:

np.ndarray

dianna._get_explainer(method, kwargs, modality)[source]