rise_text

Module Contents

Classes

RISEText

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.

_calculate_mean_class_std(p_keep, runner, input_text, tokenizer, n_masks, batch_size)[source]
_generate_masks(input_shape, p_keep, n_masks)[source]
_get_saliencies(runner, sentences, num_tokens, batch_size, p_keep)[source]
static _reshape_result(input_tokens, labels, saliencies)[source]
_create_masked_sentences(tokens, masks, tokenizer)[source]