rise_text
Module Contents
Classes
RISE implementation for text based on https://github.com/eclique/RISE/blob/master/Easy_start.ipynb. |
- class rise_text.RISEText(n_masks=1000, feature_res=8, p_keep=None, preprocess_function=None)[source]
RISE implementation for text based on https://github.com/eclique/RISE/blob/master/Easy_start.ipynb.
- explain(model_or_function, input_text, labels, tokenizer=None, batch_size=100)[source]
Runs the RISE explainer on text.
The model will be called with masked versions of the input text.
- 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.
input_text (np.ndarray) – Text to be explained
tokenizer – Tokenizer class with tokenize and convert_tokens_to_string methods, and mask_token attribute
labels (Iterable(int)) – Labels to be explained
batch_size (int) – Batch size to use for running the model.
- Returns:
List of tuples (word, index of word in raw text, importance for target class) for each class.
- _determine_p_keep(input_text, runner, tokenizer, n_masks, batch_size)[source]
See n_mask default value https://github.com/dianna-ai/dianna/issues/24#issuecomment-1000152233.