



"""simple docstring"""

import os
from typing import List, Optional, Union

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


lowercase__			   =  logging.get_logger(__name__)

lowercase__			   =  {'vocab_file': 'vocab.txt'}

lowercase__			   =  {
    'vocab_file': {
        'facebook/esm2_t6_8M_UR50D': 'https://huggingface.co/facebook/esm2_t6_8M_UR50D/resolve/main/vocab.txt',
        'facebook/esm2_t12_35M_UR50D': 'https://huggingface.co/facebook/esm2_t12_35M_UR50D/resolve/main/vocab.txt',
    },
}

lowercase__			   =  {
    'facebook/esm2_t6_8M_UR50D': 1024,
    'facebook/esm2_t12_35M_UR50D': 1024,
}





def       __magic_name__    (   _lowerCamelCase				: List[str]					):
							with open(__lowerCAmelCase  ,       """r"""					) as f:
														__a		:		Optional[int]									=       f.read().splitlines()
														return [l.strip() for l in lines]







class SCREAMING_SNAKE_CASE__					(		__snake_case      ):
						_lowerCAmelCase							=					VOCAB_FILES_NAMES
						_lowerCAmelCase							=					PRETRAINED_VOCAB_FILES_MAP
						_lowerCAmelCase							=					PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
						_lowerCAmelCase							=					["input_ids", "attention_mask"]



						def __init__(self						,     _lowercase						,     _lowercase="<unk>"						,     _lowercase="<cls>"						,     _lowercase="<pad>"						,     _lowercase="<mask>"						,     _lowercase="<eos>"						,     **_lowercase						,     ):





													'''simple docstring'''

													super().__init__(**_lowerCAmelCase							)
													__a		:		Dict									=       load_vocab_file(_lowerCAmelCase							)
													__a		:		List[str]									=       dict(enumerate(self.all_tokens							)							)
													__a		:		List[str]									=       {tok: ind for ind, tok in enumerate(self.all_tokens							)}
													__a		:		List[str]									=       unk_token
													__a		:		Tuple									=       cls_token
													__a		:		Dict									=       pad_token
													__a		:		Union[str, Any]									=       mask_token
													__a		:		Union[str, Any]									=       eos_token
													__a		:		Union[str, Any]									=       self.all_tokens
													self._create_trie(self.unique_no_split_tokens							)



						def     lowerCAmelCase__(self						,     _lowercase							):





													'''simple docstring'''

													return self._id_to_token.get(_lowerCAmelCase						,     self.unk_token							)



						def     lowerCAmelCase__(self						,     _lowercase							):





													'''simple docstring'''

													return self._token_to_id.get(_lowerCAmelCase						,     self._token_to_id.get(self.unk_token							)							)



						def     lowerCAmelCase__(self						,     _lowercase						,     **_lowercase							):





													'''simple docstring'''

													return text.split()



						def     lowerCAmelCase__(self						,     _lowercase=False							):





													'''simple docstring'''

													return len(self._id_to_token							)



						def     lowerCAmelCase__(self							):





													'''simple docstring'''

													return {token: i for i, token in enumerate(self.all_tokens							)}



						def     lowerCAmelCase__(self						,     _lowercase							):





													'''simple docstring'''

													return self._token_to_id.get(_lowerCAmelCase						,     self._token_to_id.get(self.unk_token							)							)



						def     lowerCAmelCase__(self						,     _lowercase							):





													'''simple docstring'''

													return self._id_to_token.get(_lowerCAmelCase						,     self.unk_token							)



						def     lowerCAmelCase__(self						,     _lowercase						,     _lowercase = None							):





													'''simple docstring'''

													__a		:		Tuple									=       [self.cls_token_id]
													__a		:		str									=       [self.eos_token_id]  # No sep token in ESM vocabulary
													if token_ids_a is None:
																				if self.eos_token_id is None:
																											return cls + token_ids_a
																				else:
																											return cls + token_ids_a + sep
													elif self.eos_token_id is None:
																				raise ValueError("""Cannot tokenize multiple sequences when EOS token is not set!"""							)
													return cls + token_ids_a + sep + token_ids_a + sep  # Multiple inputs always have an EOS token



						def     lowerCAmelCase__(self						,     _lowercase						,     _lowercase = None						,     _lowercase = False							):





													'''simple docstring'''

													if already_has_special_tokens:
																				if token_ids_a is not None:
																											raise ValueError(
																											    """You should not supply a second sequence if the provided sequence of """
																											    """ids is already formatted with special tokens for the model."""							)

																				return [1 if token in self.all_special_ids else 0 for token in token_ids_a]
													__a		:		Tuple									=       [1] + ([0] * len(_lowerCAmelCase							)) + [1]
													if token_ids_a is not None:
																				mask += [0] * len(_lowerCAmelCase							) + [1]
													return mask



						def     lowerCAmelCase__(self						,     _lowercase						,     _lowercase							):





													'''simple docstring'''

													__a		:		Optional[Any]									=       os.path.join(_lowerCAmelCase						,     (filename_prefix + """-""" if filename_prefix else """""") + """vocab.txt"""							)
													with open(_lowerCAmelCase						,     """w"""							) as f:
																				f.write("""\n""".join(self.all_tokens							)							)
													return (vocab_file,)



						@property
						def     lowerCAmelCase__(self							):





													'''simple docstring'''

													return self.get_vocab_size(with_added_tokens=_lowerCAmelCase							)





						def     lowerCAmelCase__(self						,     _lowercase						,     _lowercase = False							):





													'''simple docstring'''

													return super()._add_tokens(_lowerCAmelCase						,     special_tokens=_lowerCAmelCase							)






