code: def _features_to_numpy(
      features: tf_feature_pb2.Features,
      flat_example_specs: Mapping[str, feature_lib.TensorInfo],
  ) -> Mapping[str, Union[np.ndarray, list[Any]]]:
      """Parses features to NumPy type.
  
      Args:
        features: The features of an example, encoded by TFDS.
        flat_example_specs: All tensor infos in a flat dictionary.
  
      Returns:
        The parsed NumPy object of type: np.ndarray or np.dtype.
  
      Raises:
        KeyError: if `features` and `flat_example_specs` do not correspond.
      """
      parsed_example = {}
      feature_map = features.feature
      for key in feature_map:
          ragged_row_length = _RAGGED_ROW_LENGTH_REGEX.match(key)
          ragged_flat_values = _RAGGED_FLAT_VALUES_REGEX.match(key)
          # For ragged arrays we need to reshape the np.arrays using
          # ragged_flat_values/ragged_row_lengths_*. `features` can look like:
          # {
          #     'video/image': np.array(...),
          #     'video/object/bbox': {
          #         'ragged_flat_values': np.array(...),
          #         'ragged_row_lengths_0', np.array(...),
          #     },
          # }
          if key in flat_example_specs or ragged_flat_values:
              feature_name = _key_to_feature_name(key)
              with utils.try_reraise(
                  f"Error wile parsing feature {key}: "
              ):
                  parsed_example[feature_name] = _feature_to_numpy(
                      feature_map,
                      flat_example_specs[feature_name],
                      key,
                  )
          elif ragged_row_length:
              # Lengths are extracted later for each feature in _feature_to_numpy.
              continue
          else:
              raise KeyError(
                  f"Malformed input: {key} is found in the feature, but not in"
                  f" {flat_example_specs}"
              )
      return parsed_example
  
imports: from __future__ import annotations
  import abc
  from collections.abc import Iterable, Mapping, Sequence
  import dataclasses
  import re
  from typing import Any, Union
  import numpy
  from tensorflow_datasets.core import utils
  from tensorflow_datasets.core.features import feature
  from tensorflow_datasets.core.utils import dtype_utils
  from tensorflow_datasets.core.utils.lazy_imports_utils import tensorflow
  from tensorflow_datasets.proto import tf_example_pb2
  from tensorflow_datasets.proto import tf_feature_pb2
label_desc: Use image node_id 3 for calling a global function with example usage: _features_to_numpy(features, flat_example_specs) and returns: parsed_example