towhee.models.visualization.transformer_visualization.LRP¶
- class towhee.models.visualization.transformer_visualization.LRP(model: Module)[source]¶
Bases:
object
Layer-wise relevance propagation. https://journals.plos.org/plosone/article/file?id=10.1371/journal.pone.0130140&type=printable
Methods
Generate LRP for a specific layer.
- generate_lrp(input_tensor: Module, index: Optional[int] = None, method: str = 'transformer_attribution', start_layer: int = 0, device=None)[source]¶
Generate LRP for a specific layer. :param input_tensor: The input tensor to the model. :type input_tensor: nn.Module :param index: The index of the layer to be visualized. :type index: int :param method: The method to be used for LRP. :type method: str :param start_layer: The index of the layer to start from. :type start_layer: int :param device: Model device. :type device: str
- Returns:
The LRP tensor.
- Return type:
(torch.Tensor)