peal.explainers.explainer_factory.get_explainer

peal.explainers.explainer_factory.get_explainer(explainer, device='cuda', predictor_datasets=None, **kwargs)[source]

Return an explainer built from an instance, a yaml path or a config dict.

Parameters:
  • explainer (ExplainerInterface or str or dict) – A ready explainer (returned unchanged), a yaml path or a dict-like config. The config’s explainer_type selects the class: the values SCE, ACE, TIME and DAEdistill all instantiate CounterfactualExplainer(explainer_config=..., **kwargs); any other value must be the class name of an ExplainerInterface subclass discovered under peal/explainers, which is then called as cls(config=..., device=..., predictor_dataset=predictor_datasets, **kwargs).

  • device (str or torch.device, optional) – Device handed to non-counterfactual explainers. Default "cuda".

  • predictor_datasets (optional) – Dataset(s) of the predictor, forwarded as predictor_dataset.

  • **kwargs – Extra constructor arguments forwarded to the explainer class.

Returns:

The resolved explainer.

Return type:

ExplainerInterface

Raises:

peal.registry.UnknownComponentError – If the config’s explainer_type matches neither the legacy names nor a registered or discoverable subclass.