code: def _feature_to_numpy(
      features: Mapping[str, tf_feature_pb2.Feature],
      tensor_info: feature_lib.TensorInfo,
      key: str,
  ) -> Union[np.ndarray, list[Any]]:
      """Parses a single feature to NumPy type.
  
      Args:
        features: TFDS features.
        tensor_info: Tensor info for the current feature.
        key: full name of the feature to convert to NumPy.
  
      Returns:
        The parsed NumPy object of type: np.ndarray or np.dtype.
  
      Raises:
        AttributeError: if the parsed feature is malformed.
        KeyError: if feature_name is not found in example_specs.
        ValueError: if a scalar feature is represented by an array.
      """
      if key not in features:
          raise KeyError(f"Malformed input: {key} is not in {features}")
      feature = features[key]
      dtype = tensor_info.np_dtype
      shape = tensor_info.shape
      if feature.HasField("int64_list"):
          value_array = feature.int64_list.value
      elif feature.HasField("float_list"):
          value_array = feature.float_list.value
      elif feature.HasField("bytes_list"):
          value_array = feature.bytes_list.value
      else:
          raise AttributeError(
              f"cannot convert '{key}' from proto to NumPy"
          )
      value_array = np.array(value_array, dtype=dtype)
      if not shape:
          return value_array.item()
      feature_name = _key_to_feature_name(key)
      row_lengths = _extract_row_lengths(features, feature_name)
      return reshape_ragged_tensor(value_array, row_lengths, shape)
  
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 4 for calling a global function with example usage: _feature_to_numpy(features, tensor_info, key) and returns: reshape_ragged_tensor, value_array