






"""simple docstring"""







import functools
import operator

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


__a       :	Tuple             = logging.get_logger(__name__)

__a       :	List[str]             = {
    'asapp/sew-d-tiny-100k': 'https://huggingface.co/asapp/sew-d-tiny-100k/resolve/main/config.json',
    # See all SEW-D models at https://huggingface.co/models?filter=sew-d
}







class        _SCREAMING_SNAKE_CASE						(  __snake_case							):





							"""simple docstring"""





							_SCREAMING_SNAKE_CASE    ='sew-d'




							def __init__(   self:     Optional[Any]				,		__A:     List[Any]=32				,		__A:     Dict=768				,		__A:     Any=12				,		__A:     int=12				,		__A:     Union[str, Any]=3072				,		__A:     List[Any]=2				,		__A:     Any=512				,		__A:     Optional[Any]=256				,		__A:     Optional[int]=True				,		__A:     str=True				,		__A:     List[Any]=("p2c", "c2p")				,		__A:     Union[str, Any]="layer_norm"				,		__A:     Optional[int]="gelu_python"				,		__A:     Dict=0.1				,		__A:     str=0.1				,		__A:     Optional[Any]=0.1				,		__A:     Dict=0.0				,		__A:     Tuple=0.1				,		__A:     Dict=0.0_2				,		__A:     Dict=1e-7				,		__A:     str=1e-5				,		__A:     Dict="group"				,		__A:     int="gelu"				,		__A:     int=(64, 128, 128, 128, 128, 256, 256, 256, 256, 512, 512, 512, 512)				,		__A:     Any=(5, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1)				,		__A:     List[Any]=(10, 3, 1, 3, 1, 3, 1, 3, 1, 2, 1, 2, 1)				,		__A:     Tuple=False				,		__A:     Optional[Any]=128				,		__A:     str=16				,		__A:     Tuple=True				,		__A:     Tuple=0.0_5				,		__A:     Optional[int]=10				,		__A:     Union[str, Any]=2				,		__A:     str=0.0				,		__A:     Union[str, Any]=10				,		__A:     Optional[Any]=0				,		__A:     List[Any]="mean"				,		__A:     Any=False				,		__A:     List[str]=False				,		__A:     Dict=256				,		__A:     Optional[Any]=0				,		__A:     int=1				,		__A:     Any=2				,		**__A:     int				,		):

												'''simple docstring'''

												super().__init__(**__A				,		pad_token_id=__A				,		bos_token_id=__A				,		eos_token_id=__A    )
												a__          =  hidden_size
												a__          =  feat_extract_norm
												a__          =  feat_extract_activation
												a__          =  list(__A    )
												a__          =  list(__A    )
												a__          =  list(__A    )
												a__          =  conv_bias
												a__          =  num_conv_pos_embeddings
												a__          =  num_conv_pos_embedding_groups
												a__          =  len(self.conv_dim    )
												a__          =  num_hidden_layers
												a__          =  intermediate_size
												a__          =  squeeze_factor
												a__          =  max_position_embeddings
												a__          =  position_buckets
												a__          =  share_att_key
												a__          =  relative_attention
												a__          =  norm_rel_ebd
												a__          =  list(__A    )
												a__          =  hidden_act
												a__          =  num_attention_heads
												a__          =  hidden_dropout
												a__          =  attention_dropout
												a__          =  activation_dropout
												a__          =  feat_proj_dropout
												a__          =  final_dropout
												a__          =  layer_norm_eps
												a__          =  feature_layer_norm_eps
												a__          =  initializer_range
												a__          =  vocab_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)`,'''
																	    F'but is `len(config.conv_dim) = {len(self.conv_dim    )}`, `len(config.conv_stride)'
																	    F'= {len(self.conv_stride    )}`, `len(config.conv_kernel) = {len(self.conv_kernel    )}`.'    )

												# fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
												a__          =  apply_spec_augment
												a__          =  mask_time_prob
												a__          =  mask_time_length
												a__          =  mask_time_min_masks
												a__          =  mask_feature_prob
												a__          =  mask_feature_length
												a__          =  mask_feature_min_masks

												# ctc loss
												a__          =  ctc_loss_reduction
												a__          =  ctc_zero_infinity

												# sequence classification
												a__          =  use_weighted_layer_sum
												a__          =  classifier_proj_size





							@property
							def  lowercase		(   self:     Optional[Any]    ):

												'''simple docstring'''

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










