LimeText
LIME explanations for text classification models.
Fits a sparse linear surrogate model on random word-masked variants of
the input text, weighting variants by similarity to the original. The
surrogate's coefficients estimate each word's contribution to the
predicted class. Model agnostic: only predict is queried. Compared to
Token Ablation (one word at a time), LIME captures joint effects of
removing several words but is stochastic and needs more model calls.
References
- [1] Ribeiro, M.T., Singh, S. & Guestrin, C. (2016). "'Why Should I Trust You?' Explaining the Predictions of Any Classifier." KDD 2016. https://arxiv.org/abs/1602.04938
- [2] https://github.com/marcotcr/lime
Parameters
- num_features : integer, default=
10 - Maximum number of words reported in the explanation.
- num_samples : integer, default=
1000 - Number of perturbed texts sampled to fit the local surrogate model. More samples give more stable explanations but take longer.
Methods
explain_instance(self, instances)
LimeTextCompute LIME word attributions for each instance.
Parameters
- instances : DatasetDict
- Instances to be explained; must contain a single text column (tokenizer artifact columns are ignored).
Returns
- dict
- Dictionary with, for each instance, the word weights and the model prediction.
fit(self, background_dataset, **kwargs)
LimeTextStore 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
- LimeText
- The fitted explainer instance (
self).
plot(self, explanation: dict) -> List[DashAI.back.core.artifacts.GroupedArtifacts]
LimeTextRender each instance as a word weight 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 word weight 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.