


"""simple docstring"""







import functools
import operator

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


__SCREAMING_SNAKE_CASE								=logging.get_logger(__name__)

__SCREAMING_SNAKE_CASE								={
    "microsoft/unispeech-sat-base-100h-libri-ft": (
        "https://huggingface.co/microsoft/unispeech-sat-base-100h-libri-ft/resolve/main/config.json"
    ),
    # See all UniSpeechSat models at https://huggingface.co/models?filter=unispeech_sat
}







class  UpperCamelCase	(    lowercase_						):
   lowercase							=						"unispeech-sat"
   def __init__(    self  ,__UpperCamelCase=32  ,__UpperCamelCase=768  ,__UpperCamelCase=12  ,__UpperCamelCase=12  ,__UpperCamelCase=3072  ,__UpperCamelCase="gelu"  ,__UpperCamelCase=0.1  ,__UpperCamelCase=0.1  ,__UpperCamelCase=0.1  ,__UpperCamelCase=0.0  ,__UpperCamelCase=0.0  ,__UpperCamelCase=0.1  ,__UpperCamelCase=0.1  ,__UpperCamelCase=0.02  ,__UpperCamelCase=1e-5  ,__UpperCamelCase="group"  ,__UpperCamelCase="gelu"  ,__UpperCamelCase=(512, 512, 512, 512, 512, 512, 512)  ,__UpperCamelCase=(5, 2, 2, 2, 2, 2, 2)  ,__UpperCamelCase=(10, 3, 3, 3, 3, 2, 2)  ,__UpperCamelCase=False  ,__UpperCamelCase=128  ,__UpperCamelCase=16  ,__UpperCamelCase=False  ,__UpperCamelCase=True  ,__UpperCamelCase=0.05  ,__UpperCamelCase=10  ,__UpperCamelCase=2  ,__UpperCamelCase=0.0  ,__UpperCamelCase=10  ,__UpperCamelCase=0  ,__UpperCamelCase=320  ,__UpperCamelCase=2  ,__UpperCamelCase=0.1  ,__UpperCamelCase=100  ,__UpperCamelCase=256  ,__UpperCamelCase=256  ,__UpperCamelCase=0.1  ,__UpperCamelCase="mean"  ,__UpperCamelCase=False  ,__UpperCamelCase=False  ,__UpperCamelCase=256  ,__UpperCamelCase=(512, 512, 512, 512, 1500)  ,__UpperCamelCase=(5, 3, 3, 1, 1)  ,__UpperCamelCase=(1, 2, 3, 1, 1)  ,__UpperCamelCase=512  ,__UpperCamelCase=0  ,__UpperCamelCase=1  ,__UpperCamelCase=2  ,__UpperCamelCase=504  ,**__UpperCamelCase  ,)			->   Dict:


        '''simple docstring'''


        super().__init__(**UpperCamelCase_  ,pad_token_id=UpperCamelCase_  ,bos_token_id=UpperCamelCase_  ,eos_token_id=UpperCamelCase_    )
        lowercase_			:       Tuple									=			hidden_size
        lowercase_			:       Union[str, Any]									=			feat_extract_norm
        lowercase_			:       Union[str, Any]									=			feat_extract_activation
        lowercase_			:       List[Any]									=			list(UpperCamelCase_    )
        lowercase_			:       Optional[int]									=			list(UpperCamelCase_    )
        lowercase_			:       Optional[Any]									=			list(UpperCamelCase_    )
        lowercase_			:       Tuple									=			conv_bias
        lowercase_			:       Optional[int]									=			num_conv_pos_embeddings
        lowercase_			:       int									=			num_conv_pos_embedding_groups
        lowercase_			:       List[str]									=			len(self.conv_dim    )
        lowercase_			:       Optional[Any]									=			num_hidden_layers
        lowercase_			:       str									=			intermediate_size
        lowercase_			:       Dict									=			hidden_act
        lowercase_			:       List[Any]									=			num_attention_heads
        lowercase_			:       List[str]									=			hidden_dropout
        lowercase_			:       Dict									=			attention_dropout
        lowercase_			:       Optional[Any]									=			activation_dropout
        lowercase_			:       str									=			feat_proj_dropout
        lowercase_			:       Dict									=			final_dropout
        lowercase_			:       List[str]									=			layerdrop
        lowercase_			:       Union[str, Any]									=			layer_norm_eps
        lowercase_			:       Optional[int]									=			initializer_range
        lowercase_			:       Optional[Any]									=			vocab_size
        lowercase_			:       Dict									=			num_clusters
        lowercase_			:       List[Any]									=			do_stable_layer_norm
        lowercase_			:       List[str]									=			use_weighted_layer_sum

        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
        lowercase_			:       Union[str, Any]									=			apply_spec_augment
        lowercase_			:       Optional[Any]									=			mask_time_prob
        lowercase_			:       Optional[Any]									=			mask_time_length
        lowercase_			:       Any									=			mask_time_min_masks
        lowercase_			:       Optional[int]									=			mask_feature_prob
        lowercase_			:       List[str]									=			mask_feature_length
        lowercase_			:       int									=			mask_feature_min_masks

        # parameters for pretraining with codevector quantized representations
        lowercase_			:       Union[str, Any]									=			num_codevectors_per_group
        lowercase_			:       List[Any]									=			num_codevector_groups
        lowercase_			:       Tuple									=			contrastive_logits_temperature
        lowercase_			:       Optional[int]									=			feat_quantizer_dropout
        lowercase_			:       Optional[int]									=			num_negatives
        lowercase_			:       Tuple									=			codevector_dim
        lowercase_			:       Any									=			proj_codevector_dim
        lowercase_			:       List[str]									=			diversity_loss_weight

        # ctc loss
        lowercase_			:       str									=			ctc_loss_reduction
        lowercase_			:       Optional[Any]									=			ctc_zero_infinity

        # SequenceClassification-specific parameter. Feel free to ignore for other classes.
        lowercase_			:       str									=			classifier_proj_size

        # XVector-specific parameters. Feel free to ignore for other classes.
        lowercase_			:       List[str]									=			list(UpperCamelCase_    )
        lowercase_			:       Union[str, Any]									=			list(UpperCamelCase_    )
        lowercase_			:       Dict									=			list(UpperCamelCase_    )
        lowercase_			:       List[str]									=			xvector_output_dim







   @property
   def     _UpperCAmelCase     (    self    )			->   str:


        '''simple docstring'''


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


