code: def _extract_unbatched_inputs(  # pylint: disable=invalid-name
      mixed_legacy_batched_extract: types.Extracts,
  ) -> Sequence[types.Extracts]:
      """Extract features, predictions, labels and weights from batched extract."""
      batched_extract = {}
      # TODO(mdreves): Remove record batch
      keys_to_retain = set(mixed_legacy_batched_extract)
      if constants.ARROW_RECORD_BATCH_KEY in keys_to_retain:
          keys_to_retain.remove(constants.ARROW_RECORD_BATCH_KEY)
      dataframe = pd.DataFrame()
      for key in keys_to_retain:
          # Previously a batch of transformed features were stored as a list of dicts
          # instead of a dict of np.arrays with batch dimensions. These legacy
          # conversions are done using dataframes instead.
          if isinstance(mixed_legacy_batched_extract[key], list):
              try:
                  dataframe[key] = mixed_legacy_batched_extract[key]
              except Exception as e:
                  raise RuntimeError(
                      f"Exception encountered while adding key {key} with "
                      f"batched length {len(mixed_legacy_batched_extract[key])}"
                  ) from e
          else:
              batched_extract[key] = mixed_legacy_batched_extract[key]
      unbatched_extracts = util.split_extracts(batched_extract)
      legacy_unbatched_extracts = dataframe.to_dict(orient="records")
      if unbatched_extracts and legacy_unbatched_extracts:
          if len(unbatched_extracts) != len(legacy_unbatched_extracts):
              raise ValueError(
                  f"Batch sizes have differing values: {len(unbatched_extracts)} != "
                  f"{len(legacy_unbatched_extracts)}, "
                  f"unbatched_extracts={unbatched_extracts}, "
                  f"legacy_unbatched_extracts={legacy_unbatched_extracts}"
              )
          result = []
          for unbatched_extract, legacy_unbatched_extract in zip(
              unbatched_extracts, legacy_unbatched_extracts
          ):
              legacy_unbatched_extract.update(unbatched_extract)
              result.append(legacy_unbatched_extract)
          return result
      elif legacy_unbatched_extracts:
          return legacy_unbatched_extracts
      else:
          return unbatched_extracts
  
file_path: model-analysis/tensorflow_model_analysis/extractors/unbatch_extractor.py
imports: from typing import Sequence
  import apache_beam
  import pandas
  from tensorflow_model_analysis import constants
  from tensorflow_model_analysis.api import types
  from tensorflow_model_analysis.extractors import extractor
  from tensorflow_model_analysis.utils import util
label_desc: Use image node_id 2 for calling a global function with example usage: _extract_unbatched_inputs(mixed_legacy_batched_extract) and returns: result, legacy_unbatched_extracts, unbatched_extracts