





import functools
import operator

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


_lowerCamelCase      							=   logging.get_logger(__name__)

_lowerCamelCase      							=   {
    '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       __A							(   lowerCamelCase__	):




      """simple docstring"""







      UpperCAmelCase__							=   """sew-d"""


      def __init__(		self   ,				a__=32   ,				a__=768   ,				a__=12   ,				a__=12   ,				a__=3072   ,				a__=2   ,				a__=512   ,				a__=256   ,				a__=True   ,				a__=True   ,				a__=("p2c", "c2p")   ,				a__="layer_norm"   ,				a__="gelu_python"   ,				a__=0.1   ,				a__=0.1   ,				a__=0.1   ,				a__=0.0   ,				a__=0.1   ,				a__=0.02   ,				a__=1e-7   ,				a__=1e-5   ,				a__="group"   ,				a__="gelu"   ,				a__=(64, 128, 128, 128, 128, 256, 256, 256, 256, 512, 512, 512, 512)   ,				a__=(5, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1)   ,				a__=(10, 3, 1, 3, 1, 3, 1, 3, 1, 2, 1, 2, 1)   ,				a__=False   ,				a__=128   ,				a__=16   ,				a__=True   ,				a__=0.05   ,				a__=10   ,				a__=2   ,				a__=0.0   ,				a__=10   ,				a__=0   ,				a__="mean"   ,				a__=False   ,				a__=False   ,				a__=256   ,				a__=0   ,				a__=1   ,				a__=2   ,				**a__   ,				):



             """simple docstring"""





             super().__init__(**a__   ,				pad_token_id=a__   ,				bos_token_id=a__   ,				eos_token_id=a__)
             _lowerCamelCase				:  Optional[int]						=		hidden_size
             _lowerCamelCase				:  int						=		feat_extract_norm
             _lowerCamelCase				:  Tuple						=		feat_extract_activation
             _lowerCamelCase				:  Optional[Any]						=		list(a__)
             _lowerCamelCase				:  Tuple						=		list(a__)
             _lowerCamelCase				:  str						=		list(a__)
             _lowerCamelCase				:  Tuple						=		conv_bias
             _lowerCamelCase				:  List[Any]						=		num_conv_pos_embeddings
             _lowerCamelCase				:  List[str]						=		num_conv_pos_embedding_groups
             _lowerCamelCase				:  Optional[int]						=		len(self.conv_dim)
             _lowerCamelCase				:  int						=		num_hidden_layers
             _lowerCamelCase				:  Tuple						=		intermediate_size
             _lowerCamelCase				:  Dict						=		squeeze_factor
             _lowerCamelCase				:  Union[str, Any]						=		max_position_embeddings
             _lowerCamelCase				:  Union[str, Any]						=		position_buckets
             _lowerCamelCase				:  List[str]						=		share_att_key
             _lowerCamelCase				:  Optional[int]						=		relative_attention
             _lowerCamelCase				:  int						=		norm_rel_ebd
             _lowerCamelCase				:  Optional[Any]						=		list(a__)
             _lowerCamelCase				:  str						=		hidden_act
             _lowerCamelCase				:  Any						=		num_attention_heads
             _lowerCamelCase				:  Dict						=		hidden_dropout
             _lowerCamelCase				:  Tuple						=		attention_dropout
             _lowerCamelCase				:  Optional[int]						=		activation_dropout
             _lowerCamelCase				:  int						=		feat_proj_dropout
             _lowerCamelCase				:  Union[str, Any]						=		final_dropout
             _lowerCamelCase				:  Any						=		layer_norm_eps
             _lowerCamelCase				:  Optional[Any]						=		feature_layer_norm_eps
             _lowerCamelCase				:  Union[str, Any]						=		initializer_range
             _lowerCamelCase				:  Union[str, 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
             _lowerCamelCase				:  str						=		apply_spec_augment
             _lowerCamelCase				:  str						=		mask_time_prob
             _lowerCamelCase				:  List[str]						=		mask_time_length
             _lowerCamelCase				:  List[str]						=		mask_time_min_masks
             _lowerCamelCase				:  Tuple						=		mask_feature_prob
             _lowerCamelCase				:  Optional[int]						=		mask_feature_length
             _lowerCamelCase				:  Dict						=		mask_feature_min_masks

             # ctc loss
             _lowerCamelCase				:  Any						=		ctc_loss_reduction
             _lowerCamelCase				:  Optional[Any]						=		ctc_zero_infinity

             # sequence classification
             _lowerCamelCase				:  Tuple						=		use_weighted_layer_sum
             _lowerCamelCase				:  Any						=		classifier_proj_size



      @property
      def 					__snake_case      (		self):



             """simple docstring"""





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








import copy
import random

from transformers import CLIPTokenizer







class       __A							(   lowerCamelCase__	):




      """simple docstring"""







      def __init__(		self   ,				*a__   ,				**a__):



             """simple docstring"""





             super().__init__(*a__   ,				**a__)
             _lowerCamelCase				:  Optional[Any]						=		{}


      def 					__snake_case      (		self   ,				a__   ,				*a__   ,				**a__):



             """simple docstring"""





             _lowerCamelCase				:  Optional[int]						=		super().add_tokens(a__   ,				*a__   ,				**a__)
             if num_added_tokens == 0:
                    raise ValueError(
                        F"""The tokenizer already contains the token {placeholder_token}. Please pass a different"""
                        ''' `placeholder_token` that is not already in the tokenizer.''')


      def 					__snake_case      (		self   ,				a__   ,				*a__   ,				a__=1   ,				**a__):



             """simple docstring"""





             _lowerCamelCase				:  Tuple						=		[]
             if num_vec_per_token == 1:
                    self.try_adding_tokens(a__   ,				*a__   ,				**a__)
                    output.append(a__)
             else:
                    _lowerCamelCase				:  Dict						=		[]
                    for i in range(a__):
                           _lowerCamelCase				:  Optional[Any]						=		placeholder_token + F"""_{i}"""
                           self.try_adding_tokens(a__   ,				*a__   ,				**a__)
                           output.append(a__)
        # handle cases where there is a new placeholder token that contains the current placeholder token but is larger
             for token in self.token_map:
                    if token in placeholder_token:
                           raise ValueError(
                               F"""The tokenizer already has placeholder token {token} that can get confused with"""
                               F""" {placeholder_token}keep placeholder tokens independent""")
             _lowerCamelCase				:  int						=		output


      def 					__snake_case      (		self   ,				a__   ,				a__=False   ,				a__=1.0):



             """simple docstring"""





             if isinstance(a__   ,				a__):
                    _lowerCamelCase				:  Tuple						=		[]
                    for i in range(len(a__)):
                           output.append(self.replace_placeholder_tokens_in_text(text[i]   ,				vector_shuffle=a__))
                    return output
             for placeholder_token in self.token_map:
                    if placeholder_token in text:
                           _lowerCamelCase				:  Union[str, Any]						=		self.token_map[placeholder_token]
                           _lowerCamelCase				:  Optional[Any]						=		tokens[: 1 + int(len(a__) * prop_tokens_to_load)]
                           if vector_shuffle:
                                  _lowerCamelCase				:  int						=		copy.copy(a__)
                                  random.shuffle(a__)
                           _lowerCamelCase				:  List[str]						=		text.replace(a__   ,				''' '''.join(a__))
             return text


      def __call__(		self   ,				a__   ,				*a__   ,				a__=False   ,				a__=1.0   ,				**a__):



             """simple docstring"""





             return super().__call__(
                 self.replace_placeholder_tokens_in_text(
                     a__   ,				vector_shuffle=a__   ,				prop_tokens_to_load=a__)   ,				*a__   ,				**a__   ,				)



      def 					__snake_case      (		self   ,				a__   ,				*a__   ,				a__=False   ,				a__=1.0   ,				**a__):



             """simple docstring"""





             return super().encode(
                 self.replace_placeholder_tokens_in_text(
                     a__   ,				vector_shuffle=a__   ,				prop_tokens_to_load=a__)   ,				*a__   ,				**a__   ,				)