"""simple docstring"""







__SCREAMING_SNAKE_CASE								="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"



def     lowercase__( __SCREAMING_SNAKE_CASE							:  bytes   ):
     # Make sure the supplied data is a bytes-like object
     if not isinstance(__SCREAMING_SNAKE_CASE  ,    __SCREAMING_SNAKE_CASE   ):
          lowercase_			:       Dict									=			F'''a bytes-like object is required, not \'{data.__class__.__name__}\''''
          raise TypeError(__SCREAMING_SNAKE_CASE   )

     lowercase_			:       List[Any]									=			''.join(bin(__SCREAMING_SNAKE_CASE   )[2:].zfill(8   ) for byte in data   )

     lowercase_			:       List[Any]									=			len(__SCREAMING_SNAKE_CASE   ) % 6 != 0

     if padding_needed:
          # The padding that will be added later
          lowercase_			:       Optional[int]									=			b'=' * ((6 - len(__SCREAMING_SNAKE_CASE   ) % 6) // 2)

          # Append binary_stream with arbitrary binary digits (0's by default) to make its
          # length a multiple of 6.
          binary_stream += "0" * (6 - len(__SCREAMING_SNAKE_CASE   ) % 6)
     else:
          lowercase_			:       List[Any]									=			b''

     # Encode every 6 binary digits to their corresponding Base64 character
     return (
         "".join(
             B64_CHARSET[int(binary_stream[index : index + 6]  ,    2   )]
             for index in range(0  ,    len(__SCREAMING_SNAKE_CASE   )  ,    6   )   ).encode()
         + padding
     )



def     lowercase__( __SCREAMING_SNAKE_CASE							:  str   ):
     # Make sure encoded_data is either a string or a bytes-like object
     if not isinstance(__SCREAMING_SNAKE_CASE  ,    __SCREAMING_SNAKE_CASE   ) and not isinstance(__SCREAMING_SNAKE_CASE  ,    __SCREAMING_SNAKE_CASE   ):
          lowercase_			:       Tuple									=			(
              'argument should be a bytes-like object or ASCII string, '
              F'''not \'{encoded_data.__class__.__name__}\''''
          )
          raise TypeError(__SCREAMING_SNAKE_CASE   )

     # In case encoded_data is a bytes-like object, make sure it contains only
     # ASCII characters so we convert it to a string object
     if isinstance(__SCREAMING_SNAKE_CASE  ,    __SCREAMING_SNAKE_CASE   ):
          try:
               lowercase_			:       List[str]									=			encoded_data.decode('utf-8'   )
          except UnicodeDecodeError:
               raise ValueError('base64 encoded data should only contain ASCII characters'   )

     lowercase_			:       List[str]									=			encoded_data.count('='   )

     # Check if the encoded string contains non base64 characters
     if padding:
          assert all(
              char in B64_CHARSET for char in encoded_data[:-padding]   ), "Invalid base64 character(s) found."
     else:
          assert all(
              char in B64_CHARSET for char in encoded_data   ), "Invalid base64 character(s) found."

     # Check the padding
     assert len(__SCREAMING_SNAKE_CASE   ) % 4 == 0 and padding < 3, "Incorrect padding"

     if padding:
          # Remove padding if there is one
          lowercase_			:       Union[str, Any]									=			encoded_data[:-padding]

          lowercase_			:       List[Any]									=			''.join(
              bin(B64_CHARSET.index(__SCREAMING_SNAKE_CASE   )   )[2:].zfill(6   ) for char in encoded_data   )[: -padding * 2]
     else:
          lowercase_			:       int									=			''.join(
              bin(B64_CHARSET.index(__SCREAMING_SNAKE_CASE   )   )[2:].zfill(6   ) for char in encoded_data   )

     lowercase_			:       str									=			[
         int(binary_stream[index : index + 8]  ,    2   )
         for index in range(0  ,    len(__SCREAMING_SNAKE_CASE   )  ,    8   )
     ]

     return bytes(__SCREAMING_SNAKE_CASE   )


if __name__ == "__main__":
       import doctest

       doctest.testmod()

