




'''simple docstring'''





import functools
import operator

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


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

UpperCamelCase_		:    List[str]									=		{
    '''facebook/hubert-base-ls960''': '''https://huggingface.co/facebook/hubert-base-ls960/resolve/main/config.json''',
    # See all Hubert models at https://huggingface.co/models?filter=hubert
}

class      _a       (		__lowerCAmelCase							):
     SCREAMING_SNAKE_CASE_							:					Tuple					       =		"""hubert"""






     def __init__(				self      ,_SCREAMING_SNAKE_CASE=32      ,_SCREAMING_SNAKE_CASE=768      ,_SCREAMING_SNAKE_CASE=12      ,_SCREAMING_SNAKE_CASE=12      ,_SCREAMING_SNAKE_CASE=3_072      ,_SCREAMING_SNAKE_CASE="gelu"      ,_SCREAMING_SNAKE_CASE=0.1      ,_SCREAMING_SNAKE_CASE=0.1      ,_SCREAMING_SNAKE_CASE=0.1      ,_SCREAMING_SNAKE_CASE=True      ,_SCREAMING_SNAKE_CASE=0.0      ,_SCREAMING_SNAKE_CASE=0.1      ,_SCREAMING_SNAKE_CASE=0.1      ,_SCREAMING_SNAKE_CASE=0.0_2      ,_SCREAMING_SNAKE_CASE=1e-5      ,_SCREAMING_SNAKE_CASE="group"      ,_SCREAMING_SNAKE_CASE="gelu"      ,_SCREAMING_SNAKE_CASE=(512, 512, 512, 512, 512, 512, 512)      ,_SCREAMING_SNAKE_CASE=(5, 2, 2, 2, 2, 2, 2)      ,_SCREAMING_SNAKE_CASE=(10, 3, 3, 3, 3, 2, 2)      ,_SCREAMING_SNAKE_CASE=False      ,_SCREAMING_SNAKE_CASE=128      ,_SCREAMING_SNAKE_CASE=16      ,_SCREAMING_SNAKE_CASE=False      ,_SCREAMING_SNAKE_CASE=True      ,_SCREAMING_SNAKE_CASE=0.0_5      ,_SCREAMING_SNAKE_CASE=10      ,_SCREAMING_SNAKE_CASE=2      ,_SCREAMING_SNAKE_CASE=0.0      ,_SCREAMING_SNAKE_CASE=10      ,_SCREAMING_SNAKE_CASE=0      ,_SCREAMING_SNAKE_CASE="sum"      ,_SCREAMING_SNAKE_CASE=False      ,_SCREAMING_SNAKE_CASE=False      ,_SCREAMING_SNAKE_CASE=256      ,_SCREAMING_SNAKE_CASE=0      ,_SCREAMING_SNAKE_CASE=1      ,_SCREAMING_SNAKE_CASE=2      ,**_SCREAMING_SNAKE_CASE      ,)							->    List[Any]:
          super().__init__(**__lowerCamelCase      ,pad_token_id=__lowerCamelCase      ,bos_token_id=__lowerCamelCase      ,eos_token_id=__lowerCamelCase					)
          _snake_case								=   hidden_size
          _snake_case								=   feat_extract_norm
          _snake_case								=   feat_extract_activation
          _snake_case								=   list(__lowerCamelCase					)
          _snake_case								=   list(__lowerCamelCase					)
          _snake_case								=   list(__lowerCamelCase					)
          _snake_case								=   conv_bias
          _snake_case								=   num_conv_pos_embeddings
          _snake_case								=   num_conv_pos_embedding_groups
          _snake_case								=   len(self.conv_dim					)
          _snake_case								=   num_hidden_layers
          _snake_case								=   intermediate_size
          _snake_case								=   hidden_act
          _snake_case								=   num_attention_heads
          _snake_case								=   hidden_dropout
          _snake_case								=   attention_dropout
          _snake_case								=   activation_dropout
          _snake_case								=   feat_proj_layer_norm
          _snake_case								=   feat_proj_dropout
          _snake_case								=   final_dropout
          _snake_case								=   layerdrop
          _snake_case								=   layer_norm_eps
          _snake_case								=   initializer_range
          _snake_case								=   vocab_size
          _snake_case								=   do_stable_layer_norm
          _snake_case								=   use_weighted_layer_sum
          _snake_case								=   classifier_proj_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)`, but is `len(config.conv_dim) ="
                   f""" {len(self.conv_dim					)}`, `len(config.conv_stride) = {len(self.conv_stride					)}`,"""
                   f""" `len(config.conv_kernel) = {len(self.conv_kernel					)}`."""					)

          # fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
          _snake_case								=   apply_spec_augment
          _snake_case								=   mask_time_prob
          _snake_case								=   mask_time_length
          _snake_case								=   mask_time_min_masks
          _snake_case								=   mask_feature_prob
          _snake_case								=   mask_feature_length
          _snake_case								=   mask_feature_min_masks

          # ctc loss
          _snake_case								=   ctc_loss_reduction
          _snake_case								=   ctc_zero_infinity






     @property
     def        _lowercase			(				self					)							->    int:
          return functools.reduce(operator.mul      ,self.conv_stride      ,1					)








'''simple docstring'''





from typing import List, Optional, Tuple

