code: def batch_flatten(x: Tensor) -> Tensor:
      """Flattens all but last dimension of `x` so it becomes 2D.
  
      Args:
          x: Any tensor with at least 2 dimensions
  
      Returns:
          The reshaped tensor, where all but the last dimension
          are flattened into the first dimension
      """
      return tf.reshape(x, (-1, x.shape[-1]))
  
imports: import tensorflow
  from tensorflow import Tensor
  from typing import Union, Optional
label_desc: Use image node_id 2 for calling a global function with example usage: batch_flatten(x) and returns: tf