



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


__A   			=logging.get_logger(__name__)

__A   			={
    "facebook/s2t-small-librispeech-asr": (
        "https://huggingface.co/facebook/s2t-small-librispeech-asr/resolve/main/config.json"
    ),
    # See all Speech2Text models at https://huggingface.co/models?filter=speech_to_text
}

class 		UpperCAmelCase__			(			__UpperCamelCase   ):




			'''simple docstring'''






			UpperCamelCase									=       """speech_to_text"""
			UpperCamelCase									=       ["""past_key_values"""]
			UpperCamelCase									=       {"""num_attention_heads""": """encoder_attention_heads""", """hidden_size""": """d_model"""}




			def __init__(   self							: Any       ,       a_							: List[str]=1_00_00       ,       a_							: Optional[int]=12       ,       a_							: Any=20_48       ,       a_							: List[str]=4       ,       a_							: List[str]=6       ,       a_							: int=20_48       ,       a_							: List[Any]=4       ,       a_							: Dict=0.0       ,       a_							: int=0.0       ,       a_							: Optional[int]=True       ,       a_							: Tuple=True       ,       a_							: Tuple="relu"       ,       a_							: int=2_56       ,       a_							: Optional[int]=0.1       ,       a_							: int=0.0       ,       a_							: Optional[Any]=0.0       ,       a_							: Optional[Any]=0.0_2       ,       a_							: Tuple=2       ,       a_							: Tuple=True       ,       a_							: int=1       ,       a_							: Union[str, Any]=0       ,       a_							: List[str]=2       ,       a_							: Optional[int]=60_00       ,       a_							: Optional[Any]=10_24       ,       a_							: Optional[Any]=2       ,       a_							: Any=(5, 5)       ,       a_							: Dict=10_24       ,       a_							: Dict=80       ,       a_							: List[Any]=1       ,       **a_							: int       ,       ):
					'''simple docstring'''





					__UpperCAmelCase    :     int													=	vocab_size
					__UpperCAmelCase    :     List[str]													=	d_model
					__UpperCAmelCase    :     int													=	encoder_ffn_dim
					__UpperCAmelCase    :     List[str]													=	encoder_layers
					__UpperCAmelCase    :     Dict													=	encoder_attention_heads
					__UpperCAmelCase    :     Any													=	decoder_ffn_dim
					__UpperCAmelCase    :     Any													=	decoder_layers
					__UpperCAmelCase    :     Optional[Any]													=	decoder_attention_heads
					__UpperCAmelCase    :     Any													=	dropout
					__UpperCAmelCase    :     str													=	attention_dropout
					__UpperCAmelCase    :     Any													=	activation_dropout
					__UpperCAmelCase    :     Optional[int]													=	activation_function
					__UpperCAmelCase    :     List[str]													=	init_std
					__UpperCAmelCase    :     str													=	encoder_layerdrop
					__UpperCAmelCase    :     List[str]													=	decoder_layerdrop
					__UpperCAmelCase    :     List[Any]													=	use_cache
					__UpperCAmelCase    :     Any													=	encoder_layers
					__UpperCAmelCase    :     Optional[int]													=	scale_embedding  # scale factor will be sqrt(d_model) if True
					__UpperCAmelCase    :     Optional[Any]													=	max_source_positions
					__UpperCAmelCase    :     Tuple													=	max_target_positions
					__UpperCAmelCase    :     Union[str, Any]													=	num_conv_layers
					__UpperCAmelCase    :     Any													=	list(a_ )
					__UpperCAmelCase    :     Tuple													=	conv_channels
					__UpperCAmelCase    :     str													=	input_feat_per_channel
					__UpperCAmelCase    :     Optional[Any]													=	input_channels

					if len(self.conv_kernel_sizes ) != self.num_conv_layers:
							raise ValueError(
							    '''Configuration for convolutional module is incorrect. '''
							    '''It is required that `len(config.conv_kernel_sizes)` == `config.num_conv_layers` '''
							    F'but is `len(config.conv_kernel_sizes) = {len(self.conv_kernel_sizes )}`, '
							    F'`config.num_conv_layers = {self.num_conv_layers}`.' )

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










import warnings
from typing import Dict, List, Optional, Tuple

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


__A   			=logging.get_logger(__name__)