from tokenizers import pre_tokenizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_clip import CLIPTokenizer


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

UpperCamelCase_		:    str									=		{'''vocab_file''': '''vocab.json''', '''merges_file''': '''merges.txt''', '''tokenizer_file''': '''tokenizer.json'''}

UpperCamelCase_		:    List[str]									=		{
    '''vocab_file''': {
        '''openai/clip-vit-base-patch32''': '''https://huggingface.co/openai/clip-vit-base-patch32/resolve/main/vocab.json''',
    },
    '''merges_file''': {
        '''openai/clip-vit-base-patch32''': '''https://huggingface.co/openai/clip-vit-base-patch32/resolve/main/merges.txt''',
    },
    '''tokenizer_file''': {
        '''openai/clip-vit-base-patch32''': (
            '''https://huggingface.co/openai/clip-vit-base-patch32/resolve/main/tokenizer.json'''
        ),
    },
}

UpperCamelCase_		:    List[Any]									=		{
    '''openai/clip-vit-base-patch32''': 77,
}

class      _a       (		__lowerCAmelCase							):
     SCREAMING_SNAKE_CASE_							:					Any					       =		VOCAB_FILES_NAMES
     SCREAMING_SNAKE_CASE_							:					List[Any]					       =		PRETRAINED_VOCAB_FILES_MAP
     SCREAMING_SNAKE_CASE_							:					Dict					       =		PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
     SCREAMING_SNAKE_CASE_							:					int					       =		["""input_ids""", """attention_mask"""]
     SCREAMING_SNAKE_CASE_							:					Optional[Any]					       =		CLIPTokenizer






     def __init__(				self      ,_SCREAMING_SNAKE_CASE=None      ,_SCREAMING_SNAKE_CASE=None      ,_SCREAMING_SNAKE_CASE=None      ,_SCREAMING_SNAKE_CASE="<|endoftext|>"      ,_SCREAMING_SNAKE_CASE="<|startoftext|>"      ,_SCREAMING_SNAKE_CASE="<|endoftext|>"      ,_SCREAMING_SNAKE_CASE="<|endoftext|>"      ,**_SCREAMING_SNAKE_CASE      ,)							->    List[Any]:
          super().__init__(
              _SCREAMING_SNAKE_CASE      ,_SCREAMING_SNAKE_CASE      ,tokenizer_file=_SCREAMING_SNAKE_CASE      ,unk_token=_SCREAMING_SNAKE_CASE      ,bos_token=_SCREAMING_SNAKE_CASE      ,eos_token=_SCREAMING_SNAKE_CASE      ,pad_token=_SCREAMING_SNAKE_CASE      ,**_SCREAMING_SNAKE_CASE      ,)

          if not isinstance(self.backend_tokenizer.pre_tokenizer      ,pre_tokenizers.Sequence					):
               raise ValueError(
                   "The `backend_tokenizer` provided does not match the expected format. The CLIP tokenizer has been"
                   " heavily modified from transformers version 4.17.0. You need to convert the tokenizer you are using"
                   " to be compatible with this version.The easiest way to do so is"
                   " `CLIPTokenizerFast.from_pretrained(\"path_to_local_folder_or_hub_repo, from_slow=True)`. If you want"
                   " to use your existing tokenizer, you will have to revert to a version prior to 4.17.0 of"
                   " transformers."					)

          self._wrap_decode_method_backend_tokenizer()






     def        _lowercase			(				self					)							->    Tuple:
          _snake_case							=   self.backend_tokenizer.decode

          def new_decode_method(*_SCREAMING_SNAKE_CASE      ,**_SCREAMING_SNAKE_CASE					):
               _snake_case							=   orig_decode_method(*_SCREAMING_SNAKE_CASE      ,**_SCREAMING_SNAKE_CASE					)
               _snake_case							=   text.replace(self.backend_tokenizer.model.end_of_word_suffix      ," "					).strip()
               return text

          _snake_case							=   new_decode_method






     def        _lowercase			(				self      ,_SCREAMING_SNAKE_CASE      ,_SCREAMING_SNAKE_CASE = None					)							->    List[int]:
          _snake_case							=   [self.bos_token_id]
          _snake_case							=   [self.eos_token_id]

          if token_ids_a is None:
               return bos_token + token_ids_a + eos_token
          return bos_token + token_ids_a + eos_token + eos_token + token_ids_a + eos_token






     def        _lowercase			(				self      ,_SCREAMING_SNAKE_CASE      ,_SCREAMING_SNAKE_CASE = None					)							->    List[int]:
          _snake_case							=   [self.bos_token_id]
          _snake_case							=   [self.eos_token_id]

          if token_ids_a is None:
               return len(bos_token + token_ids_a + eos_token					) * [0]
          return len(bos_token + token_ids_a + eos_token + eos_token + token_ids_a + eos_token					) * [0]






     def        _lowercase			(				self      ,_SCREAMING_SNAKE_CASE      ,_SCREAMING_SNAKE_CASE = None					)							->    Tuple[str]:
          _snake_case							=   self._tokenizer.model.save(_SCREAMING_SNAKE_CASE      ,name=_SCREAMING_SNAKE_CASE					)
          return tuple(_SCREAMING_SNAKE_CASE					)


