LIME¶
Bases: MultitaskExplainerMixin
, AttributionExplainer
Local Interpretable Model-agnostic Explanations (LIME) is a perturbation‑based approach that explains individual predictions by fitting a simple, interpretable surrogate model locally around the prediction of interest. By sampling perturbed versions of the input and weighting them by their proximity to the original instance, LIME learns per‑feature importance scores that approximate the behaviour of the underlying black‑box model in that local region.
Reference: Ribeiro et al. (2016). "Why Should I Trust You?": Explaining the Predictions of Any Classifier. Paper
Examples:
>>> from interpreto import Granularity, Lime
>>> from interpreto.attributions import InferenceModes
>>> method = Lime(model, tokenizer, batch_size=4,
>>> inference_mode=InferenceModes.LOG_SOFTMAX,
>>> n_perturbations=20,
>>> granularity=Granularity.WORD,
>>> distance_function=Lime.distance_functions.HAMMING)
>>> explanations = method(text)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
PreTrainedModel
|
model to explain |
required |
|
PreTrainedTokenizer
|
Hugging Face tokenizer associated with the model |
required |
|
int
|
batch size for the attribution method |
4
|
|
Granularity
|
granularity level of the perturbations (token, word, sentence, etc.) |
WORD
|
|
Callable[[Tensor], Tensor]
|
The mode used for inference. It can be either one of LOGITS, SOFTMAX, or LOG_SOFTMAX. Use InferenceModes to choose the appropriate mode. |
LOGITS
|
|
int
|
the number of perturbations to generate. |
100
|
|
float
|
probability of perturbation. |
0.5
|
|
DistancesFromMaskProtocol
|
distance function used to compute weights of perturbed samples in the linear model training. |
COSINE
|
|
float | Callable | None
|
kernel width used in the |
None
|
|
device
|
device on which the attribution method will be run |
None
|