code: def format_multiannotator_labels(
      labels: LabelLike,
  ) -> Tuple[pd.DataFrame, dict]:
      """Takes an array of labels and formats it such that labels are in the set ``0, 1, ..., K-1``,
      where ``K`` is the number of classes. The labels are assigned based on lexicographic order.
  
      Returns
      -------
      formatted_labels
          Returns pd.DataFrame of shape ``(N,M)``. The return labels will be properly formatted and can be passed to
          cleanlab.multiannotator functions.
  
      mapping
          A dictionary showing the mapping of new to old labels, such that ``mapping[k]`` returns the name of the k-th class.
      """
      if isinstance(labels, pd.DataFrame):
          np_labels = labels.values
      elif isinstance(labels, np.ndarray):
          np_labels = labels
      else:
          raise TypeError(
              "labels must be 2D numpy array or pandas DataFrame"
          )
  
      unique_labels = pd.unique(np_labels.ravel())
  
      try:
          unique_labels = unique_labels[~np.isnan(unique_labels)]
          unique_labels.sort()
      except (
          TypeError
      ):  # np.unique / np.sort cannot handle string values or pd.NA types
          nan_mask = np.array(
              [
                  (l is np.NaN) or (l is pd.NA) or (l == "nan")
                  for l in unique_labels
              ]
          )
          unique_labels = unique_labels[~nan_mask]
          unique_labels.sort()
  
      # convert float labels (that arose because np.nan is float type) to int
      if unique_labels.dtype == "float":
          unique_labels = unique_labels.astype("int")
  
      label_map = {label: i for i, label in enumerate(unique_labels)}
      inverse_map = {i: label for label, i in label_map.items()}
  
      if isinstance(labels, np.ndarray):
          labels = pd.DataFrame(labels)
  
      formatted_labels = labels.replace(label_map)
  
      return formatted_labels, inverse_map
  
file_path: cleanlab/cleanlab/internal/multiannotator_utils.py
imports: from cleanlab.typing import LabelLike
  from typing import Optional, Tuple
  import warnings
  import numpy
  import pandas
  from cleanlab.internal.validation import assert_valid_class_labels
  from cleanlab.internal.numerics import softmax
  from cleanlab.internal.util import get_num_classes, value_counts
label_desc: Use image node_id 3 for calling a global function with example usage: format_multiannotator_labels(labels) and returns: formatted_labels,  inverse_map