
import functools
import operator

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


UpperCAmelCase__		:     Optional[int]     			=      logging.get_logger(__name__)

UpperCAmelCase__		:     int     			=      {
    'asapp/sew-d-tiny-100k': 'https://huggingface.co/asapp/sew-d-tiny-100k/resolve/main/config.json',
    # See all SEW-D models at https://huggingface.co/models?filter=sew-d
}






class UpperCAmelCase   (						SCREAMING_SNAKE_CASE__   ):





   '''simple docstring'''
   __UpperCamelCase		:    List[str] 				=    '''sew-d'''


   def __init__(					self     :							Dict			,			lowerCAmelCase_     :							Union[str, Any]=3_2			,			lowerCAmelCase_     :							Tuple=7_6_8			,			lowerCAmelCase_     :							List[Any]=1_2			,			lowerCAmelCase_     :							Optional[int]=1_2			,			lowerCAmelCase_     :							str=3_0_7_2			,			lowerCAmelCase_     :							Tuple=2			,			lowerCAmelCase_     :							int=5_1_2			,			lowerCAmelCase_     :							Any=2_5_6			,			lowerCAmelCase_     :							str=True			,			lowerCAmelCase_     :							Optional[Any]=True			,			lowerCAmelCase_     :							List[Any]=("p2c", "c2p")			,			lowerCAmelCase_     :							Any="layer_norm"			,			lowerCAmelCase_     :							List[str]="gelu_python"			,			lowerCAmelCase_     :							int=0.1			,			lowerCAmelCase_     :							Any=0.1			,			lowerCAmelCase_     :							Optional[Any]=0.1			,			lowerCAmelCase_     :							str=0.0			,			lowerCAmelCase_     :							int=0.1			,			lowerCAmelCase_     :							int=0.02			,			lowerCAmelCase_     :							List[Any]=1e-7			,			lowerCAmelCase_     :							Optional[int]=1e-5			,			lowerCAmelCase_     :							List[str]="group"			,			lowerCAmelCase_     :							Dict="gelu"			,			lowerCAmelCase_     :							int=(6_4, 1_2_8, 1_2_8, 1_2_8, 1_2_8, 2_5_6, 2_5_6, 2_5_6, 2_5_6, 5_1_2, 5_1_2, 5_1_2, 5_1_2)			,			lowerCAmelCase_     :							Union[str, Any]=(5, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1)			,			lowerCAmelCase_     :							List[str]=(1_0, 3, 1, 3, 1, 3, 1, 3, 1, 2, 1, 2, 1)			,			lowerCAmelCase_     :							Union[str, Any]=False			,			lowerCAmelCase_     :							List[str]=1_2_8			,			lowerCAmelCase_     :							Dict=1_6			,			lowerCAmelCase_     :							Dict=True			,			lowerCAmelCase_     :							Union[str, Any]=0.05			,			lowerCAmelCase_     :							str=1_0			,			lowerCAmelCase_     :							Union[str, Any]=2			,			lowerCAmelCase_     :							List[str]=0.0			,			lowerCAmelCase_     :							Tuple=1_0			,			lowerCAmelCase_     :							Union[str, Any]=0			,			lowerCAmelCase_     :							Tuple="mean"			,			lowerCAmelCase_     :							Dict=False			,			lowerCAmelCase_     :							Tuple=False			,			lowerCAmelCase_     :							Optional[int]=2_5_6			,			lowerCAmelCase_     :							Optional[Any]=0			,			lowerCAmelCase_     :							Any=1			,			lowerCAmelCase_     :							Optional[int]=2			,			**lowerCAmelCase_     :							Tuple			,			):

      """simple docstring"""
      super().__init__(**lowerCAmelCase_			,			pad_token_id=lowerCAmelCase_			,			bos_token_id=lowerCAmelCase_			,			eos_token_id=lowerCAmelCase_     )
      _A:  int					=       hidden_size
      _A:  Tuple					=       feat_extract_norm
      _A:  int					=       feat_extract_activation
      _A:  Union[str, Any]					=       list(lowerCAmelCase_     )
      _A:  List[Any]					=       list(lowerCAmelCase_     )
      _A:  Optional[int]					=       list(lowerCAmelCase_     )
      _A:  int					=       conv_bias
      _A:  Tuple					=       num_conv_pos_embeddings
      _A:  Any					=       num_conv_pos_embedding_groups
      _A:  List[Any]					=       len(self.conv_dim     )
      _A:  Any					=       num_hidden_layers
      _A:  Optional[int]					=       intermediate_size
      _A:  Optional[int]					=       squeeze_factor
      _A:  Optional[Any]					=       max_position_embeddings
      _A:  str					=       position_buckets
      _A:  int					=       share_att_key
      _A:  Dict					=       relative_attention
      _A:  List[Any]					=       norm_rel_ebd
      _A:  Union[str, Any]					=       list(lowerCAmelCase_     )
      _A:  Optional[Any]					=       hidden_act
      _A:  Optional[int]					=       num_attention_heads
      _A:  int					=       hidden_dropout
      _A:  Tuple					=       attention_dropout
      _A:  Any					=       activation_dropout
      _A:  Optional[int]					=       feat_proj_dropout
      _A:  List[str]					=       final_dropout
      _A:  List[str]					=       layer_norm_eps
      _A:  int					=       feature_layer_norm_eps
      _A:  Optional[Any]					=       initializer_range
      _A:  List[Any]					=       vocab_size

      if (
          (len(self.conv_stride     ) != self.num_feat_extract_layers)
          or (len(self.conv_kernel     ) != self.num_feat_extract_layers)
          or (len(self.conv_dim     ) != self.num_feat_extract_layers)
      ):
         raise ValueError(
             '''Configuration for convolutional layers is incorrect.'''
             '''It is required that `len(config.conv_dim)` == `len(config.conv_stride)` == `len(config.conv_kernel)`,'''
             F"""but is `len(config.conv_dim) = {len(self.conv_dim     )}`, `len(config.conv_stride)"""
             F"""= {len(self.conv_stride     )}`, `len(config.conv_kernel) = {len(self.conv_kernel     )}`."""     )

      # fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
      _A:  List[Any]					=       apply_spec_augment
      _A:  Dict					=       mask_time_prob
      _A:  Tuple					=       mask_time_length
      _A:  int					=       mask_time_min_masks
      _A:  Any					=       mask_feature_prob
      _A:  List[str]					=       mask_feature_length
      _A:  Tuple					=       mask_feature_min_masks

      # ctc loss
      _A:  Optional[int]					=       ctc_loss_reduction
      _A:  Tuple					=       ctc_zero_infinity

      # sequence classification
      _A:  List[str]					=       use_weighted_layer_sum
      _A:  Tuple					=       classifier_proj_size


   @property
   def  __magic_name__				(					self     :							Dict     ):

      """simple docstring"""
      return functools.reduce(operator.mul			,			self.conv_stride			,			1     )





