
"""simple docstring"""




import functools
import operator

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


snake_case					  =						logging.get_logger(__name__)

snake_case					  =						{
    '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 	UpperCamelCase      (			__magic_name__ ):

				"""simple docstring"""



				UpperCAmelCase_							: Tuple		    =							"hubert"


				def __init__(							self						,      lowercase__=32						,      lowercase__=768						,      lowercase__=12						,      lowercase__=12						,      lowercase__=3072						,      lowercase__="gelu"						,      lowercase__=0.1						,      lowercase__=0.1						,      lowercase__=0.1						,      lowercase__=True						,      lowercase__=0.0						,      lowercase__=0.1						,      lowercase__=0.1						,      lowercase__=0.02						,      lowercase__=1E-5						,      lowercase__="group"						,      lowercase__="gelu"						,      lowercase__=(512, 512, 512, 512, 512, 512, 512)						,      lowercase__=(5, 2, 2, 2, 2, 2, 2)						,      lowercase__=(10, 3, 3, 3, 3, 2, 2)						,      lowercase__=False						,      lowercase__=128						,      lowercase__=16						,      lowercase__=False						,      lowercase__=True						,      lowercase__=0.05						,      lowercase__=10						,      lowercase__=2						,      lowercase__=0.0						,      lowercase__=10						,      lowercase__=0						,      lowercase__="sum"						,      lowercase__=False						,      lowercase__=False						,      lowercase__=256						,      lowercase__=0						,      lowercase__=1						,      lowercase__=2						,      **lowercase__						,      )       ->       Dict:
									"""simple docstring"""







									super().__init__(**lowercase__						,      pad_token_id=lowercase__						,      bos_token_id=lowercase__						,      eos_token_id=lowercase__     )
									SCREAMING_SNAKE_CASE           =      hidden_size
									SCREAMING_SNAKE_CASE           =      feat_extract_norm
									SCREAMING_SNAKE_CASE           =      feat_extract_activation
									SCREAMING_SNAKE_CASE           =      list(lowercase__     )
									SCREAMING_SNAKE_CASE           =      list(lowercase__     )
									SCREAMING_SNAKE_CASE           =      list(lowercase__     )
									SCREAMING_SNAKE_CASE           =      conv_bias
									SCREAMING_SNAKE_CASE           =      num_conv_pos_embeddings
									SCREAMING_SNAKE_CASE           =      num_conv_pos_embedding_groups
									SCREAMING_SNAKE_CASE           =      len(self.conv_dim     )
									SCREAMING_SNAKE_CASE           =      num_hidden_layers
									SCREAMING_SNAKE_CASE           =      intermediate_size
									SCREAMING_SNAKE_CASE           =      hidden_act
									SCREAMING_SNAKE_CASE           =      num_attention_heads
									SCREAMING_SNAKE_CASE           =      hidden_dropout
									SCREAMING_SNAKE_CASE           =      attention_dropout
									SCREAMING_SNAKE_CASE           =      activation_dropout
									SCREAMING_SNAKE_CASE           =      feat_proj_layer_norm
									SCREAMING_SNAKE_CASE           =      feat_proj_dropout
									SCREAMING_SNAKE_CASE           =      final_dropout
									SCREAMING_SNAKE_CASE           =      layerdrop
									SCREAMING_SNAKE_CASE           =      layer_norm_eps
									SCREAMING_SNAKE_CASE           =      initializer_range
									SCREAMING_SNAKE_CASE           =      vocab_size
									SCREAMING_SNAKE_CASE           =      do_stable_layer_norm
									SCREAMING_SNAKE_CASE           =      use_weighted_layer_sum
									SCREAMING_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
									SCREAMING_SNAKE_CASE           =      apply_spec_augment
									SCREAMING_SNAKE_CASE           =      mask_time_prob
									SCREAMING_SNAKE_CASE           =      mask_time_length
									SCREAMING_SNAKE_CASE           =      mask_time_min_masks
									SCREAMING_SNAKE_CASE           =      mask_feature_prob
									SCREAMING_SNAKE_CASE           =      mask_feature_length
									SCREAMING_SNAKE_CASE           =      mask_feature_min_masks

									# ctc loss
									SCREAMING_SNAKE_CASE           =      ctc_loss_reduction
									SCREAMING_SNAKE_CASE           =      ctc_zero_infinity




				@property
				def 				A   (							self     )       ->       Tuple:
									"""simple docstring"""







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


"""simple docstring"""




from typing import Dict, List, Optional, Tuple

from ...tokenization_utils import AddedToken, PreTrainedTokenizer
from ...utils import logging


snake_case					  =						logging.get_logger(__name__)




class 	UpperCamelCase      (			__magic_name__ ):

				"""simple docstring"""



				UpperCAmelCase_							: Dict		    =							["input_ids", "attention_mask"]


				def __init__(							self						,      lowercase__="[PAD]"						,      lowercase__="[BOS]"						,      lowercase__="[EOS]"						,      lowercase__="[MASK]"						,      lowercase__="[CLS]"						,      lowercase__="[SEP]"						,      lowercase__=2048						,      **lowercase__						,      )       ->       None:
									"""simple docstring"""







									SCREAMING_SNAKE_CASE           =      AddedToken(lowercase__						,      lstrip=lowercase__						,      rstrip=lowercase__     ) if isinstance(lowercase__						,      lowercase__     ) else pad_token
									SCREAMING_SNAKE_CASE           =      AddedToken(lowercase__						,      lstrip=lowercase__						,      rstrip=lowercase__     ) if isinstance(lowercase__						,      lowercase__     ) else bos_token
									SCREAMING_SNAKE_CASE           =      AddedToken(lowercase__						,      lstrip=lowercase__						,      rstrip=lowercase__     ) if isinstance(lowercase__						,      lowercase__     ) else eos_token
									SCREAMING_SNAKE_CASE           =      AddedToken(lowercase__						,      lstrip=lowercase__						,      rstrip=lowercase__     ) if isinstance(lowercase__						,      lowercase__     ) else mask_token
									SCREAMING_SNAKE_CASE           =      AddedToken(lowercase__						,      lstrip=lowercase__						,      rstrip=lowercase__     ) if isinstance(lowercase__						,      lowercase__     ) else cls_token
									SCREAMING_SNAKE_CASE           =      AddedToken(lowercase__						,      lstrip=lowercase__						,      rstrip=lowercase__     ) if isinstance(lowercase__						,      lowercase__     ) else sep_token

									super().__init__(
									    pad_token=lowercase__						,      bos_token=lowercase__						,      eos_token=lowercase__						,      mask_token=lowercase__						,      cls_token=lowercase__						,      sep_token=lowercase__						,      model_max_length=lowercase__						,      **lowercase__						,      )

									SCREAMING_SNAKE_CASE           =      2**8  # utf is 8 bits

									# define special tokens dict
									SCREAMING_SNAKE_CASE           =      {
									    self.pad_token: 0,
									    self.bos_token: 1,
									    self.eos_token: 2,
									    self.mask_token: 3,
									    self.cls_token: 4,
									    self.sep_token: 5,
									}
									SCREAMING_SNAKE_CASE           =      len(self.special_tokens_encoder     )
									SCREAMING_SNAKE_CASE           =      {v: k for k, v in self.special_tokens_encoder.items()}


				def 				A   (							self     )       ->       Dict[str, int]:
									"""simple docstring"""







									SCREAMING_SNAKE_CASE           =      self.special_tokens_encoder.copy()
									vocab.update(self.added_tokens_encoder     )
									for i in range(self._utf_vocab_size     ):
														SCREAMING_SNAKE_CASE           =      chr(lowercase__     )
														SCREAMING_SNAKE_CASE           =      i + len(self.special_tokens_encoder     )
									return vocab


				@property
				def 				A   (							self     )       ->       List[Any]:
									"""simple docstring"""







									return self._utf_vocab_size + self._num_special_tokens


				def 				A   (							self						,      lowercase__						,      lowercase__ = None						,      lowercase__ = False     )       ->       List[int]:
									"""simple docstring"""







									if already_has_special_tokens:
														return super().get_special_tokens_mask(
														    token_ids_a=lowercase__						,      token_ids_a=lowercase__						,      already_has_special_tokens=lowercase__     )

									# normal case: some special tokens
									if token_ids_a is None:
														return [1] + [0] * len(lowercase__     ) + [1]
									return [1] + ([0] * len(lowercase__     )) + [1] + ([0] * len(lowercase__     )) + [1]


				def 				A   (							self						,      lowercase__						,      lowercase__ = None     )       ->       List[int]:
									"""simple docstring"""







									if token_ids_a is None:
														return [self.cls_token_id] + token_ids_a + [self.sep_token_id]
									else:
														return [self.cls_token_id] + token_ids_a + [self.sep_token_id] + token_ids_a + [self.sep_token_id]


				def 				A   (							self						,      lowercase__     )       ->       List[str]:
									"""simple docstring"""







									SCREAMING_SNAKE_CASE           =      [chr(lowercase__     ) for i in text.encode('utf-8'     )]
									return tokens


				def 				A   (							self						,      lowercase__     )       ->       str:
									"""simple docstring"""







									if token in self.special_tokens_encoder:
														SCREAMING_SNAKE_CASE           =      self.special_tokens_encoder[token]
									elif token in self.added_tokens_encoder:
														SCREAMING_SNAKE_CASE           =      self.added_tokens_encoder[token]
									elif len(lowercase__     ) != 1:
														SCREAMING_SNAKE_CASE           =      self.unk_token_id
									else:
														SCREAMING_SNAKE_CASE           =      ord(lowercase__     ) + self._num_special_tokens
									return token_id


				def 				A   (							self						,      lowercase__     )       ->       int:
									"""simple docstring"""







									if index in self.special_tokens_decoder:
														SCREAMING_SNAKE_CASE           =      self.special_tokens_decoder[index]
									elif index in self.added_tokens_decoder:
														SCREAMING_SNAKE_CASE           =      self.added_tokens_decoder[index]
									else:
														SCREAMING_SNAKE_CASE           =      chr(index - self._num_special_tokens     )
									return token


				def 				A   (							self						,      lowercase__     )       ->       Dict:
									"""simple docstring"""







									SCREAMING_SNAKE_CASE           =      b''
									for token in tokens:
														if token in self.special_tokens_decoder:
																			SCREAMING_SNAKE_CASE           =      self.special_tokens_decoder[token].encode('utf-8'     )
														elif token in self.added_tokens_decoder:
																			SCREAMING_SNAKE_CASE           =      self.special_tokens_decoder[token].encode('utf-8'     )
														elif token in self.special_tokens_encoder:
																			SCREAMING_SNAKE_CASE           =      token.encode('utf-8'     )
														elif token in self.added_tokens_encoder:
																			SCREAMING_SNAKE_CASE           =      token.encode('utf-8'     )
														else:
																			SCREAMING_SNAKE_CASE           =      bytes([ord(lowercase__     )]     )
														bstring += tok_string
									SCREAMING_SNAKE_CASE           =      bstring.decode('utf-8'						,      errors='replace'     )
									return string




				def 				A   (							self						,      lowercase__						,      lowercase__ = None     )       ->       Tuple[str]:
									"""simple docstring"""







									return ()
