-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 49-python3.10
- Loading branch information
Showing
36 changed files
with
962 additions
and
292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
| fair-software.eu recommendations | | | ||
| :-- | :-- | | ||
| license | [![github license badge](https://img.shields.io/github/license/dianna-ai/dianna)](https://github.com/dianna-ai/dianna) | | ||
| community registry | [![RSD](https://img.shields.io/badge/rsd-dianna-00a3e3.svg)](https://www.research-software.nl/software/dianna) [![workflow pypi badge](https://img.shields.io/pypi/v/dianna.svg?colorB=blue)](https://pypi.python.org/project/dianna/) | | ||
| citation | [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.5592606.svg)](https://doi.org/10.5281/zenodo.5592606) | | ||
| howfairis | [![fair-software badge](https://img.shields.io/badge/fair--software.eu-%E2%97%8F%20%20%E2%97%8F%20%20%E2%97%8F%20%20%E2%97%8F%20%20%E2%97%8B-yellow)](https://fair-software.eu) | | ||
| **Other best practices** | | | ||
| Static analysis | [![workflow scq badge](https://sonarcloud.io/api/project_badges/measure?project=dianna-ai_dianna&metric=alert_status)](https://sonarcloud.io/dashboard?id=dianna-ai_dianna) | | ||
| Coverage | [![workflow scc badge](https://sonarcloud.io/api/project_badges/measure?project=dianna-ai_dianna&metric=coverage)](https://sonarcloud.io/dashboard?id=dianna-ai_dianna) | | ||
| Documentation | [![Documentation Status](https://readthedocs.org/projects/dianna/badge/?version=latest)](https://dianna.readthedocs.io/en/latest/?badge=latest) | | ||
| **GitHub Actions** | | | ||
| Build | [![build](https://github.com/dianna-ai/dianna/actions/workflows/build.yml/badge.svg)](https://github.com/dianna-ai/dianna/actions/workflows/build.yml) | | ||
| Citation data consistency | [![cffconvert](https://github.com/dianna-ai/dianna/actions/workflows/cffconvert.yml/badge.svg)](https://github.com/dianna-ai/dianna/actions/workflows/cffconvert.yml) | | ||
| SonarCloud | [![sonarcloud](https://github.com/dianna-ai/dianna/actions/workflows/sonarcloud.yml/badge.svg)](https://github.com/dianna-ai/dianna/actions/workflows/sonarcloud.yml) | | ||
| MarkDown link checker | [![markdown-link-check](https://github.com/dianna-ai/dianna/actions/workflows/markdown-link-check.yml/badge.svg)](https://github.com/dianna-ai/dianna/actions/workflows/markdown-link-check.yml) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,79 @@ | ||
"""Documentation about 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 | ||
""" | ||
import logging | ||
from . import methods | ||
from . import utils | ||
|
||
|
||
logging.getLogger(__name__).addHandler(logging.NullHandler()) | ||
|
||
__author__ = "DIANNA Team" | ||
__email__ = "dianna-ai@esciencecenter.nl" | ||
__version__ = "0.1.0" | ||
__version__ = "0.2.1" | ||
|
||
|
||
def explain_image(model_or_function, input_data, method, **kwargs): | ||
def explain_image(model_or_function, input_data, method, labels=(1,), **kwargs): | ||
""" | ||
Exampler explainer wrapper | ||
Explain an image (input_data) given a model and a chosen method. | ||
Args: | ||
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_data (np.ndarray): Image data to be explained | ||
method (string): One of the supported methods: RISE, LIME or KernelSHAP | ||
labels (tuple): Labels to be explained | ||
Returns: | ||
One heatmap (2D array) per class. | ||
""" | ||
return get_explainer(method, kwargs).explain_image(model_or_function, input_data) | ||
explainer = _get_explainer(method, kwargs) | ||
explain_image_kwargs = utils.get_kwargs_applicable_to_function(explainer.explain_image, kwargs) | ||
return explainer.explain_image(model_or_function, input_data, labels, **explain_image_kwargs) | ||
|
||
|
||
def explain_text(model_or_function, input_data, method, labels=(1,), **kwargs): | ||
""" | ||
Exampler explainer wrapper | ||
Explain text (input_data) given a model and a chosen method. | ||
Args: | ||
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_data (string): Text to be explained | ||
method (string): One of the supported methods: RISE or LIME | ||
labels (tuple): Labels to be explained | ||
Returns: | ||
List of (word, index of word in raw text, importance for target class) tuples. | ||
""" | ||
return get_explainer(method, kwargs).explain_text(model_or_function, input_data, labels) | ||
explainer = _get_explainer(method, kwargs) | ||
explain_text_kwargs = utils.get_kwargs_applicable_to_function(explainer.explain_text, kwargs) | ||
return explainer.explain_text(model_or_function, input_data, labels, **explain_text_kwargs) | ||
|
||
|
||
def get_explainer(method, kwargs): | ||
def _get_explainer(method, kwargs): | ||
method_class = getattr(methods, method) | ||
return method_class(**kwargs) | ||
method_kwargs = utils.get_kwargs_applicable_to_function(method_class.__init__, kwargs) | ||
return method_class(**method_kwargs) |
Oops, something went wrong.