rise_text ========= .. py:module:: rise_text Classes ------- .. autoapisummary:: rise_text.RISEText Module Contents --------------- .. py:class:: RISEText(n_masks=1000, feature_res=8, p_keep=None, preprocess_function=None) RISE implementation for text based on https://github.com/eclique/RISE/blob/master/Easy_start.ipynb. .. py:attribute:: n_masks .. py:attribute:: feature_res .. py:attribute:: p_keep .. py:attribute:: preprocess_function .. py:attribute:: masks :value: None .. py:attribute:: predictions :value: None .. py:method:: explain(model_or_function, input_text, labels, tokenizer=None, batch_size=100) Runs the RISE explainer on text. The model will be called with masked versions of the input text. :param model_or_function: The function that runs the model to be explained _or_ the path to a ONNX model on disk. :type model_or_function: callable or str :param input_text: Text to be explained :type input_text: np.ndarray :param tokenizer: Tokenizer class with tokenize and convert_tokens_to_string methods, and mask_token attribute :param labels: Labels to be explained :type labels: Iterable(int) :param batch_size: Batch size to use for running the model. :type batch_size: int :returns: List of tuples (word, index of word in raw text, importance for target class) for each class. .. py:method:: _determine_p_keep(input_text, runner, tokenizer, n_masks, batch_size) See n_mask default value https://github.com/dianna-ai/dianna/issues/24#issuecomment-1000152233. .. py:method:: _calculate_mean_class_std(p_keep, runner, input_text, tokenizer, n_masks, batch_size) .. py:method:: _generate_masks(input_shape, p_keep, n_masks) .. py:method:: _get_saliencies(runner, sentences, num_tokens, batch_size, p_keep) .. py:method:: _reshape_result(input_tokens, labels, saliencies) :staticmethod: .. py:method:: _create_masked_sentences(tokens, masks, tokenizer)