attribench.masking.TabularMasker
- class attribench.masking.TabularMasker(mask_value=0.0)[source]
Bases:
ImageMasker- Parameters:
- masking_levelstr
Either
"feature"or"pixel". If"feature", the masker will mask features. If"pixel", the masker will mask pixels.
- Raises:
- ValueError
If
masking_levelis not"feature"or"pixel".
Methods
Return the number of features in the samples.
Mask the
kleast important features, according to the attributions.Mask
krandom features.Mask the
kmost important features, according to the attributions.Set the batch of samples and attributions to use for masking.
- get_num_features()
Return the number of features in the samples.
- Returns:
- int
Number of features in the samples.
- mask_bot(k)
Mask the
kleast important features, according to the attributions.- Parameters:
- kint
Number of features to mask.
- Returns:
- torch.Tensor
Samples with the bottom k features masked.
- mask_rand(k, return_indices=False)
Mask
krandom features.- Parameters:
- kint
Number of features to mask.
- return_indicesbool, optional
Whether to return the indices of the masked features, by default False
- Returns:
- torch.Tensor
Samples with k random features masked.
- Return type:
Union[Tensor,Tuple[Tensor,Tensor]]
- mask_top(k)
Mask the
kmost important features, according to the attributions.- Parameters:
- kint
Number of features to mask.
- Returns:
- torch.Tensor
Samples with the top k features masked.
- set_batch(samples, attributions=None, segmented_samples=None)
Set the batch of samples and attributions to use for masking. Optionally also set the segmented samples.
- Parameters:
- samplestorch.Tensor
Samples to use for masking.
- attributionstorch.Tensor, optional
Attributions to use for masking, by default None If None, the
mask_top()andmask_bot()methods will not be available.- segmented_samplestorch.Tensor, optional
Segmented samples to use for masking, by default None