code: def get_per_sample_features(
      modality_features: Dict,
      modality_types: Dict,
      idx: int,
      id_mappings: Optional[Dict] = None,
  ):
      """
      Extract the modality features of one sample.
  
      Parameters
      ----------
      modality_features
          Modality features of all samples.
      modality_types
          Data types of all columns.
      idx
          The sample index.
      id_mappings
          Id-to-content mappings. The contents can be text, image, etc.
          This is used when the dataframe contains the query/response indexes instead of their contents.
  
      Returns
      -------
      One sample's modality features.
      """
      ret = dict()
      for (
          per_modality,
          per_modality_features,
      ) in modality_features.items():
          if per_modality_features:
              per_modality_ret = dict()
              for (
                  per_col_name,
                  per_col_features,
              ) in per_modality_features.items():
                  per_sample_features = per_col_features[idx]
                  if (
                      modality_types
                      and modality_types[per_modality]
                      and modality_types[per_modality][
                          per_col_name
                      ].endswith(IDENTIFIER)
                  ):
                      per_sample_features = id_mappings[per_col_name][
                          per_sample_features
                      ]
  
                  per_modality_ret[per_col_name] = per_sample_features
              ret[per_modality] = per_modality_ret
  
      return ret
  
imports: import ast
  import codecs
  import copy
  import re
  import warnings
  from io import BytesIO
  from typing import Callable, Dict, Iterable, List, Optional, Tuple, Union
  import numpy
  import pandas
  import PIL
  from omegaconf import ListConfig
  from text_unidecode import unidecode
  from timm.data.constants import IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_STD, IMAGENET_INCEPTION_MEAN, IMAGENET_INCEPTION_STD
  from tokenizers import pre_tokenizers
  from torchvision import transforms
  from ..constants import CLIP_IMAGE_MEAN, CLIP_IMAGE_STD, IDENTIFIER, IMAGE, IMAGE_BYTEARRAY, IMAGE_PATH, MMDET_IMAGE, MMLAB_MODELS
  from .collator import DictCollator
  from .preprocess_dataframe import MultiModalFeaturePreprocessor
  from .randaug import RandAugment
  from .trivial_augmenter import TrivialAugment
label_desc: Use image node_id 5 for calling a global function with example usage: get_per_sample_features(modality_features, modality_types, idx, id_mappings) and returns: ret