code: def reshape_first_ndims(tensor, first_ndims, new_shape):
      """Reshapes the first n dims of the input `tensor` to `new shape`.
  
      Args:
        tensor: The input `Tensor`.
        first_ndims: A int denoting the first n dims.
        new_shape: A list of int representing the new shape.
  
      Returns:
        A reshaped `Tensor`.
      """
      assert (
          tensor.get_shape().ndims is None
          or tensor.get_shape().ndims >= first_ndims
      ), "Tensor shape is less than {} dims.".format(first_ndims)
      new_shape = tf.concat(
          [new_shape, tf.shape(input=tensor)[first_ndims:]], 0
      )
      if isinstance(tensor, tf.SparseTensor):
          return tf.sparse.reshape(tensor, new_shape)
  
      return tf.reshape(tensor, new_shape)
  
file_path: ranking/tensorflow_ranking/python/utils.py
imports: from typing import Callable, Dict, Tuple
  import tensorflow
label_desc: Use image node_id 9 for calling a global function with example usage: reshape_first_ndims(tensor, first_ndims, new_shape) and returns: tf, tf