





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


UpperCamelCase__           =			logging.get_logger(__name__)

UpperCamelCase__           =			{
    "facebook/s2t-wav2vec2-large-en-de": (
        "https://huggingface.co/facebook/s2t-wav2vec2-large-en-de/resolve/main/config.json"
    ),
    # See all Speech2Text models at https://huggingface.co/models?filter=speech2text2
}

class 							__SCREAMING_SNAKE_CASE       (  _a							):
							snake_case  :   Tuple      =							"""speech_to_text_2"""
							snake_case  :   int      =							["""past_key_values"""]
							snake_case  :   str      =							{"""num_attention_heads""": """decoder_attention_heads""", """hidden_size""": """d_model"""}






							def __init__(    self	,			__lowerCAmelCase=10000	,			__lowerCAmelCase=6	,			__lowerCAmelCase=2048	,			__lowerCAmelCase=4	,			__lowerCAmelCase=0.0	,			__lowerCAmelCase=True	,			__lowerCAmelCase="relu"	,			__lowerCAmelCase=256	,			__lowerCAmelCase=0.1	,			__lowerCAmelCase=0.0	,			__lowerCAmelCase=0.0	,			__lowerCAmelCase=0.02	,			__lowerCAmelCase=2	,			__lowerCAmelCase=True	,			__lowerCAmelCase=1	,			__lowerCAmelCase=0	,			__lowerCAmelCase=2	,			__lowerCAmelCase=1024	,			**__lowerCAmelCase	,			):
														UpperCamelCase__					  =      vocab_size
														UpperCamelCase__					  =      d_model
														UpperCamelCase__					  =      decoder_ffn_dim
														UpperCamelCase__					  =      decoder_layers
														UpperCamelCase__					  =      decoder_attention_heads
														UpperCamelCase__					  =      dropout
														UpperCamelCase__					  =      attention_dropout
														UpperCamelCase__					  =      activation_dropout
														UpperCamelCase__					  =      activation_function
														UpperCamelCase__					  =      init_std
														UpperCamelCase__					  =      decoder_layerdrop
														UpperCamelCase__					  =      use_cache
														UpperCamelCase__					  =      decoder_layers
														UpperCamelCase__					  =      scale_embedding  # scale factor will be sqrt(d_model) if True
														UpperCamelCase__					  =      max_target_positions

														super().__init__(
														    pad_token_id=__lowerCAmelCase	,			bos_token_id=__lowerCAmelCase	,			eos_token_id=__lowerCAmelCase	,			decoder_start_token_id=__lowerCAmelCase	,			**__lowerCAmelCase	,			)











import copy
import random

from transformers import CLIPTokenizer

class 							__SCREAMING_SNAKE_CASE       (  _a							):






							def __init__(    self	,			*__lowerCAmelCase	,			**__lowerCAmelCase	):
														super().__init__(*__lowerCAmelCase	,			**__lowerCAmelCase	)
														UpperCamelCase__					  =      {}






							def 					_lowerCamelCase		(    self	,			__lowerCAmelCase	,			*__lowerCAmelCase	,			**__lowerCAmelCase	):
														UpperCamelCase__					  =      super().add_tokens(__lowerCAmelCase	,			*__lowerCAmelCase	,			**__lowerCAmelCase	)
														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 					_lowerCamelCase		(    self	,			__lowerCAmelCase	,			*__lowerCAmelCase	,			__lowerCAmelCase=1	,			**__lowerCAmelCase	):
														UpperCamelCase__					  =      []
														if num_vec_per_token == 1:
																					self.try_adding_tokens(__lowerCAmelCase	,			*__lowerCAmelCase	,			**__lowerCAmelCase	)
																					output.append(__lowerCAmelCase	)
														else:
																					UpperCamelCase__					  =      []
																					for i in range(__lowerCAmelCase	):
																												UpperCamelCase__					  =      placeholder_token + f"""_{i}"""
																												self.try_adding_tokens(__lowerCAmelCase	,			*__lowerCAmelCase	,			**__lowerCAmelCase	)
																												output.append(__lowerCAmelCase	)
        # 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"""	)
														UpperCamelCase__					  =      output






							def 					_lowerCamelCase		(    self	,			__lowerCAmelCase	,			__lowerCAmelCase=False	,			__lowerCAmelCase=1.0	):
														if isinstance(__lowerCAmelCase	,			__lowerCAmelCase	):
																					UpperCamelCase__					  =      []
																					for i in range(len(__lowerCAmelCase	)	):
																												output.append(self.replace_placeholder_tokens_in_text(text[i]	,			vector_shuffle=__lowerCAmelCase	)	)
																					return output
														for placeholder_token in self.token_map:
																					if placeholder_token in text:
																												UpperCamelCase__					  =      self.token_map[placeholder_token]
																												UpperCamelCase__					  =      tokens[: 1 + int(len(__lowerCAmelCase	) * prop_tokens_to_load	)]
																												if vector_shuffle:
																																			UpperCamelCase__					  =      copy.copy(__lowerCAmelCase	)
																																			random.shuffle(__lowerCAmelCase	)
																												UpperCamelCase__					  =      text.replace(__lowerCAmelCase	,			""" """.join(__lowerCAmelCase	)	)
														return text






							def __call__(    self	,			__lowerCAmelCase	,			*__lowerCAmelCase	,			__lowerCAmelCase=False	,			__lowerCAmelCase=1.0	,			**__lowerCAmelCase	):
														return super().__call__(
														    self.replace_placeholder_tokens_in_text(
														        __lowerCAmelCase	,			vector_shuffle=__lowerCAmelCase	,			prop_tokens_to_load=__lowerCAmelCase	)	,			*__lowerCAmelCase	,			**__lowerCAmelCase	,			)







							def 					_lowerCamelCase		(    self	,			__lowerCAmelCase	,			*__lowerCAmelCase	,			__lowerCAmelCase=False	,			__lowerCAmelCase=1.0	,			**__lowerCAmelCase	):
														return super().encode(
														    self.replace_placeholder_tokens_in_text(
														        __lowerCAmelCase	,			vector_shuffle=__lowerCAmelCase	,			prop_tokens_to_load=__lowerCAmelCase	)	,			*__lowerCAmelCase	,			**__lowerCAmelCase	,			)




