Saltar al contenido principal

TokenAblation

LocalExplainer
DashAI.back.explainability.explainers.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

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)

Defined on TokenAblation

Compute 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)

Defined on TokenAblation

Store 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]

Defined on TokenAblation

Render 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

Defined on ConfigObject

Generates the component related Json Schema.

Returns

dict
Dictionary representing the Json Schema of the component.

validate_and_transform(self, raw_data: dict) -> dict

Defined on ConfigObject

It 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.

Compatible with