Skip to content

Occlusion

Bases: MultitaskExplainerMixin, AttributionExplainer

The Occlusion method is a perturbation-based approach to interpret model behavior by analyzing the impact of removing or masking parts of the input text. The principle is simple: by systematically occluding (i.e., masking, deleting, or replacing) specific tokens or spans in the input and observing how the model's output changes, one can infer the relative importance of each part of the input to the model's behavior.

Reference: Zeiler and Fergus (2014). Visualizing and understanding convolutional networks. Paper

Examples:

>>> from interpreto import Granularity, Occlusion
>>> from interpreto.attributions import InferenceModes
>>> method = Occlusion(model, tokenizer, batch_size=4,
>>>                    inference_mode=InferenceModes.SOFTMAX,
>>>                    granularity=Granularity.WORD)
>>> explanations = method(text)

Parameters:

Name Type Description Default

model

PreTrainedModel

model to explain

required

tokenizer

PreTrainedTokenizer

Hugging Face tokenizer associated with the model

required

batch_size

int

batch size for the attribution method

4

granularity

Granularity

granularity level of the perturbations (token, word, sentence, etc.)

WORD

inference_mode

Callable[[Tensor], Tensor]

The mode used for inference. It can be either one of LOGITS, SOFTMAX, or LOG_SOFTMAX. Use InferenceModes to choose the appropriate mode.

LOGITS

device

device

device on which the attribution method will be run

None