






# 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 torch


class    __lowercase   (						TensorFormatter[Mapping, "torch.Tensor", Mapping]	):







     '''simple docstring'''




     def __init__(					self							:      int			,						UpperCamelCase_							:      Optional[int]=None			,						**UpperCamelCase_							:      List[str]					):


         """simple docstring"""



         super().__init__(features=UpperCamelCase_					)
         __A       =						torch_tensor_kwargs
         import torch  # noqa import torch at initialization




     def 		lowerCAmelCase_  (					self							:      int			,						UpperCamelCase_							:      List[Any]					):


         """simple docstring"""



         import torch

         if isinstance(UpperCamelCase_			,						UpperCamelCase_					) and column:
             if all(
                 isinstance(UpperCamelCase_			,						torch.Tensor					) and x.shape == column[0].shape and x.dtype == column[0].dtype
                 for x in column					):
                 return torch.stack(UpperCamelCase_					)
         return column




     def 		lowerCAmelCase_  (					self							:      Tuple			,						UpperCamelCase_							:      Union[str, Any]					):


         """simple docstring"""



         import torch

         if isinstance(UpperCamelCase_			,						(str, bytes, type(UpperCamelCase_					))					):
             return value
         elif isinstance(UpperCamelCase_			,						(np.character, np.ndarray)					) and np.issubdtype(value.dtype			,						np.character					):
             return value.tolist()

         __A       =						{}

         if isinstance(UpperCamelCase_			,						(np.number, np.ndarray)					) and np.issubdtype(value.dtype			,						np.integer					):
             __A       =						{"""dtype""": torch.intaa}
         elif isinstance(UpperCamelCase_			,						(np.number, np.ndarray)					) and np.issubdtype(value.dtype			,						np.floating					):
             __A       =						{"""dtype""": torch.floataa}
         elif config.PIL_AVAILABLE and "PIL" in sys.modules:
             import PIL.Image

             if isinstance(UpperCamelCase_			,						PIL.Image.Image					):
                 __A       =						np.asarray(UpperCamelCase_					)
         return torch.tensor(UpperCamelCase_			,						**{**default_dtype, **self.torch_tensor_kwargs}					)




     def 		lowerCAmelCase_  (					self							:      Any			,						UpperCamelCase_							:      Dict					):


         """simple docstring"""



         import torch

         # support for torch, tf, jax etc.
         if hasattr(UpperCamelCase_			,						"""__array__"""					) and not isinstance(UpperCamelCase_			,						torch.Tensor					):
             __A       =						data_struct.__array__()
         # support for nested types like struct of list of struct
         if isinstance(UpperCamelCase_			,						np.ndarray					):
             if data_struct.dtype == object:  # torch 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							:      List[str]			,						UpperCamelCase_							:      dict					):


         """simple docstring"""



         return map_nested(self._recursive_tensorize			,						UpperCamelCase_			,						map_list=UpperCamelCase_					)




     def 		lowerCAmelCase_  (					self							:      str			,						UpperCamelCase_							:      pa.Table					):


         """simple docstring"""



         __A       =						self.numpy_arrow_extractor().extract_row(UpperCamelCase_					)
         __A       =						self.python_features_decoder.decode_row(UpperCamelCase_					)
         return self.recursive_tensorize(UpperCamelCase_					)




     def 		lowerCAmelCase_  (					self							:      List[str]			,						UpperCamelCase_							:      pa.Table					):


         """simple docstring"""



         __A       =						self.numpy_arrow_extractor().extract_column(UpperCamelCase_					)
         __A       =						self.python_features_decoder.decode_column(UpperCamelCase_			,						pa_table.column_names[0]					)
         __A       =						self.recursive_tensorize(UpperCamelCase_					)
         __A       =						self._consolidate(UpperCamelCase_					)
         return column





     def 		lowerCAmelCase_  (					self							:      str			,						UpperCamelCase_							:      pa.Table					):


         """simple docstring"""



         __A       =						self.numpy_arrow_extractor().extract_batch(UpperCamelCase_					)
         __A       =						self.python_features_decoder.decode_batch(UpperCamelCase_					)
         __A       =						self.recursive_tensorize(UpperCamelCase_					)
         for column_name in batch:
             __A       =						self._consolidate(batch[column_name]					)
         return batch












from ....configuration_utils import PretrainedConfig
from ....utils import logging


__a   :							List[Any]						= logging.get_logger(__name__)

# TODO: upload to AWS
__a   :							Union[str, Any]						= {
    "yjernite/retribert-base-uncased": (
        "https://huggingface.co/yjernite/retribert-base-uncased/resolve/main/config.json"
    ),
}


class    __lowercase   (						lowercase_	):







     '''simple docstring'''
     SCREAMING_SNAKE_CASE     =					"retribert"




     def __init__(					self							:      Any			,						UpperCamelCase_							:      int=30_522			,						UpperCamelCase_							:      Optional[int]=768			,						UpperCamelCase_							:      Union[str, Any]=8			,						UpperCamelCase_							:      Tuple=12			,						UpperCamelCase_							:      List[Any]=3_072			,						UpperCamelCase_							:      Tuple="gelu"			,						UpperCamelCase_							:      str=0.1			,						UpperCamelCase_							:      Dict=0.1			,						UpperCamelCase_							:      List[str]=512			,						UpperCamelCase_							:      Optional[int]=2			,						UpperCamelCase_							:      Tuple=0.02			,						UpperCamelCase_							:      List[str]=1e-12			,						UpperCamelCase_							:      Any=True			,						UpperCamelCase_							:      List[Any]=128			,						UpperCamelCase_							:      Union[str, Any]=0			,						**UpperCamelCase_							:      List[str]			,						):


         """simple docstring"""



         super().__init__(pad_token_id=UpperCamelCase_			,						**UpperCamelCase_					)

         __A       =						vocab_size
         __A       =						hidden_size
         __A       =						num_hidden_layers
         __A       =						num_attention_heads
         __A       =						hidden_act
         __A       =						intermediate_size
         __A       =						hidden_dropout_prob
         __A       =						attention_probs_dropout_prob
         __A       =						max_position_embeddings
         __A       =						type_vocab_size
         __A       =						initializer_range
         __A       =						layer_norm_eps
         __A       =						share_encoders
         __A       =						projection_dim




