'''simple docstring'''
import functools
import operator

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


a=  logging.get_logger(__name__)

a=  {
    '''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 			__lowercase		(						__a						):







     """simple docstring"""






     SCREAMING_SNAKE_CASE__		   =						'''unispeech'''







     def __init__(		self     ,			_lowerCamelCase=3_2     ,			_lowerCamelCase=7_6_8     ,			_lowerCamelCase=1_2     ,			_lowerCamelCase=1_2     ,			_lowerCamelCase=3_0_7_2     ,			_lowerCamelCase="gelu"     ,			_lowerCamelCase=0.1     ,			_lowerCamelCase=0.1     ,			_lowerCamelCase=0.1     ,			_lowerCamelCase=0.0     ,			_lowerCamelCase=0.0     ,			_lowerCamelCase=0.1     ,			_lowerCamelCase=0.1     ,			_lowerCamelCase=0.0_2     ,			_lowerCamelCase=1E-5     ,			_lowerCamelCase="group"     ,			_lowerCamelCase="gelu"     ,			_lowerCamelCase=(5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2)     ,			_lowerCamelCase=(5, 2, 2, 2, 2, 2, 2)     ,			_lowerCamelCase=(1_0, 3, 3, 3, 3, 2, 2)     ,			_lowerCamelCase=False     ,			_lowerCamelCase=1_2_8     ,			_lowerCamelCase=1_6     ,			_lowerCamelCase=False     ,			_lowerCamelCase=True     ,			_lowerCamelCase=0.0_5     ,			_lowerCamelCase=1_0     ,			_lowerCamelCase=2     ,			_lowerCamelCase=0.0     ,			_lowerCamelCase=1_0     ,			_lowerCamelCase=0     ,			_lowerCamelCase=3_2_0     ,			_lowerCamelCase=2     ,			_lowerCamelCase=0.1     ,			_lowerCamelCase=1_0_0     ,			_lowerCamelCase=2_5_6     ,			_lowerCamelCase=2_5_6     ,			_lowerCamelCase=0.1     ,			_lowerCamelCase="mean"     ,			_lowerCamelCase=False     ,			_lowerCamelCase=False     ,			_lowerCamelCase=2_5_6     ,			_lowerCamelCase=8_0     ,			_lowerCamelCase=0     ,			_lowerCamelCase=1     ,			_lowerCamelCase=2     ,			_lowerCamelCase=0.5     ,			**_lowerCamelCase     ,			):
         super().__init__(**snake_case__     ,			pad_token_id=snake_case__     ,			bos_token_id=snake_case__     ,			eos_token_id=snake_case__    )
         __UpperCamelCase	:	List[Any]		    =  hidden_size
         __UpperCamelCase	:	Optional[int]		    =  feat_extract_norm
         __UpperCamelCase	:	str		    =  feat_extract_activation
         __UpperCamelCase	:	Union[str, Any]		    =  list(snake_case__    )
         __UpperCamelCase	:	List[Any]		    =  list(snake_case__    )
         __UpperCamelCase	:	Optional[Any]		    =  list(snake_case__    )
         __UpperCamelCase	:	Tuple		    =  conv_bias
         __UpperCamelCase	:	List[Any]		    =  num_conv_pos_embeddings
         __UpperCamelCase	:	Union[str, Any]		    =  num_conv_pos_embedding_groups
         __UpperCamelCase	:	Any		    =  len(self.conv_dim    )
         __UpperCamelCase	:	Optional[int]		    =  num_hidden_layers
         __UpperCamelCase	:	Dict		    =  intermediate_size
         __UpperCamelCase	:	Optional[int]		    =  hidden_act
         __UpperCamelCase	:	List[str]		    =  num_attention_heads
         __UpperCamelCase	:	Dict		    =  hidden_dropout
         __UpperCamelCase	:	Optional[int]		    =  attention_dropout
         __UpperCamelCase	:	Any		    =  activation_dropout
         __UpperCamelCase	:	Dict		    =  feat_proj_dropout
         __UpperCamelCase	:	List[Any]		    =  final_dropout
         __UpperCamelCase	:	Any		    =  layerdrop
         __UpperCamelCase	:	str		    =  layer_norm_eps
         __UpperCamelCase	:	List[str]		    =  initializer_range
         __UpperCamelCase	:	Dict		    =  num_ctc_classes
         __UpperCamelCase	:	int		    =  vocab_size
         __UpperCamelCase	:	Union[str, Any]		    =  do_stable_layer_norm
         __UpperCamelCase	:	Optional[Any]		    =  use_weighted_layer_sum
         __UpperCamelCase	:	Any		    =  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
         __UpperCamelCase	:	List[str]		    =  apply_spec_augment
         __UpperCamelCase	:	str		    =  mask_time_prob
         __UpperCamelCase	:	Union[str, Any]		    =  mask_time_length
         __UpperCamelCase	:	Dict		    =  mask_time_min_masks
         __UpperCamelCase	:	str		    =  mask_feature_prob
         __UpperCamelCase	:	Tuple		    =  mask_feature_length
         __UpperCamelCase	:	int		    =  mask_feature_min_masks

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

         # ctc loss
         __UpperCamelCase	:	List[Any]		    =  ctc_loss_reduction
         __UpperCamelCase	:	Tuple		    =  ctc_zero_infinity

         # pretraining loss
         __UpperCamelCase	:	Tuple		    =  replace_prob







     @property
     def lowerCAmelCase     (		self    ):
         return functools.reduce(operator.mul     ,			self.conv_stride     ,			1    )




'''simple docstring'''
from ...processing_utils import ProcessorMixin






class 			__lowercase		(						_lowerCamelCase						):







     """simple docstring"""






     SCREAMING_SNAKE_CASE__		   =						'''SpeechT5FeatureExtractor'''
     SCREAMING_SNAKE_CASE__		   =						'''SpeechT5Tokenizer'''







     def __init__(		self     ,			_lowerCamelCase     ,			_lowerCamelCase    ):
         super().__init__(_lowerCamelCase     ,			_lowerCamelCase    )







     def __call__(		self     ,			*_lowerCamelCase     ,			**_lowerCamelCase    ):
         __UpperCamelCase	:	Union[str, Any]		    =  kwargs.pop('audio'     ,			_lowerCamelCase    )
         __UpperCamelCase	:	Tuple		    =  kwargs.pop('text'     ,			_lowerCamelCase    )
         __UpperCamelCase	:	Union[str, Any]		    =  kwargs.pop('text_target'     ,			_lowerCamelCase    )
         __UpperCamelCase	:	List[Any]		    =  kwargs.pop('audio_target'     ,			_lowerCamelCase    )
         __UpperCamelCase	:	Any		    =  kwargs.pop('sampling_rate'     ,			_lowerCamelCase    )

         if audio is not None and text is not None:
             raise ValueError(
                 'Cannot process both `audio` and `text` inputs. Did you mean `audio_target` or `text_target`?'    )
         if audio_target is not None and text_target is not None:
             raise ValueError(
                 'Cannot process both `audio_target` and `text_target` inputs. Did you mean `audio` or `text`?'    )
         if audio is None and audio_target is None and text is None and text_target is None:
             raise ValueError(
                 'You need to specify either an `audio`, `audio_target`, `text`, or `text_target` input to process.'    )

         if audio is not None:
             __UpperCamelCase	:	Dict		    =  self.feature_extractor(_lowerCamelCase     ,			*_lowerCamelCase     ,			sampling_rate=_lowerCamelCase     ,			**_lowerCamelCase    )
         elif text is not None:
             __UpperCamelCase	:	int		    =  self.tokenizer(_lowerCamelCase     ,			**_lowerCamelCase    )
         else:
             __UpperCamelCase	:	List[str]		    =  None

         if audio_target is not None:
             __UpperCamelCase	:	Dict		    =  self.feature_extractor(audio_target=_lowerCamelCase     ,			*_lowerCamelCase     ,			sampling_rate=_lowerCamelCase     ,			**_lowerCamelCase    )
             __UpperCamelCase	:	Optional[int]		    =  targets['input_values']
         elif text_target is not None:
             __UpperCamelCase	:	Any		    =  self.tokenizer(_lowerCamelCase     ,			**_lowerCamelCase    )
             __UpperCamelCase	:	Optional[int]		    =  targets['input_ids']
         else:
             __UpperCamelCase	:	List[str]		    =  None

         if inputs is None:
             return targets

         if targets is not None:
             __UpperCamelCase	:	List[Any]		    =  labels

             __UpperCamelCase	:	Any		    =  targets.get('attention_mask'    )
             if decoder_attention_mask is not None:
                 __UpperCamelCase	:	int		    =  decoder_attention_mask

         return inputs







     def lowerCAmelCase     (		self     ,			*_lowerCamelCase     ,			**_lowerCamelCase    ):
         __UpperCamelCase	:	Optional[Any]		    =  kwargs.pop('input_values'     ,			_lowerCamelCase    )
         __UpperCamelCase	:	Union[str, Any]		    =  kwargs.pop('input_ids'     ,			_lowerCamelCase    )
         __UpperCamelCase	:	List[Any]		    =  kwargs.pop('labels'     ,			_lowerCamelCase    )

         if input_values is not None and input_ids is not None:
             raise ValueError('Cannot process both `input_values` and `input_ids` inputs.'    )
         if input_values is None and input_ids is None and labels is None:
             raise ValueError(
                 'You need to specify either an `input_values`, `input_ids`, or `labels` input to be padded.'    )

         if input_values is not None:
             __UpperCamelCase	:	Optional[int]		    =  self.feature_extractor.pad(_lowerCamelCase     ,			*_lowerCamelCase     ,			**_lowerCamelCase    )
         elif input_ids is not None:
             __UpperCamelCase	:	int		    =  self.tokenizer.pad(_lowerCamelCase     ,			**_lowerCamelCase    )
         else:
             __UpperCamelCase	:	str		    =  None

         if labels is not None:
             if "input_ids" in labels or (isinstance(_lowerCamelCase     ,			_lowerCamelCase    ) and "input_ids" in labels[0]):
                 __UpperCamelCase	:	Dict		    =  self.tokenizer.pad(_lowerCamelCase     ,			**_lowerCamelCase    )
                 __UpperCamelCase	:	str		    =  targets['input_ids']
             else:
                 __UpperCamelCase	:	int		    =  self.feature_extractor.feature_size
                 __UpperCamelCase	:	Any		    =  self.feature_extractor.num_mel_bins
                 __UpperCamelCase	:	Dict		    =  self.feature_extractor.pad(_lowerCamelCase     ,			*_lowerCamelCase     ,			**_lowerCamelCase    )
                 __UpperCamelCase	:	List[str]		    =  feature_size_hack
                 __UpperCamelCase	:	Tuple		    =  targets['input_values']
         else:
             __UpperCamelCase	:	List[str]		    =  None

         if inputs is None:
             return targets

         if targets is not None:
             __UpperCamelCase	:	Optional[int]		    =  labels

             __UpperCamelCase	:	Union[str, Any]		    =  targets.get('attention_mask'    )
             if decoder_attention_mask is not None:
                 __UpperCamelCase	:	Optional[Any]		    =  decoder_attention_mask

         return inputs







     def lowerCAmelCase     (		self     ,			*_lowerCamelCase     ,			**_lowerCamelCase    ):
         return self.tokenizer.batch_decode(*_lowerCamelCase     ,			**_lowerCamelCase    )







     def lowerCAmelCase     (		self     ,			*_lowerCamelCase     ,			**_lowerCamelCase    ):
         return self.tokenizer.decode(*_lowerCamelCase     ,			**_lowerCamelCase    )



