TAM#

class txv.exp.TAM(model: Module)#

Link to paper: Explaining Information Flow Inside Vision Transformers Using Markov Chain

__init__(model: Module) None#
Parameters:

model (torch.nn.Module) – A model from txv.vit

Tip

Use the model with lrp=False as LRP models have higher memory footprint.

Caution

This method is only supported for Vision Transformers- small, base and large.

explain(input: Tensor, index: int | None = None, l_end: int = 0, steps: int = 20, baseline: Tensor | None = None, abm: bool = True) Tensor#
Parameters:
  • input (torch.Tensor) – Input tensor

  • index (int, optional) – Index of the class to explain, by default the predicted class is explained

  • l_end (int, optional) – Layer number to end the computation of attention weights. By default 0. Attention weights are computed from last_layer to l_end.

  • steps (int, optional) – Number of steps in Riemann approximation of integral, by default 20

  • baseline (torch.Tensor, optional) – Baseline tensor, by default None(tensor of zeros)