Insights

Batch

AttributionVisualizer

Features

BaseFeature

class captum.insights.features.BaseFeature(name, baseline_transforms, input_transforms, visualization_transform)[source]

All Feature classes extend this class to implement custom visualizations in Insights.

It enforces child classes to implement visualization_type and visualize methods.

Parameters
  • name (str) – The label of the specific feature. For example, an ImageFeature’s name can be “Photo”.

  • baseline_transforms (list, callable, optional) – Optional list of callables (e.g. functions) to be called on the input tensor to construct multiple baselines. Currently only one baseline is supported. See IntegratedGradients for more information about baselines.

  • input_transforms (list, callable, optional) – Optional list of callables (e.g. functions) called on the input tensor sequentially to convert it into the format expected by the model.

  • visualization_transform (callable, optional) – Optional callable (e.g. function) applied as a postprocessing step of the original input data (before input_transforms) to convert it to a format to be understood by the frontend visualizer as specified in captum/captum/insights/frontend/App.js.

GeneralFeature

class captum.insights.features.GeneralFeature(name, categories)[source]

GeneralFeature is used for non-specified feature visualization in Insights. It can be used for dense or sparse features.

Currently general features are only supported for 2-d tensors, in the format (N, C) where N is the number of samples and C is the number of categories.

Parameters
  • name (str) – The label of the specific feature. For example, an ImageFeature’s name can be “Photo”.

  • categories (list[str]) – Category labels for the general feature. The order and size should match the second dimension of the data tensor parameter in visualize.

TextFeature

class captum.insights.features.TextFeature(name, baseline_transforms, input_transforms, visualization_transform)[source]

TextFeature is used to visualize text (e.g. sentences) in Insights. It expects the visualization transform to convert the input data (e.g. index to string) to the raw text.

Parameters
  • name (str) – The label of the specific feature. For example, an ImageFeature’s name can be “Photo”.

  • baseline_transforms (list, callable, optional) – Optional list of callables (e.g. functions) to be called on the input tensor to construct multiple baselines. Currently only one baseline is supported. See IntegratedGradients for more information about baselines. For text features, a common baseline is a tensor of indices corresponding to PAD with the same size as the input tensor. See TokenReferenceBase for more information.

  • input_transforms (list, callable, optional) – A list of transforms or transform to be applied to the input. For text, a common transform is to convert the tokenized input tensor into an interpretable embedding. See InterpretableEmbeddingBase and configure_interpretable_embedding_layer() for more information.

  • visualization_transform (callable, optional) – Optional callable (e.g. function) applied as a postprocessing step of the original input data (before input_transforms) to convert it to a suitable format for visualization. For text features, a common function is to convert the token indices to their corresponding (sub)words.

ImageFeature

class captum.insights.features.ImageFeature(name, baseline_transforms, input_transforms, visualization_transform=None)[source]

ImageFeature is used to visualize image features in Insights. It expects an image in NCHW format. If C has a dimension of 1, its assumed to be a greyscale image. If it has a dimension of 3, its expected to be in RGB format.

Parameters
  • name (str) – The label of the specific feature. For example, an ImageFeature’s name can be “Photo”.

  • baseline_transforms (list, callable, optional) – Optional list of callables (e.g. functions) to be called on the input tensor to construct multiple baselines. Currently only one baseline is supported. See IntegratedGradients for more information about baselines.

  • input_transforms (list, callable, optional) – A list of transforms or transform to be applied to the input. For images, normalization is often applied here.

  • visualization_transform (callable, optional) – Optional callable (e.g. function) applied as a postprocessing step of the original input data (before input_transforms) to convert it to a format to be visualized.