View source: R/visualization.R
integrated_gradients | R Documentation |
Computes integrated gradients scores for model and an input sequence. This can be used to visualize what part of the input is import for the models decision. Code is R implementation of python code from here. Tensorflow implementation is based on this paper.
integrated_gradients(
m_steps = 50,
baseline_type = "zero",
input_seq,
target_class_idx,
model,
pred_stepwise = FALSE,
num_baseline_repeats = 1
)
m_steps |
Number of steps between baseline and original input. |
baseline_type |
Baseline sequence, either |
input_seq |
Input tensor. |
target_class_idx |
Index of class to compute gradient for |
model |
Model to compute gradient for. |
pred_stepwise |
Whether to do predictions with batch size 1 rather than all at once. Can be used if input is too big to handle at once. Only supported for single input layer. |
num_baseline_repeats |
Number of different baseline estimations if baseline_type is |
A tensorflow tensor.
library(reticulate)
model <- create_model_lstm_cnn(layer_lstm = 8, layer_dense = 3, maxlen = 20, verbose = FALSE)
random_seq <- sample(0:3, 20, replace = TRUE)
input_seq <- array(keras::to_categorical(random_seq), dim = c(1, 20, 4))
integrated_gradients(
input_seq = input_seq,
target_class_idx = 3,
model = model)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.