code: def expected_gradients(inputs, labels, model, index_true_class=True):
      """
      Given a batch of inputs and labels, and a model,
      symbolically computes a single sample of expected gradients.
  
      Args:
          inputs: A [batch_size, ...]-shaped tensor. The input to a model.
          labels: A [batch_size, num_classes]-shaped tensor.
                  The true class labels in one-hot encoding form,
                  assuming a multi-class problem.
          model:  A tf.keras.Model object, or a subclass object thereof.
          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.
      Returns:
          A tensor the same shape as the input representing a single sample of expected gradients
          of the output of the model with respect to the input.
      """
      current_batch_size = tf.shape(inputs)[0]
  
      # Here we have to compute the interpolated input into the model
      references = tf.roll(inputs, shift=1, axis=0)
      alphas = tf.random.uniform(
          shape=(current_batch_size, 1, 1, 1),
          minval=0.0,
          maxval=1.0,
          dtype=tf.float32,
      )
      interpolated_inputs = (
          alphas * inputs + (1.0 - alphas) * references
      )
  
      with tf.GradientTape() as tape:
          tape.watch(interpolated_inputs)
          predictions = model(interpolated_inputs, training=True)
  
          if index_true_class:
              predictions_indexed = _index_predictions(
                  predictions, labels
              )
          else:
              predictions_indexed = predictions
  
      input_gradients = tape.gradient(
          predictions_indexed, interpolated_inputs
      )
      difference_from_reference = inputs - references
      expected_gradients = input_gradients * difference_from_reference
      return expected_gradients
  
file_path: attributionpriors/attributionpriors/eager_ops.py
imports: import tensorflow
  import numpy
label_desc: Use image node_id 4 for calling a global function with example usage: expected_gradients(inputs, labels, model, index_true_class) and returns: expected_gradients