code: def gather_nd(
      params: Union[tf.Tensor, tf.Variable],
      indices: Union[tf.Tensor, tf.Variable],
      /,
      *,
      batch_dims: int = 0,
      out: Optional[Union[tf.Tensor, tf.Variable]] = None,
  ) -> Union[tf.Tensor, tf.Variable]:
      ivy.utils.assertions.check_gather_nd_input_valid(
          params, indices, batch_dims
      )
      try:
          return tf.gather_nd(params, indices, batch_dims=batch_dims)
      except Exception:  # fall back to compositional implementation
          batch_dims %= len(params.shape)
          result = []
          if batch_dims == 0:
              result = gather_nd_helper(params, indices)
          else:
              for b in range(batch_dims):
                  if b == 0:
                      zip_list = list(zip(params, indices))
                  else:
                      zip_list = [
                          (p, i)
                          for z in [zip(p1, i1) for p1, i1 in zip_list]
                          for p, i in z
                      ]
              for z in zip_list:
                  p, i = z
                  r = gather_nd_helper(p, i)
                  result.append(r)
              result = tf.stack(result)
              result = tf.reshape(
                  result,
                  tf.concat(
                      [params.shape[0:batch_dims], result.shape[1:]], 0
                  ),
              )
          return result
  
imports: from typing import Optional, Union, Sequence, Callable, Tuple
  import numpy
  import multiprocessing
  from numbers import Number
  import tensorflow
  import ivy
  from ivy.functional.ivy.gradients import _is_variable
  from ivy.func_wrapper import with_unsupported_dtypes
  from ivy.utils.exceptions import _check_inplace_update_support
  from .None import backend_version
  from ...ivy.general import _broadcast_to
label_desc: Use image node_id 12 for calling a global function with example usage: gather_nd() and returns: tf, result