TokenAblation
Occlusion-based local explainer for text classification.
For each instance, ablates one token at a time (removing it or replacing
it with an [UNK] placeholder) and measures how much the predicted class
probability drops. Tokens whose removal causes a large drop are the ones
the model relied on for its prediction. The method is model agnostic: it
only queries predict, so it works with any text classifier.
References
- [1] Zeiler, M.D. & Fergus, R. (2014). "Visualizing and Understanding Convolutional Networks." ECCV 2014. https://arxiv.org/abs/1311.2901
- [2] Li, J. et al. (2016). "Understanding Neural Networks through Representation Erasure." https://arxiv.org/abs/1612.08220
Parameters
- max_tokens : integer, default=
50 - Maximum number of tokens (whitespace-separated words) evaluated per instance. Texts longer than this are truncated for the analysis to bound the number of model calls.
- replacement : string, default=
remove - How an ablated token is handled: 'remove' deletes it from the text, 'unk' replaces it with the [UNK] placeholder.
Methods
explain_instance(self, instances)
TokenAblationCompute token importances for each instance.
Parameters
- instances : DatasetDict
- Instances to be explained; must contain a single text column.
Returns
- dict
- Dictionary with, for each instance, the tokens, their importance (probability drop when ablated) and the model prediction.
fit(self, background_dataset, **kwargs)
TokenAblationStore class names from the training targets.
Parameters
- background_dataset : Tuple[DatasetDict, DatasetDict]
- Tuple
(x, y)with the dataset splits. - **kwargs : Any
- Ignored; present for interface compatibility.
Returns
- TokenAblation
- The fitted explainer instance (
self).
plot(self, explanation: dict) -> List[DashAI.back.core.artifacts.GroupedArtifacts]
TokenAblationRender each instance as a token importance bar plot plus a summary.
Parameters
- explanation : dict
- Dictionary with the explanation generated by the explainer.
Returns
- List[GroupedArtifacts]
- A single grouped artifact with one group per explained instance, each holding that instance's token plot and text summary.
get_schema(cls) -> dict
ConfigObjectGenerates the component related Json Schema.
Returns
- dict
- Dictionary representing the Json Schema of the component.
validate_and_transform(self, raw_data: dict) -> dict
ConfigObjectIt takes the data given by the user to initialize the model and returns it with all the objects that the model needs to work.
Parameters
- raw_data : dict
- A dictionary with the data provided by the user to initialize the model.
Returns
- dict
- A validated dictionary with the necessary objects.