attribench.AttributionMethod

class attribench.AttributionMethod(model, **kwargs)[source]

Bases: object

Wrapper class for attribution methods. An attribution method takes 2 arguments (input and target) and produces attributions in the shape of the input. To create a compatible attribution method, override the __call__() method and optionally the __init__() method for kwargs.

Parameters:
modelnn.Module

Model to compute attributions for.

Methods

abstract __call__(batch_x, batch_target)[source]

Compute attributions for a batch of inputs.

Parameters:
batch_xtorch.Tensor

Input samples.

batch_targettorch.Tensor

Targets to compute attributions for. Note that these need not be the same as the ground truth targets.

Returns:
torch.Tensor

Attributions for the given inputs and targets.

Return type:

Tensor