-
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.
- Loading branch information
Showing
72 changed files
with
1,467 additions
and
14,519 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,10 +28,11 @@ | |
|
||
__author__ = 'DIANNA Team' | ||
__email__ = '[email protected]' | ||
__version__ = '1.3.0' | ||
__version__ = '1.4.0' | ||
|
||
|
||
def explain_timeseries(model_or_function, input_timeseries, method, labels, **kwargs): | ||
def explain_timeseries(model_or_function, input_timeseries, method, labels, | ||
**kwargs): | ||
"""Explain timeseries data given a model and a chosen method. | ||
Args: | ||
|
@@ -48,15 +49,13 @@ def explain_timeseries(model_or_function, input_timeseries, method, labels, **kw | |
""" | ||
explainer = _get_explainer(method, kwargs, modality='Timeseries') | ||
explain_timeseries_kwargs = utils.get_kwargs_applicable_to_function( | ||
explainer.explain, kwargs | ||
) | ||
explainer.explain, kwargs) | ||
for key in explain_timeseries_kwargs.keys(): | ||
kwargs.pop(key) | ||
if kwargs: | ||
raise TypeError(f'Error due to following unused kwargs: {kwargs}') | ||
return explainer.explain( | ||
model_or_function, input_timeseries, labels, **explain_timeseries_kwargs | ||
) | ||
return explainer.explain(model_or_function, input_timeseries, labels, | ||
**explain_timeseries_kwargs) | ||
|
||
|
||
def explain_image(model_or_function, input_image, method, labels, **kwargs): | ||
|
@@ -79,18 +78,17 @@ def explain_image(model_or_function, input_image, method, labels, **kwargs): | |
from onnx_tf.backend import prepare # noqa: F401 | ||
explainer = _get_explainer(method, kwargs, modality='Image') | ||
explain_image_kwargs = utils.get_kwargs_applicable_to_function( | ||
explainer.explain, kwargs | ||
) | ||
explainer.explain, kwargs) | ||
for key in explain_image_kwargs.keys(): | ||
kwargs.pop(key) | ||
if kwargs: | ||
raise TypeError(f'Error due to following unused kwargs: {kwargs}') | ||
return explainer.explain( | ||
model_or_function, input_image, labels, **explain_image_kwargs | ||
) | ||
return explainer.explain(model_or_function, input_image, labels, | ||
**explain_image_kwargs) | ||
|
||
|
||
def explain_text(model_or_function, input_text, tokenizer, method, labels, **kwargs): | ||
def explain_text(model_or_function, input_text, tokenizer, method, labels, | ||
**kwargs): | ||
"""Explain text (input_text) given a model and a chosen method. | ||
Args: | ||
|
@@ -108,8 +106,7 @@ def explain_text(model_or_function, input_text, tokenizer, method, labels, **kwa | |
""" | ||
explainer = _get_explainer(method, kwargs, modality='Text') | ||
explain_text_kwargs = utils.get_kwargs_applicable_to_function( | ||
explainer.explain, kwargs | ||
) | ||
explainer.explain, kwargs) | ||
for key in explain_text_kwargs.keys(): | ||
kwargs.pop(key) | ||
if kwargs: | ||
|
@@ -123,7 +120,11 @@ def explain_text(model_or_function, input_text, tokenizer, method, labels, **kwa | |
) | ||
|
||
|
||
def explain_tabular(model_or_function, input_tabular, method, labels=(1, ), **kwargs): | ||
def explain_tabular(model_or_function, | ||
input_tabular, | ||
method, | ||
labels=(1, ), | ||
**kwargs): | ||
"""Explain tabular (input_text) given a model and a chosen method. | ||
Args: | ||
|
@@ -139,8 +140,7 @@ def explain_tabular(model_or_function, input_tabular, method, labels=(1, ), **kw | |
""" | ||
explainer = _get_explainer(method, kwargs, modality='Tabular') | ||
explain_tabular_kwargs = utils.get_kwargs_applicable_to_function( | ||
explainer.explain, kwargs | ||
) | ||
explainer.explain, kwargs) | ||
for key in explain_tabular_kwargs.keys(): | ||
kwargs.pop(key) | ||
if kwargs: | ||
|
@@ -152,11 +152,11 @@ def explain_tabular(model_or_function, input_tabular, method, labels=(1, ), **kw | |
**explain_tabular_kwargs, | ||
) | ||
|
||
|
||
def _get_explainer(method, kwargs, modality): | ||
try: | ||
method_submodule = importlib.import_module( | ||
f'dianna.methods.{method.lower()}_{modality.lower()}' | ||
) | ||
f'dianna.methods.{method.lower()}_{modality.lower()}') | ||
except ImportError as err: | ||
raise ValueError( | ||
f'Method {method.lower()}_{modality.lower()} does not exist' | ||
|
@@ -168,8 +168,7 @@ def _get_explainer(method, kwargs, modality): | |
f'Data modality {modality} is not available for method {method.upper()}' | ||
) from err | ||
method_kwargs = utils.get_kwargs_applicable_to_function( | ||
method_class.__init__, kwargs | ||
) | ||
method_class.__init__, kwargs) | ||
# Remove used kwargs from list of kwargs passed to the function. | ||
for key in method_kwargs.keys(): | ||
kwargs.pop(key) | ||
|
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
Binary file not shown.
File renamed without changes
Binary file not shown.
File renamed without changes
File renamed without changes.
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,2 @@ | ||
Noise | ||
FRB |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.