import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_convbert import ConvBertTokenizer


UpperCAmelCase__		:     Optional[Any]     			=      logging.get_logger(__name__)

UpperCAmelCase__		:     Dict     			=      {'vocab_file': 'vocab.txt'}

UpperCAmelCase__		:     List[Any]     			=      {
    'vocab_file': {
        'YituTech/conv-bert-base': 'https://huggingface.co/YituTech/conv-bert-base/resolve/main/vocab.txt',
        'YituTech/conv-bert-medium-small': (
            'https://huggingface.co/YituTech/conv-bert-medium-small/resolve/main/vocab.txt'
        ),
        'YituTech/conv-bert-small': 'https://huggingface.co/YituTech/conv-bert-small/resolve/main/vocab.txt',
    }
}

UpperCAmelCase__		:     Union[str, Any]     			=      {
    'YituTech/conv-bert-base': 512,
    'YituTech/conv-bert-medium-small': 512,
    'YituTech/conv-bert-small': 512,
}


UpperCAmelCase__		:     Dict     			=      {
    'YituTech/conv-bert-base': {'do_lower_case': True},
    'YituTech/conv-bert-medium-small': {'do_lower_case': True},
    'YituTech/conv-bert-small': {'do_lower_case': True},
}






class UpperCAmelCase   (						SCREAMING_SNAKE_CASE__   ):





   '''simple docstring'''
   __UpperCamelCase		:    Any 				=    VOCAB_FILES_NAMES
   __UpperCamelCase		:    Tuple 				=    PRETRAINED_VOCAB_FILES_MAP
   __UpperCamelCase		:    str 				=    PRETRAINED_INIT_CONFIGURATION
   __UpperCamelCase		:    int 				=    PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
   __UpperCamelCase		:    int 				=    ConvBertTokenizer


   def __init__(					self     :							Tuple			,			lowerCAmelCase_     :							int=None			,			lowerCAmelCase_     :							List[Any]=None			,			lowerCAmelCase_     :							Optional[Any]=True			,			lowerCAmelCase_     :							List[Any]="[UNK]"			,			lowerCAmelCase_     :							Optional[Any]="[SEP]"			,			lowerCAmelCase_     :							Optional[Any]="[PAD]"			,			lowerCAmelCase_     :							List[Any]="[CLS]"			,			lowerCAmelCase_     :							Optional[int]="[MASK]"			,			lowerCAmelCase_     :							Any=True			,			lowerCAmelCase_     :							List[str]=None			,			**lowerCAmelCase_     :							List[Any]			,			):

      """simple docstring"""
      super().__init__(
          lowerCAmelCase_			,			tokenizer_file=lowerCAmelCase_			,			do_lower_case=lowerCAmelCase_			,			unk_token=lowerCAmelCase_			,			sep_token=lowerCAmelCase_			,			pad_token=lowerCAmelCase_			,			cls_token=lowerCAmelCase_			,			mask_token=lowerCAmelCase_			,			tokenize_chinese_chars=lowerCAmelCase_			,			strip_accents=lowerCAmelCase_			,			**lowerCAmelCase_			,			)

      _A:  List[Any]					=       json.loads(self.backend_tokenizer.normalizer.__getstate__()     )
      if (
          normalizer_state.get('''lowercase'''			,			lowerCAmelCase_     ) != do_lower_case
          or normalizer_state.get('''strip_accents'''			,			lowerCAmelCase_     ) != strip_accents
          or normalizer_state.get('''handle_chinese_chars'''			,			lowerCAmelCase_     ) != tokenize_chinese_chars
      ):
         _A:  List[str]					=       getattr(lowerCAmelCase_			,			normalizer_state.pop('''type'''     )     )
         _A:  List[Any]					=       do_lower_case
         _A:  Optional[Any]					=       strip_accents
         _A:  Union[str, Any]					=       tokenize_chinese_chars
         _A:  Optional[int]					=       normalizer_class(**lowerCAmelCase_     )

      _A:  Optional[Any]					=       do_lower_case


   def  __magic_name__				(					self     :							str			,			lowerCAmelCase_     :							Tuple			,			lowerCAmelCase_     :							Union[str, Any]=None     ):

      """simple docstring"""
      _A:  Dict					=       [self.cls_token_id] + token_ids_a + [self.sep_token_id]

      if token_ids_a:
         output += token_ids_a + [self.sep_token_id]

      return output


   def  __magic_name__				(					self     :							Union[str, Any]			,			lowerCAmelCase_     :							List[int]			,			lowerCAmelCase_     :							Optional[List[int]] = None     ):

      """simple docstring"""
      _A:  Any					=       [self.sep_token_id]
      _A:  int					=       [self.cls_token_id]
      if token_ids_a is None:
         return len(cls + token_ids_a + sep     ) * [0]
      return len(cls + token_ids_a + sep     ) * [0] + len(token_ids_a + sep     ) * [1]


   def  __magic_name__				(					self     :							int			,			lowerCAmelCase_     :							str			,			lowerCAmelCase_     :							Optional[str] = None     ):

      """simple docstring"""
      _A:  str					=       self._tokenizer.model.save(lowerCAmelCase_			,			name=lowerCAmelCase_     )
      return tuple(lowerCAmelCase_     )



