Skip to content

Commit

Permalink
Merge branch 'main' into 49-python3.10
Browse files Browse the repository at this point in the history
  • Loading branch information
cwmeijer committed Jan 18, 2022
2 parents 6b0396f + a31e1ed commit 6fef479
Show file tree
Hide file tree
Showing 36 changed files with 962 additions and 292 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.1.0
current_version = 0.2.1

[comment]
comment = The contents of this file cannot be merged with that of setup.cfg until https://github.com/c4urself/bump2version/issues/185 is resolved
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
fail-fast: false
matrix:
os: ['ubuntu-latest', 'macos-latest', 'windows-latest']
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
python-version: ['3.7', '3.8', '3.9', '3.10']
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ jobs:
- name: Check style against standards using prospector
run: prospector
- name: Check import order
run: isort --recursive --check-only dianna
run: isort --check-only dianna --diff
2 changes: 1 addition & 1 deletion .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: Check style against standards using prospector
run: prospector --zero-exit --output-format grouped --output-format pylint:pylint-report.txt
- name: Run unit tests with coverage
run: pytest --cov --cov-report term --cov-report xml --junitxml=xunit-result.xml tests/
run: pytest --cov --cov-report term --cov-report xml --cov-report html --junitxml=xunit-result.xml tests/
- name: Correct coverage paths
run: sed -i "s+$PWD/++g" coverage.xml
- name: SonarCloud Scan
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@
*.egg-info
*.eggs
.ipynb_checkpoints
*.pt

build
dist
.cache
__pycache__

# testing
htmlcov
.coverage
coverage.xml
.pytest_cache
.tox
word_vectors.txt.pt

docs/_build

Expand Down
9 changes: 8 additions & 1 deletion .prospector.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
output-format: grouped

strictness: medium
doc-warnings: false
doc-warnings: true
test-warnings: true
member-warnings: false

Expand All @@ -18,6 +18,11 @@ pyroma:
pep8:
full: true

pylint:
disable: [
C0114, # we don't check for module docstrings, because we have many separate files for single classes
]

pep257:
disable: [
# Disable because not part of PEP257 official convention:
Expand All @@ -26,4 +31,6 @@ pep257:
D212, # Multi-line docstring summary should start at the first line
D213, # Multi-line docstring summary should start at the second line
D404, # First word of the docstring should not be This
# The following list excludes things that are irrelevant to the Google style
D203, D204, D213, D215, D400, D401, D404, D406, D407, D408, D409, D413,
]
7 changes: 3 additions & 4 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ authors:
given-names: Leon
orcid: "https://orcid.org/0000-0001-8724-8372"

# date-released and DOI to be updated
date-released: 1999-01-01
doi: 10.0000/FIXME
version: "0.1.0"
# date-released: 2021-12-23
doi: 10.5281/zenodo.5801485
version: "0.2.1"
repository-code: "https://github.com/dianna-ai/dianna"
keywords:
- XAI
Expand Down
45 changes: 18 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
[![build](https://github.com/dianna-ai/dianna/actions/workflows/build.yml/badge.svg)](https://github.com/dianna-ai/dianna/actions/workflows/build.yml)
[![workflow pypi badge](https://img.shields.io/pypi/v/dianna.svg?colorB=blue)](https://pypi.python.org/project/dianna/)
[![workflow scc badge](https://sonarcloud.io/api/project_badges/measure?project=dianna-ai_dianna&metric=coverage)](https://sonarcloud.io/dashboard?id=dianna-ai_dianna)
[more badges](badges.md)

# 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.

## How to use dianna

The project setup is documented in [project_setup.md](project_setup.md). Feel free to remove this document (and/or the link to this document) if you don't need it.
The project setup is documented in [project_setup.md](https://github.com/dianna-ai/dianna/blob/main/project_setup.md). Feel free to remove this document (and/or the link to this document) if you don't need it.

## Installation
## Installation [![workflow pypi badge](https://img.shields.io/pypi/v/dianna.svg?colorB=blue)](https://pypi.python.org/project/dianna/)

To install dianna directly from the GitHub repository, do:

Expand All @@ -20,36 +31,16 @@ cd dianna
python3 -m pip install -e .
```

## Badges

(Customize these badges with your own links, and check https://shields.io/ or https://badgen.net/ to see which other badges are available.)
## Documentation [![Documentation Status](https://readthedocs.org/projects/dianna/badge/?version=latest)](https://dianna.readthedocs.io/en/latest/?badge=latest)

| fair-software.eu recommendations | |
| :-- | :-- |
| (1/5) code repository | [![github repo badge](https://img.shields.io/badge/github-repo-000.svg?logo=github&labelColor=gray&color=blue)](https://github.com/dianna-ai/dianna) |
| (2/5) license | [![github license badge](https://img.shields.io/github/license/dianna-ai/dianna)](https://github.com/dianna-ai/dianna) |
| (3/5) community registry | [![RSD](https://img.shields.io/badge/rsd-dianna-00a3e3.svg)](https://www.research-software.nl/software/dianna) -no pypi package yet- |
| (4/5) citation | [![DOI](https://zenodo.org/badge/DOI/<replace-with-created-DOI>.svg)](https://doi.org/<replace-with-created-DOI>) |
| (5/5) checklist | [![workflow cii badge](https://bestpractices.coreinfrastructure.org/projects/<replace-with-created-project-identifier>/badge)](https://bestpractices.coreinfrastructure.org/projects/<replace-with-created-project-identifier>) |
| 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** | &nbsp; |
| 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** | &nbsp; |
| 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) |

## Documentation

Include a link to your project's full documentation here.

## Contributing

If you want to contribute to the development of dianna,
have a look at the [contribution guidelines](CONTRIBUTING.md).
have a look at the [contribution guidelines](https://github.com/dianna-ai/dianna/blob/main/CONTRIBUTING.md).

## How to cite us [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.5592606.svg)](https://doi.org/10.5281/zenodo.5592606)


## Credits

Expand Down
15 changes: 15 additions & 0 deletions badges.md
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** | &nbsp; |
| 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** | &nbsp; |
| 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) |
68 changes: 59 additions & 9 deletions dianna/__init__.py
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)
Loading

0 comments on commit 6fef479

Please sign in to comment.