Switch to unified view

a b/man/integrated_gradients.Rd
1
% Generated by roxygen2: do not edit by hand
2
% Please edit documentation in R/visualization.R
3
\name{integrated_gradients}
4
\alias{integrated_gradients}
5
\title{Compute integrated gradients}
6
\usage{
7
integrated_gradients(
8
  m_steps = 50,
9
  baseline_type = "zero",
10
  input_seq,
11
  target_class_idx,
12
  model,
13
  pred_stepwise = FALSE,
14
  num_baseline_repeats = 1
15
)
16
}
17
\arguments{
18
\item{m_steps}{Number of steps between baseline and original input.}
19
20
\item{baseline_type}{Baseline sequence, either \code{"zero"} for all zeros or \code{"shuffle"} for random permutation of \code{input_seq}.}
21
22
\item{input_seq}{Input tensor.}
23
24
\item{target_class_idx}{Index of class to compute gradient for}
25
26
\item{model}{Model to compute gradient for.}
27
28
\item{pred_stepwise}{Whether to do predictions with batch size 1 rather than all at once. Can be used if
29
input is too big to handle at once. Only supported for single input layer.}
30
31
\item{num_baseline_repeats}{Number of different baseline estimations if baseline_type is \code{"shuffle"} (estimate integrated
32
gradient repeatedly for different shuffles). Final result is average of \code{num_baseline} single calculations.}
33
}
34
\value{
35
A tensorflow tensor.
36
}
37
\description{
38
Computes integrated gradients scores for model and an input sequence.
39
This can be used to visualize what part of the input is import for the models decision.
40
Code is R implementation of python code from \href{https://www.tensorflow.org/tutorials/interpretability/integrated_gradients}{here}.
41
Tensorflow implementation is based on this \href{https://arxiv.org/abs/1703.01365}{paper}.
42
}
43
\examples{
44
\dontshow{if (reticulate::py_module_available("tensorflow")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf}
45
library(reticulate)
46
model <- create_model_lstm_cnn(layer_lstm = 8, layer_dense = 3, maxlen = 20, verbose = FALSE)
47
random_seq <- sample(0:3, 20, replace = TRUE)
48
input_seq <- array(keras::to_categorical(random_seq), dim = c(1, 20, 4))
49
integrated_gradients(
50
  input_seq = input_seq,
51
  target_class_idx = 3,
52
  model = model)
53
  
54
\dontshow{\}) # examplesIf}
55
}