code: def one_hot(tensor: np.ndarray, target: np.ndarray) -> np.ndarray:
      """Convert tensor's last dimension into a one-hot vector of target's shape.
  
      Args:
        tensor: Tensor to convert to one-hot vector. Must have no shape or a final
          dimension of size 1.
        target: Target tensor to reshape the tensor to.
  
      Returns:
        Tensor with last dimension encoded as a one-hot vector with the overall
        shape the same as that of target.
      """
      try:
          # For values that are OOV (i.e. set to -1) we will use a vector of all 0's.
          # When np.eye is indexed by -1, a value of all 0's followed by 1 is used for
          # the row. The following handles -1 values by adding an additional column
          # for indexing the -1 and then removing it after.
          tensor = np.delete(
              np.eye(target.shape[-1] + 1)[tensor.astype(int)],
              -1,
              axis=-1,
          )
          return tensor.reshape(target.shape)
      except IndexError as e:
          raise ValueError(
              f"invalid inputs to one_hot: tensor={tensor}, target={target}"
          ) from e
  
imports: import inspect
  import math
  from typing import Any, Callable, Dict, Iterable, Iterator, List, Mapping, Optional, Tuple, Union
  import numpy
  import tensorflow
  from tensorflow_model_analysis import constants
  from tensorflow_model_analysis.api import types
  from tensorflow_model_analysis.metrics import metric_types
  from tensorflow_model_analysis.proto import config_pb2
  from tensorflow_model_analysis.utils import util
  from tensorflow_metadata.proto.v0 import schema_pb2
label_desc: Use image node_id 25 for calling a global function with example usage: one_hot(tensor, target) and returns: tensor