code: def format_labels(labels: LabelLike) -> Tuple[np.ndarray, 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.
      This is useful for mapping string class labels to the integer format required by many cleanlab (and sklearn) functions.
  
      Returns
      -------
      formatted_labels
          Returns np.ndarray of shape ``(N,)``. The return labels will be properly formatted and can be passed to other cleanlab functions.
  
      mapping
          A dictionary showing the mapping of new to old labels, such that ``mapping[k]`` returns the name of the k-th class.
      """
      labels = labels_to_array(labels)
      if labels.ndim != 1:
          raise ValueError("labels must be 1D numpy array.")
  
      unique_labels = np.unique(labels)
      label_map = {label: i for i, label in enumerate(unique_labels)}
      formatted_labels = np.array([label_map[l] for l in labels])
      inverse_map = {i: label for label, i in label_map.items()}
  
      return formatted_labels, inverse_map
  
imports: import warnings
  import numpy
  import pandas
  from typing import Union, Tuple
  from cleanlab.typing import DatasetLike, LabelLike
  from cleanlab.internal.validation import labels_to_array
  from cleanlab.internal.constants import FLOATING_POINT_COMPARISON, TINY_VALUE
label_desc: Use image node_id 29 for calling a global function with example usage: format_labels(labels) and returns: formatted_labels,  inverse_map