class 		UpperCAmelCase__			(			__UpperCamelCase   ):




			'''simple docstring'''






			UpperCamelCase									=       ["""input_ids""", """attention_mask"""]




			def __init__(   self							: List[str]       ,       a_							: List[Any]="</s>"       ,       a_							: str="<unk>"       ,       a_							: Tuple="<pad>"       ,       a_							: List[Any]=1_25       ,       a_							: Any=None       ,       **a_							: Tuple       ,       ):
					'''simple docstring'''





					if extra_ids > 0 and additional_special_tokens is None:
							__UpperCAmelCase    :     Optional[Any]													=	[F'<extra_id_{i}>' for i in range(a_ )]
					elif extra_ids > 0 and additional_special_tokens is not None:
							# Check that we have the right number of extra_id special tokens
							__UpperCAmelCase    :     Optional[Any]													=	len(set(filter(lambda a_ : bool('''extra_id''' in str(a_ ) )       ,       a_ ) ) )
							if extra_tokens != extra_ids:
									raise ValueError(
									    F'Both extra_ids ({extra_ids}) and additional_special_tokens ({additional_special_tokens}) are'
									    ''' provided to ByT5Tokenizer. In this case the additional_special_tokens must include the'''
									    ''' extra_ids tokens''' )

					__UpperCAmelCase    :     str													=	AddedToken(a_       ,       lstrip=a_       ,       rstrip=a_ ) if isinstance(a_       ,       a_ ) else pad_token
					__UpperCAmelCase    :     str													=	AddedToken(a_       ,       lstrip=a_       ,       rstrip=a_ ) if isinstance(a_       ,       a_ ) else eos_token
					__UpperCAmelCase    :     int													=	AddedToken(a_       ,       lstrip=a_       ,       rstrip=a_ ) if isinstance(a_       ,       a_ ) else unk_token

					super().__init__(
					    eos_token=a_       ,       unk_token=a_       ,       pad_token=a_       ,       extra_ids=a_       ,       additional_special_tokens=a_       ,       **a_       ,       )

					__UpperCAmelCase    :     Dict													=	extra_ids

					__UpperCAmelCase    :     Any													=	2**8  # utf is 8 bits

					# define special tokens dict
					__UpperCAmelCase    :     Dict[int, str]													=	{
					    self.pad_token: 0,
					    self.eos_token: 1,
					    self.unk_token: 2,
					}
					__UpperCAmelCase    :     Optional[int]													=	len(self.special_tokens_encoder )
					__UpperCAmelCase    :     Union[str, Any]													=	len(a_ )
					for i, token in enumerate(a_ ):
							__UpperCAmelCase    :     Union[str, Any]													=	self.vocab_size + i - n
					__UpperCAmelCase    :     Dict[str, int]													=	{v: k for k, v in self.special_tokens_encoder.items()}




			@property
			def  snake_case__     (   self							: Tuple ):
					'''simple docstring'''





					return self._utf_vocab_size + self._num_special_tokens + self._extra_ids




			def  snake_case__     (   self							: Any       ,       a_							: List[int]       ,       a_							: Optional[List[int]] = None       ,       a_							: bool = False ):
					'''simple docstring'''





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

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




			def  snake_case__     (   self							: Any       ,       a_							: List[int] ):
					'''simple docstring'''





					if len(a_ ) > 0 and token_ids[-1] == self.eos_token_id:
							warnings.warn(
							    F'This sequence already has {self.eos_token}. In future versions this behavior may lead to duplicated'
							    ''' eos tokens being added.''' )
							return token_ids
					else:
							return token_ids + [self.eos_token_id]




			def  snake_case__     (   self							: Union[str, Any]       ,       a_							: List[int]       ,       a_							: Optional[List[int]] = None ):
					'''simple docstring'''





					__UpperCAmelCase    :     str													=	[self.eos_token_id]

					if token_ids_a is None:
							return len(token_ids_a + eos ) * [0]
					return len(token_ids_a + eos + token_ids_a + eos ) * [0]




			def  snake_case__     (   self							: Optional[Any]       ,       a_							: List[int]       ,       a_							: Optional[List[int]] = None ):
					'''simple docstring'''





					__UpperCAmelCase    :     Union[str, Any]													=	self._add_eos_if_not_present(a_ )
					if token_ids_a is None:
							return token_ids_a
					else:
							__UpperCAmelCase    :     List[str]													=	self._add_eos_if_not_present(a_ )
							return token_ids_a + token_ids_a




			def  snake_case__     (   self							: List[Any]       ,       a_							: str ):
					'''simple docstring'''





					__UpperCAmelCase    :     str													=	[chr(a_ ) for i in text.encode('''utf-8''' )]
					return tokens




			def  snake_case__     (   self							: Optional[Any]       ,       a_							: int ):
					'''simple docstring'''





					if token in self.special_tokens_encoder:
							__UpperCAmelCase    :     Union[str, Any]													=	self.special_tokens_encoder[token]
					elif token in self.added_tokens_encoder:
							__UpperCAmelCase    :     Optional[Any]													=	self.added_tokens_encoder[token]
					elif len(a_ ) != 1:
							__UpperCAmelCase    :     int													=	self.unk_token_id
					else:
							__UpperCAmelCase    :     List[str]													=	ord(a_ ) + self._num_special_tokens
					return token_id




			def  snake_case__     (   self							: Union[str, Any]       ,       a_							: Optional[int] ):
					'''simple docstring'''





					if index in self.special_tokens_decoder:
							__UpperCAmelCase    :     Dict													=	self.special_tokens_decoder[index]
					else:
							__UpperCAmelCase    :     List[Any]													=	chr(index - self._num_special_tokens )
					return token




			def  snake_case__     (   self							: int       ,       a_							: Dict ):
					'''simple docstring'''





					__UpperCAmelCase    :     List[Any]													=	b''''''
					for token in tokens:
							if token in self.special_tokens_decoder:
									__UpperCAmelCase    :     Optional[int]													=	self.special_tokens_decoder[token].encode('''utf-8''' )
							elif token in self.added_tokens_decoder:
									__UpperCAmelCase    :     List[str]													=	self.special_tokens_decoder[token].encode('''utf-8''' )
							elif token in self.special_tokens_encoder:
									__UpperCAmelCase    :     Tuple													=	token.encode('''utf-8''' )
							elif token in self.added_tokens_encoder:
									__UpperCAmelCase    :     int													=	token.encode('''utf-8''' )
							else:
									__UpperCAmelCase    :     Any													=	bytes([ord(a_ )] )
							bstring += tok_string
					__UpperCAmelCase    :     Dict													=	bstring.decode('''utf-8'''       ,       errors='''ignore''' )
					return string




			def  snake_case__     (   self							: Tuple       ,       a_							: str       ,       a_							: Optional[str] = None ):
					'''simple docstring'''





					return ()





