code: def gradients(
      inputs,
      labels,
      model,
      index_true_class=True,
      multiply_by_input=False,
  ):
      """
      Computes the gradients of the output with respect to the input. Optionally mulitplies those
      gradients by the input to the model.
  
      Args:
          inputs: A [batch_size, ...]-shaped tensor. The input to a model.
          labels: A [batch_size]-shaped tensor. The true class labels, 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.
          multiply_by_input: Whether or not to multiply the gradients by the input to the model.
              Defaults to False.
      Returns:
          A tensor the same shape as the input representing the gradients of the output with
          respect to the input.
      """
      with tf.GradientTape() as tape:
          tape.watch(inputs)
          predictions = model(inputs, training=True)
  
          if index_true_class:
              predictions_indexed = _index_predictions(
                  predictions, labels
              )
          else:
              predictions_indexed = predictions
  
      input_gradients = tape.gradient(predictions_indexed, inputs)
  
      if multiply_by_input:
          input_gradients = input_gradients * inputs
  
      return input_gradients
  
file_path: attributionpriors/attributionpriors/eager_ops.py
imports: import tensorflow
  import numpy
label_desc: Use image node_id 2 for calling a global function with example usage: gradients(inputs, labels, model, index_true_class, multiply_by_input) and returns: input_gradients