code: 
  '''simple docstring'''
  # Lint as: python3
  import sys
  from collections.abc import Mapping
  from typing import TYPE_CHECKING
  
  import numpy as np
  import pyarrow as pa
  
  from .. import config
  from ..utils.py_utils import map_nested
  from .formatting import TensorFormatter
  
  
  if TYPE_CHECKING:
        import tensorflow as tf
  
  
  
  
  
  
  class   snake_case__					(			TensorFormatter[Mapping, """tf.Tensor""", Mapping]				):
  
  
  
  
  
  
  
    """simple docstring"""
  
    def __init__(			self							: Dict     ,  UpperCamelCase__							: Any=None     ,  **UpperCamelCase__							: str			)	-> List[Any]:
  
  
  
  
  
  
      """simple docstring"""
  
  
  
  
  
  
  
      super().__init__(features=UpperCamelCase__			)
      snake_case     :					str     =	tf_tensor_kwargs
      import tensorflow as tf  # noqa: import tf at initialization
  
  
  
    def 			lowerCAmelCase							(			self							: Optional[Any]     ,  UpperCamelCase__							: Union[str, Any]			)	-> Any:
  
  
  
  
  
  
      """simple docstring"""
  
  
  
  
  
  
  
      import tensorflow as tf
  
      if isinstance(UpperCamelCase__     ,  UpperCamelCase__			) and column:
        if all(
            isinstance(UpperCamelCase__     ,  tf.Tensor			) and x.shape == column[0].shape and x.dtype == column[0].dtype for x in column			):
          return tf.stack(UpperCamelCase__			)
        elif all(
            isinstance(UpperCamelCase__     ,  (tf.Tensor, tf.RaggedTensor)			) and x.ndim == 1 and x.dtype == column[0].dtype
            for x in column			):
          # only rag 1-D tensors, otherwise some dimensions become ragged even though they were consolidated
          return tf.ragged.stack(UpperCamelCase__			)
  
      return column
  
  
  
    def 			lowerCAmelCase							(			self							: Any     ,  UpperCamelCase__							: Union[str, Any]			)	-> List[str]:
  
  
  
  
  
  
      """simple docstring"""
  
  
  
  
  
  
  
      import tensorflow as tf
  
      if value is None:
        return value
  
      snake_case     :					List[Any]     =	{}
  
      if isinstance(UpperCamelCase__     ,  (np.number, np.ndarray)			) and np.issubdtype(value.dtype     ,  np.integer			):
        snake_case     :					int     =	{'dtype': tf.intaa}
      elif isinstance(UpperCamelCase__     ,  (np.number, np.ndarray)			) and np.issubdtype(value.dtype     ,  np.floating			):
        snake_case     :					List[Any]     =	{'dtype': tf.floataa}
      elif config.PIL_AVAILABLE and "PIL" in sys.modules:
        import PIL.Image
  
        if isinstance(UpperCamelCase__     ,  PIL.Image.Image			):
          snake_case     :					Union[str, Any]     =	np.asarray(UpperCamelCase__			)
  
      return tf.convert_to_tensor(UpperCamelCase__     ,  **{**default_dtype, **self.tf_tensor_kwargs}			)
  
  
  
    def 			lowerCAmelCase							(			self							: Dict     ,  UpperCamelCase__							: Any			)	-> str:
  
  
  
  
  
  
      """simple docstring"""
  
  
  
  
  
  
  
      import tensorflow as tf
  
      # support for torch, tf, jax etc.
      if config.TORCH_AVAILABLE and "torch" in sys.modules:
        import torch
  
        if isinstance(UpperCamelCase__     ,  torch.Tensor			):
          return self._tensorize(data_struct.detach().cpu().numpy()[()]			)
      if hasattr(UpperCamelCase__     ,  '''__array__'''			) and not isinstance(UpperCamelCase__     ,  tf.Tensor			):
        snake_case     :					List[Any]     =	data_struct.__array__()
      # support for nested types like struct of list of struct
      if isinstance(UpperCamelCase__     ,  np.ndarray			):
        if data_struct.dtype == object:  # tf tensors cannot be instantied from an array of objects
          return self._consolidate([self.recursive_tensorize(UpperCamelCase__			) for substruct in data_struct]			)
      elif isinstance(UpperCamelCase__     ,  (list, tuple)			):
        return self._consolidate([self.recursive_tensorize(UpperCamelCase__			) for substruct in data_struct]			)
      return self._tensorize(UpperCamelCase__			)
  
  
  
    def 			lowerCAmelCase							(			self							: Tuple     ,  UpperCamelCase__							: dict			)	-> Optional[Any]:
  
  
  
  
  
  
      """simple docstring"""
  
  
  
  
  
  
  
      return map_nested(self._recursive_tensorize     ,  UpperCamelCase__     ,  map_list=UpperCamelCase__			)
  
  
  
    def 			lowerCAmelCase							(			self							: int     ,  UpperCamelCase__							: pa.Table			)	-> Mapping:
  
  
  
  
  
  
      """simple docstring"""
  
  
  
  
  
  
  
      snake_case     :					List[Any]     =	self.numpy_arrow_extractor().extract_row(UpperCamelCase__			)
      snake_case     :					int     =	self.python_features_decoder.decode_row(UpperCamelCase__			)
      return self.recursive_tensorize(UpperCamelCase__			)
  
  
  
    def 			lowerCAmelCase							(			self							: Dict     ,  UpperCamelCase__							: pa.Table			)	-> "tf.Tensor":
  
  
  
  
  
  
      """simple docstring"""
  
  
  
  
  
  
  
      snake_case     :					str     =	self.numpy_arrow_extractor().extract_column(UpperCamelCase__			)
      snake_case     :					Union[str, Any]     =	self.python_features_decoder.decode_column(UpperCamelCase__     ,  pa_table.column_names[0]			)
      snake_case     :					Tuple     =	self.recursive_tensorize(UpperCamelCase__			)
      snake_case     :					Dict     =	self._consolidate(UpperCamelCase__			)
      return column
  
  
  
    def 			lowerCAmelCase							(			self							: Union[str, Any]     ,  UpperCamelCase__							: pa.Table			)	-> Mapping:
  
  
  
  
  
  
      """simple docstring"""
  
  
  
  
  
  
  
      snake_case     :					Optional[Any]     =	self.numpy_arrow_extractor().extract_batch(UpperCamelCase__			)
      snake_case     :					Optional[int]     =	self.python_features_decoder.decode_batch(UpperCamelCase__			)
      snake_case     :					List[Any]     =	self.recursive_tensorize(UpperCamelCase__			)
      for column_name in batch:
        snake_case     :					Optional[Any]     =	self._consolidate(batch[column_name]			)
      return batch
  
  
  
