alibi.explainers.similarity.base module

class alibi.explainers.similarity.base.BaseSimilarityExplainer(predictor, loss_fn, sim_fn, precompute_grads=False, backend=Framework.TENSORFLOW, device=None, meta=None, verbose=False)[source]

Bases: Explainer, ABC

Base class for similarity explainers.

__init__(predictor, loss_fn, sim_fn, precompute_grads=False, backend=Framework.TENSORFLOW, device=None, meta=None, verbose=False)[source]

Constructor

Parameters:
  • predictor (Union[Model, Module]) – Model to be explained.

  • loss_fn (Union[Callable[[Tensor, Tensor], Tensor], Callable[[Tensor, Tensor], Tensor]]) – Loss function.

  • sim_fn (Callable[[ndarray, ndarray], ndarray]) – Similarity function. Takes two inputs and returns a similarity value.

  • precompute_grads (bool) – Whether to precompute and store the gradients when fitting.

  • backend (Framework) – Deep learning backend.

  • device (Union[int, str, device, None]) – Device to be used. Will default to the same device the backend defaults to.

  • meta (Optional[dict]) – Metadata specific to explainers that inherit from this class. Should be initialized in the child class and passed in here. Is used in the __init__ of the base Explainer class.

fit(X_train, Y_train)[source]

Fit the explainer. If self.precompute_grads == True then the gradients are precomputed and stored.

Parameters:
  • X_train (Union[ndarray, List[Any]]) – Training data.

  • Y_train (ndarray) – Training labels.

Return type:

Explainer

Returns:

self – Returns self.

reset_predictor(predictor)[source]

Resets the predictor to the given predictor.

Parameters:

predictor (Union[Model, Module]) – The new predictor to use.

Return type:

None