"""simple docstring"""

import functools
import operator

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


lowercase__			   =  logging.get_logger(__name__)

lowercase__			   =  {
    "microsoft/unispeech-large-1500h-cv": (
        "https://huggingface.co/microsoft/unispeech-large-1500h-cv/resolve/main/config.json"
    ),
    # See all UniSpeech models at https://huggingface.co/models?filter=unispeech
}




class SCREAMING_SNAKE_CASE__					(		__snake_case      ):
						_lowerCAmelCase							=					"unispeech"



						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=0.0						,     _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=320						,     _lowercase=2						,     _lowercase=0.1						,     _lowercase=100						,     _lowercase=256						,     _lowercase=256						,     _lowercase=0.1						,     _lowercase="mean"						,     _lowercase=False						,     _lowercase=False						,     _lowercase=256						,     _lowercase=80						,     _lowercase=0						,     _lowercase=1						,     _lowercase=2						,     _lowercase=0.5						,     **_lowercase						,     ):





													'''simple docstring'''

													super().__init__(**_lowercase						,     pad_token_id=_lowercase						,     bos_token_id=_lowercase						,     eos_token_id=_lowercase							)
													__a		:		Union[str, Any]									=       hidden_size
													__a		:		Any									=       feat_extract_norm
													__a		:		Union[str, Any]									=       feat_extract_activation
													__a		:		Tuple									=       list(_lowercase							)
													__a		:		Dict									=       list(_lowercase							)
													__a		:		List[Any]									=       list(_lowercase							)
													__a		:		List[Any]									=       conv_bias
													__a		:		Optional[Any]									=       num_conv_pos_embeddings
													__a		:		Union[str, Any]									=       num_conv_pos_embedding_groups
													__a		:		Dict									=       len(self.conv_dim							)
													__a		:		Dict									=       num_hidden_layers
													__a		:		Union[str, Any]									=       intermediate_size
													__a		:		List[str]									=       hidden_act
													__a		:		int									=       num_attention_heads
													__a		:		int									=       hidden_dropout
													__a		:		Any									=       attention_dropout
													__a		:		List[Any]									=       activation_dropout
													__a		:		List[Any]									=       feat_proj_dropout
													__a		:		Union[str, Any]									=       final_dropout
													__a		:		str									=       layerdrop
													__a		:		Dict									=       layer_norm_eps
													__a		:		Dict									=       initializer_range
													__a		:		Union[str, Any]									=       num_ctc_classes
													__a		:		List[Any]									=       vocab_size
													__a		:		Any									=       do_stable_layer_norm
													__a		:		List[str]									=       use_weighted_layer_sum
													__a		:		List[str]									=       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
													__a		:		Dict									=       apply_spec_augment
													__a		:		Union[str, Any]									=       mask_time_prob
													__a		:		List[str]									=       mask_time_length
													__a		:		Dict									=       mask_time_min_masks
													__a		:		List[Any]									=       mask_feature_prob
													__a		:		Tuple									=       mask_feature_length
													__a		:		int									=       mask_feature_min_masks

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

													# ctc loss
													__a		:		Any									=       ctc_loss_reduction
													__a		:		List[str]									=       ctc_zero_infinity

													# pretraining loss
													__a		:		Tuple									=       replace_prob





						@property
						def     lowerCAmelCase__(self							):





													'''simple docstring'''

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

