Saltar al contenido principal

LimeText

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

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)

Defined on LimeText

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

Defined on LimeText

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

LimeText
The fitted explainer instance (self).

plot(self, explanation: dict) -> List[DashAI.back.core.artifacts.GroupedArtifacts]

Defined on LimeText

Render 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

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