lime_text
LIME text explainer.
Module Contents
Classes
Wrapper around the LIME explainer. |
- class lime_text.LIMEText(kernel_width=25, kernel=None, verbose=False, class_names=None, feature_selection='auto', split_expression='\\W+', bow=False, mask_string=None, random_state=None, char_level=False, preprocess_function=None)[source]
Wrapper around the LIME explainer.
See Lime explainer by Marco Tulio Correia Ribeiro (https://github.com/marcotcr/lime).
- explain(model_or_function, input_text, labels, tokenizer=None, top_labels=None, num_features=10, num_samples=5000, **kwargs)[source]
Run the LIME explainer.
- Parameters:
model_or_function (callable or str) – The function that runs the model to be explained _or_ the path to a ONNX model on disk.
tokenizer – Tokenizer class with tokenize and convert_tokens_to_string methods, and mask_token attribute
input_text (np.ndarray) – Data to be explained
labels (Iterable(int)) – Iterable of indices of class to be explained
top_labels – Top labels
num_features (int) – Number of features
num_samples (int) – Number of samples
kwargs – These parameters are passed on
Other keyword arguments: see the LIME documentation for LimeTextExplainer.explain_instance: https://lime-ml.readthedocs.io/en/latest/lime.html#lime.lime_text.LimeTextExplainer.explain_instance.
- Returns:
List of tuples (word, index of word in raw text, importance for target class) for each class
- static _reshape_result_for_single_label(local_explanation, string_map)[source]
Get results for single label.
- Parameters:
local_explanation – Lime output, map of tuples (index, importance)
string_map – Lime’s IndexedString, see documentation: https://lime-ml.readthedocs.io/en/latest/lime.html?highlight=indexedstring#lime.lime_text.IndexedString