'''simple docstring'''


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 					__SCREAMING_SNAKE_CASE						(	TensorFormatter[Mapping, '''torch.Tensor''', Mapping]	):







  '''simple docstring'''






  def __init__(			self				,		snake_case_=None				,		**snake_case_						):




       '''simple docstring'''

       super().__init__(features=snake_case_						)
       UpperCAmelCase_							:       List[Any]       =				torch_tensor_kwargs
       import torch  # noqa import torch at initialization


  def _UpperCamelCase					(			self				,		snake_case_						):




       '''simple docstring'''

       import torch

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


  def _UpperCamelCase					(			self				,		snake_case_						):




       '''simple docstring'''

       import torch

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

       UpperCAmelCase_							:       Union[str, Any]       =				{}

       if isinstance(snake_case_				,		(np.number, np.ndarray)						) and np.issubdtype(value.dtype				,		np.integer						):
            UpperCAmelCase_							:       str       =				{'dtype': torch.intaa}
       elif isinstance(snake_case_				,		(np.number, np.ndarray)						) and np.issubdtype(value.dtype				,		np.floating						):
            UpperCAmelCase_							:       Optional[int]       =				{'dtype': torch.floataa}
       elif config.PIL_AVAILABLE and "PIL" in sys.modules:
            import PIL.Image

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


  def _UpperCamelCase					(			self				,		snake_case_						):




       '''simple docstring'''

       import torch

       # support for torch, tf, jax etc.
       if hasattr(snake_case_				,		'__array__'						) and not isinstance(snake_case_				,		torch.Tensor						):
            UpperCAmelCase_							:       Optional[Any]       =				data_struct.__array__()
       # support for nested types like struct of list of struct
       if isinstance(snake_case_				,		np.ndarray						):
            if data_struct.dtype == object:  # torch tensors cannot be instantied from an array of objects
                 return self._consolidate([self.recursive_tensorize(snake_case_						) for substruct in data_struct]						)
       elif isinstance(snake_case_				,		(list, tuple)						):
            return self._consolidate([self.recursive_tensorize(snake_case_						) for substruct in data_struct]						)
       return self._tensorize(snake_case_						)


  def _UpperCamelCase					(			self				,		snake_case_						):




       '''simple docstring'''

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


  def _UpperCamelCase					(			self				,		snake_case_						):




       '''simple docstring'''

       UpperCAmelCase_							:       int       =				self.numpy_arrow_extractor().extract_row(snake_case_						)
       UpperCAmelCase_							:       Tuple       =				self.python_features_decoder.decode_row(snake_case_						)
       return self.recursive_tensorize(snake_case_						)


  def _UpperCamelCase					(			self				,		snake_case_						):




       '''simple docstring'''

       UpperCAmelCase_							:       Any       =				self.numpy_arrow_extractor().extract_column(snake_case_						)
       UpperCAmelCase_							:       str       =				self.python_features_decoder.decode_column(snake_case_				,		pa_table.column_names[0]						)
       UpperCAmelCase_							:       Dict       =				self.recursive_tensorize(snake_case_						)
       UpperCAmelCase_							:       str       =				self._consolidate(snake_case_						)
       return column






  def _UpperCamelCase					(			self				,		snake_case_						):




       '''simple docstring'''

       UpperCAmelCase_							:       str       =				self.numpy_arrow_extractor().extract_batch(snake_case_						)
       UpperCAmelCase_							:       Union[str, Any]       =				self.python_features_decoder.decode_batch(snake_case_						)
       UpperCAmelCase_							:       Union[str, Any]       =				self.recursive_tensorize(snake_case_						)
       for column_name in batch:
            UpperCAmelCase_							:       Any       =				self._consolidate(batch[column_name]						)
       return batch







'''simple docstring'''


from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig


snake_case__					:      Dict				      =  {
    '''albert-base-v1''': '''https://huggingface.co/albert-base-v1/resolve/main/config.json''',
    '''albert-large-v1''': '''https://huggingface.co/albert-large-v1/resolve/main/config.json''',
    '''albert-xlarge-v1''': '''https://huggingface.co/albert-xlarge-v1/resolve/main/config.json''',
    '''albert-xxlarge-v1''': '''https://huggingface.co/albert-xxlarge-v1/resolve/main/config.json''',
    '''albert-base-v2''': '''https://huggingface.co/albert-base-v2/resolve/main/config.json''',
    '''albert-large-v2''': '''https://huggingface.co/albert-large-v2/resolve/main/config.json''',
    '''albert-xlarge-v2''': '''https://huggingface.co/albert-xlarge-v2/resolve/main/config.json''',
    '''albert-xxlarge-v2''': '''https://huggingface.co/albert-xxlarge-v2/resolve/main/config.json''',
}






class 					__SCREAMING_SNAKE_CASE						(	lowerCamelCase_	):







  '''simple docstring'''






  lowerCamelCase_		:str						   =		'''albert'''


  def __init__(			self				,		snake_case_=3_0_0_0_0				,		snake_case_=1_2_8				,		snake_case_=4_0_9_6				,		snake_case_=1_2				,		snake_case_=1				,		snake_case_=6_4				,		snake_case_=1_6_3_8_4				,		snake_case_=1				,		snake_case_="gelu_new"				,		snake_case_=0				,		snake_case_=0				,		snake_case_=5_1_2				,		snake_case_=2				,		snake_case_=0.02				,		snake_case_=1E-12				,		snake_case_=0.1				,		snake_case_="absolute"				,		snake_case_=0				,		snake_case_=2				,		snake_case_=3				,		**snake_case_				,		):




       '''simple docstring'''

       super().__init__(pad_token_id=snake_case_				,		bos_token_id=snake_case_				,		eos_token_id=snake_case_				,		**snake_case_						)

       UpperCAmelCase_							:       List[Any]       =				vocab_size
       UpperCAmelCase_							:       Dict       =				embedding_size
       UpperCAmelCase_							:       str       =				hidden_size
       UpperCAmelCase_							:       Any       =				num_hidden_layers
       UpperCAmelCase_							:       Union[str, Any]       =				num_hidden_groups
       UpperCAmelCase_							:       List[str]       =				num_attention_heads
       UpperCAmelCase_							:       Any       =				inner_group_num
       UpperCAmelCase_							:       Optional[int]       =				hidden_act
       UpperCAmelCase_							:       Tuple       =				intermediate_size
       UpperCAmelCase_							:       Any       =				hidden_dropout_prob
       UpperCAmelCase_							:       List[str]       =				attention_probs_dropout_prob
       UpperCAmelCase_							:       Union[str, Any]       =				max_position_embeddings
       UpperCAmelCase_							:       Dict       =				type_vocab_size
       UpperCAmelCase_							:       Union[str, Any]       =				initializer_range
       UpperCAmelCase_							:       Optional[Any]       =				layer_norm_eps
       UpperCAmelCase_							:       Dict       =				classifier_dropout_prob
       UpperCAmelCase_							:       Tuple       =				position_embedding_type







class 					__SCREAMING_SNAKE_CASE						(	lowerCamelCase_	):







  '''simple docstring'''






  @property
  def _UpperCamelCase					(			self						):




       '''simple docstring'''

       if self.task == "multiple-choice":
            UpperCAmelCase_							:       Optional[Any]       =				{0: 'batch', 1: 'choice', 2: 'sequence'}
       else:
            UpperCAmelCase_							:       List[Any]       =				{0: 'batch', 1: 'sequence'}
       return OrderedDict(
           [
               ('input_ids', dynamic_axis),
               ('attention_mask', dynamic_axis),
               ('token_type_ids', dynamic_axis),
           ]						)