style_context: 
  '''simple docstring'''
  from typing import TYPE_CHECKING
  
  from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available
  
  
  lowercase__						=			{
      "configuration_flava": [
          "FLAVA_PRETRAINED_CONFIG_ARCHIVE_MAP",
          "FlavaConfig",
          "FlavaImageCodebookConfig",
          "FlavaImageConfig",
          "FlavaMultimodalConfig",
          "FlavaTextConfig",
      ],
  }
  
  try:
  						if not is_vision_available():
  												raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
  						pass
  else:
  						lowercase__						=			["FlavaFeatureExtractor"]
  						lowercase__						=			["FlavaImageProcessor"]
  						lowercase__						=			["FlavaProcessor"]
  
  try:
  						if not is_torch_available():
  												raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
  						pass
  else:
  						lowercase__						=			[
  						    "FLAVA_PRETRAINED_MODEL_ARCHIVE_LIST",
  						    "FlavaForPreTraining",
  						    "FlavaImageCodebook",
  						    "FlavaImageModel",
  						    "FlavaModel",
  						    "FlavaMultimodalModel",
  						    "FlavaPreTrainedModel",
  						    "FlavaTextModel",
  						]
  
  if TYPE_CHECKING:
  						from .configuration_flava import (
  						    FLAVA_PRETRAINED_CONFIG_ARCHIVE_MAP,
  						    FlavaConfig,
  						    FlavaImageCodebookConfig,
  						    FlavaImageConfig,
  						    FlavaMultimodalConfig,
  						    FlavaTextConfig,
  						)
  
  						try:
  												if not is_vision_available():
  																		raise OptionalDependencyNotAvailable()
  						except OptionalDependencyNotAvailable:
  												pass
  						else:
  												from .feature_extraction_flava import FlavaFeatureExtractor
  												from .image_processing_flava import FlavaImageProcessor
  												from .processing_flava import FlavaProcessor
  
  						try:
  												if not is_torch_available():
  																		raise OptionalDependencyNotAvailable()
  						except OptionalDependencyNotAvailable:
  												pass
  						else:
  												from .modeling_flava import (
  												    FLAVA_PRETRAINED_MODEL_ARCHIVE_LIST,
  												    FlavaForPreTraining,
  												    FlavaImageCodebook,
  												    FlavaImageModel,
  												    FlavaModel,
  												    FlavaMultimodalModel,
  												    FlavaPreTrainedModel,
  												    FlavaTextModel,
  												)
  
  else:
  						import sys
  
  						lowercase__						=			_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)
  
  
  