code: def expected_gradients_full(
      inputs,
      references,
      model,
      k=100,
      index_true_class=False,
      labels=None,
  ):
      """
      Given a batch of inputs and labels, and a model,
      symbolically computes expected gradients with k references.
  
      Args:
          inputs: A [batch_size, ...]-shaped tensor. The input to a model.
          references: A numpy array representing background training data to sample from.
          model:  A tf.keras.Model object, or a subclass object thereof.
          k: The number of samples to use when computing expected gradients.
          index_true_class: Whether or not to take the gradients of the output with respect to the true
              class. True by default. This should be set to True in the multi-class setting, and False
              in the regression setting.
          labels: A [batch_size, num_classes]-shaped tensor.
                  The true class labels in one-hot encoding,
                  assuming a multi-class problem.
      Returns:
          A tensor the same shape as the input representing the expected gradients
          feature attributions with respect to the output predictions.
      """
      eg_array = []
  
      for i in range(tf.shape(inputs)[0]):
          sample_indices = np.random.choice(
              references.shape[0], size=k, replace=False
          )
          sample_references = references[sample_indices]
  
          alphas = tf.random.uniform(
              shape=(k, 1, 1, 1),
              minval=0.0,
              maxval=1.0,
              dtype=tf.float32,
          )
          current_input = tf.expand_dims(inputs[i], axis=0)
  
          interpolated_inputs = (
              alphas * current_input
              + (1.0 - alphas) * sample_references
          )
  
          with tf.GradientTape() as tape:
              tape.watch(interpolated_inputs)
              predictions = model(interpolated_inputs, training=False)
  
              if index_true_class:
                  current_labels = tf.expand_dims(labels[i, :], axis=0)
                  current_labels = tf.tile(
                      current_labels, multiples=(k, 1)
                  )
                  predictions_indexed = _index_predictions(
                      predictions, current_labels
                  )
              else:
                  predictions_indexed = predictions
  
          input_gradients = tape.gradient(
              predictions_indexed, interpolated_inputs
          )
          difference_from_reference = current_input - sample_references
          expected_gradients_samples = (
              input_gradients * difference_from_reference
          )
          expected_gradients = tf.reduce_mean(
              expected_gradients_samples, axis=0
          )
          eg_array.append(expected_gradients)
  
      return tf.stack(eg_array, axis=0)
  
file_path: attributionpriors/attributionpriors/eager_ops.py
imports: import tensorflow
  import numpy
label_desc: Use image node_id 5 for calling a global function with example usage: expected_gradients_full(inputs, references, model, k, index_true_class, labels) and returns: tf