"""simple docstring"""







from typing import List, Optional

import numpy as np

from ...processing_utils import ProcessorMixin
from ...utils import to_numpy







class        _SCREAMING_SNAKE_CASE						(  __snake_case							):





							"""simple docstring"""





							_SCREAMING_SNAKE_CASE    ='EncodecFeatureExtractor'
							_SCREAMING_SNAKE_CASE    =('T5Tokenizer', 'T5TokenizerFast')




							def __init__(   self:     List[Any]				,		__A:     Any				,		__A:     Dict    ):

												'''simple docstring'''

												super().__init__(__A				,		__A    )
												a__          =  self.feature_extractor
												a__          =  False




							def  lowercase		(   self:     Union[str, Any]				,		__A:     List[Any]=None				,		__A:     Optional[Any]=None				,		__A:     List[Any]=True    ):

												'''simple docstring'''

												return self.tokenizer.get_decoder_prompt_ids(task=__A				,		language=__A				,		no_timestamps=__A    )




							def __call__(   self:     Union[str, Any]				,		*__A:     int				,		**__A:     Dict    ):

												'''simple docstring'''

												if self._in_target_context_manager:
																	return self.current_processor(*__A				,		**__A    )

												a__          =  kwargs.pop('''audio'''				,		__A    )
												a__          =  kwargs.pop('''sampling_rate'''				,		__A    )
												a__          =  kwargs.pop('''text'''				,		__A    )
												if len(__A    ) > 0:
																	a__          =  args[0]
																	a__          =  args[1:]

												if audio is None and text is None:
																	raise ValueError('''You need to specify either an `audio` or `text` input to process.'''    )

												if text is not None:
																	a__          =  self.tokenizer(__A				,		**__A    )

												if audio is not None:
																	a__          =  self.feature_extractor(__A				,		*__A				,		sampling_rate=__A				,		**__A    )

												if audio is None:
																	return inputs

												elif text is None:
																	return audio_inputs

												else:
																	a__          =  audio_inputs['''input_values''']
																	if "padding_mask" in audio_inputs:
																						a__          =  audio_inputs['''padding_mask''']
																	return inputs




							def  lowercase		(   self:     Union[str, Any]				,		*__A:     List[str]				,		**__A:     Tuple    ):

												'''simple docstring'''

												a__          =  kwargs.pop('''audio'''				,		__A    )
												a__          =  kwargs.pop('''padding_mask'''				,		__A    )

												if len(__A    ) > 0:
																	a__          =  args[0]
																	a__          =  args[1:]

												if audio_values is not None:
																	return self._decode_audio(__A				,		padding_mask=__A    )
												else:
																	return self.tokenizer.batch_decode(*__A				,		**__A    )




							def  lowercase		(   self:     Union[str, Any]				,		*__A:     Optional[int]				,		**__A:     Optional[Any]    ):

												'''simple docstring'''

												return self.tokenizer.decode(*__A				,		**__A    )





							def  lowercase		(   self:     Union[str, Any]				,		__A:     Dict				,		__A:     Optional = None    ):

												'''simple docstring'''

												a__          =  to_numpy(__A    )
												a__       ,a__       ,a__          =  audio_values.shape

												if padding_mask is None:
																	return list(__A    )

												a__          =  to_numpy(__A    )

												# match the sequence length of the padding mask to the generated audio arrays by padding with the **non-padding**
												# token (so that the generated audio values are **not** treated as padded tokens)
												a__          =  seq_len - padding_mask.shape[-1]
												a__          =  1 - self.feature_extractor.padding_value
												a__          =  np.pad(__A				,		((0, 0), (0, difference))				,		'''constant'''				,		constant_values=__A    )

												a__          =  audio_values.tolist()
												for i in range(__A    ):
																	a__          =  np.asarray(audio_values[i]    )[
																	    padding_mask[i][None, :] != self.feature_extractor.padding_value
																	]
																	a__          =  sliced_audio.reshape(__A				,		-1    )

												return audio_values


