code: def _get_target_from_target_fn(
      target_fn: Callable,
      model: tf.keras.Model,
      X: Union[np.ndarray, List[np.ndarray]],
      forward_kwargs: Optional[dict] = None,
  ) -> np.ndarray:
      """
      Generate a target vector by using the `target_fn` to pick out a
      scalar dimension from the predictions.
  
      Parameters
      ----------
      target_fn
          Target function.
      model
          Model.
      X
          Data to be explained.
      forward_kwargs
          Any additional kwargs needed for the model forward pass.
  
      Returns
      -------
      Integer array of dimension `(N, )`.
      """
      if forward_kwargs is None:
          preds = model(X)
      else:
          preds = model(X, **forward_kwargs)
  
      # raise a warning if the predictions are scalar valued already
      # TODO: in the future we want to support outputs that are >2D at which point this check should change
      if preds.shape[-1] == 1:
          msg = (
              "Predictions from the model are scalar valued but `target_fn` was passed. `target_fn` is not necessary"
              "when predictions are scalar valued already. Using `target_fn` here may result in unexpected behaviour."
          )
          warnings.warn(msg)
  
      target = target_fn(preds)
      expected_shape = (target.shape[0],)
      if target.shape != expected_shape:
          # TODO: in the future we want to support outputs that are >2D at which point this check should change
          msg = f"`target_fn` returned an array of shape {target.shape} but expected an array of shape {expected_shape}."
          raise ValueError(
              msg
          )  # TODO: raise a more specific error type?
      return target.astype(int)
  
imports: import copy
  import logging
  import string
  import warnings
  from enum import Enum
  from typing import Callable, List, Optional, Tuple, Union, cast
  import numpy
  import tensorflow
  from alibi.api.defaults import DEFAULT_DATA_INTGRAD, DEFAULT_META_INTGRAD
  from alibi.api.interfaces import Explainer, Explanation
  from alibi.utils.approximation_methods import approximation_parameters
label_desc: Use image node_id 12 for calling a global function with example usage: _get_target_from_target_fn(target_fn, model, X, forward_kwargs) and returns: target