class_docstr: Base class for similarity explainers.
docstr: Constructor
  
  Parameters
  ----------
  predictor
      Model to be explained.
  loss_fn
      Loss function.
  sim_fn
      Similarity function. Takes two inputs and returns a similarity value.
  precompute_grads
      Whether to precompute and store the gradients when fitting.
  backend
      Deep learning backend.
  device
      Device to be used. Will default to the same device the backend defaults to.
  meta
      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.
docstr_tok: ["Constructor","Parameters","--","--","--","--","--","predictor","Model","to","be","explained",".","loss_fn","Loss","function",".","sim_fn","Similarity","function",".","Takes","two","inputs","and","returns","a","similarity","value",".","precompute_grads","Whether","to","precompute","and","store","the","gradients","when","fitting",".","backend","Deep","learning","backend",".","device","Device","to","be","used",".","Will","default","to","the","same","device","the","backend","defaults","to",".","meta","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","."]
code: def __init__(
      self,
      predictor: "Union[tensorflow.keras.Model, torch.nn.Module]",
      loss_fn: """Union[Callable[[tensorflow.Tensor, tensorflow.Tensor], tensorflow.Tensor],
                                     Callable[[torch.Tensor, torch.Tensor], torch.Tensor]]""",
      sim_fn: Callable[[np.ndarray, np.ndarray], np.ndarray],
      precompute_grads: bool = False,
      backend: Framework = Framework.TENSORFLOW,
      device: "Union[int, str, torch.device, None]" = None,
      meta: Optional[dict] = None,
      verbose: bool = False,
  ):
      """Constructor
  
      Parameters
      ----------
      predictor
          Model to be explained.
      loss_fn
          Loss function.
      sim_fn
          Similarity function. Takes two inputs and returns a similarity value.
      precompute_grads
          Whether to precompute and store the gradients when fitting.
      backend
          Deep learning backend.
      device
          Device to be used. Will default to the same device the backend defaults to.
      meta
          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.
      """
  
      # Select backend.
      self.backend = _select_backend(backend)
      self.backend.set_device(device)  # type: ignore
  
      self.predictor = predictor
      self.loss_fn = loss_fn
      self.sim_fn = sim_fn
      self.precompute_grads = precompute_grads
      self.verbose = verbose
  
      meta = {} if meta is None else meta
      super().__init__(meta=meta)
  
imports: from abc import ABC
  from typing import TYPE_CHECKING, Any, Callable, List, Optional, Union
  import numpy
  from alibi.api.interfaces import Explainer
  from alibi.explainers.similarity.backends import _select_backend
  from alibi.utils.frameworks import Framework, has_pytorch, has_tensorflow
  from alibi.utils.missing_optional_dependency import import_optional
  from tqdm import tqdm
  from typing_extensions import Literal
label_desc: Use image node_id 1 to create a new BaseSimilarityExplainer object from inherited base classes: Explainer, ABC with example: obj = BaseSimilarityExplainer(predictor, loss_fn, sim_fn, precompute_grads, backend, device, meta, verbose)