code: def stack_labels(
      extracts: util.StandardExtracts,
      col_names: List[str],
      model_name: Optional[str] = None,
      allow_missing_key: Optional[bool] = False,
  ) -> np.ndarray:
      """Stacks several numpy arrays in the extracts into a single one for labels.
  
      It will search for column_names in labels, features and transformed features.
      If not found, it will raise an error.
  
      Examples:
        Extracts
        {
            features: {
                'xmin': [0, 0, 0.1]
                'xmax': [1, 1, 0.5]
                'ymin_max': [[0.2, 1], [0.3, 1], [0.1, 1]]
            }
        }
        stack_labels(extracts, ['xmin', 'xmax']) ==
          np.array([[0, 1], [0, 1], [0.1, 0.5]])
        stack_labels(extracts, ['xmin', 'xmax', 'ymin_max']) =
          np.array([[0, 1, 0.2, 1], [0, 1, 0.3, 1], [0.1, 0.5, 0.1 ,1]])
  
      Args:
       extracts: TFMA extracts that stores the keys.
       col_names: Keys of columns which will be stacked.
       model_name: The name of the model for outputs.
       allow_missing_key: (Optional) If true, it will return empty array instead of
         raising errors when col_names are not found.
  
      Returns:
       A numpy array that stacks all the columns together.
  
      Raises:
       KeyError: The columns for stacking are not found in extracts.
       ValueError: The format of the input is not valid for stacking.
      """
      cols = []
  
      dict_to_search = collections.ChainMap(
          extracts.get_labels(model_name) or {},
          extracts.get_features() or {},
          extracts.get_transformed_features(model_name) or {},
      )
  
      for col_name in col_names:
          if dict_to_search and col_name in dict_to_search:
              new_cols = dict_to_search[col_name]
              if new_cols.ndim == 2:
                  cols.append(new_cols)
              elif new_cols.ndim == 1:
                  cols.append(new_cols[:, np.newaxis])
              else:
                  raise ValueError(
                      f"Dimension of input under {col_name}"
                      " should be 1 or 2."
                  )
          else:
              if allow_missing_key:
                  return np.empty((0, 5))
              else:
                  raise KeyError(
                      f"Key {col_name} is not found under labels, "
                      "features, or transformed features of the extracts."
                      "Please set allow_missing_key to True, if you want to "
                      "return empty array instead."
                  )
      result = np.hstack(cols)
      return result
  
imports: import collections
  from typing import List, Optional
  import numpy
  from tensorflow_model_analysis.metrics import metric_util
  from tensorflow_model_analysis.utils import util
label_desc: Use image node_id 1 for calling a global function with example usage: stack_labels(extracts, col_names, model_name, allow_missing_key) and returns: result, np