attribench.functional.metrics.minimal_subset
- attribench.functional.metrics.minimal_subset(model, attributions_dataset, batch_size, maskers, mode='deletion', num_steps=100, device=device(type='cpu'))[source]
Computes Minimal Subset Deletion or Insertion for a given
AttributionsDatasetand model.Minimal Subset Deletion or Insertion is computed by iteratively masking (Deletion) or revealing (Insertion) the top features of the input samples and computing the prediction of the model on the masked samples.
Minimal Subset Deletion is the minimal number of features that must be masked to change the model’s prediction from its original prediction. Minimal Subset Insertion is the minimal number of features that must be revealed to get the model’s original prediction.
The Minimal Subset metric is computed for each masker in maskers.
- Parameters:
- modelnn.Module
Model to compute the Minimal Subset metric for.
- attributions_datasetAttributionsDataset
Dataset containing the samples and attributions to compute the Minimal Subset metric for.
- batch_sizeint
Batch size to use when computing the Minimal Subset metric.
- maskersDict[str, Masker]
Dictionary mapping masker names to Masker objects.
- modestr, optional
“deletion” or “insertion”, by default “deletion”
- num_stepsint, optional
Number of steps to use when computing the Minimal Subset metric, by default 100. More steps will result in a more accurate metric, but will take longer to compute.
- devicetorch.device, optional
Device to use when computing the Minimal Subset metric, by default torch.device(“cpu”)
- Returns:
- MinimalSubsetResult
- Return type: