

import functools
import operator

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


lowerCamelCase		      = logging.get_logger(__name__)

lowerCamelCase		      = {
    'facebook/hubert-base-ls960': 'https://huggingface.co/facebook/hubert-base-ls960/resolve/main/config.json',
    # See all Hubert models at https://huggingface.co/models?filter=hubert
}




class A						(     UpperCamelCase_  ):
      UpperCamelCase__							:						List[str]   ='hubert'






      def __init__(      self		:  List[Any]    ,     lowercase_		:  Dict=32    ,     lowercase_		:  Optional[Any]=768    ,     lowercase_		:  Union[str, Any]=12    ,     lowercase_		:  List[str]=12    ,     lowercase_		:  int=3072    ,     lowercase_		:  Any="gelu"    ,     lowercase_		:  Optional[Any]=0.1    ,     lowercase_		:  Dict=0.1    ,     lowercase_		:  List[str]=0.1    ,     lowercase_		:  Union[str, Any]=True    ,     lowercase_		:  int=0.0    ,     lowercase_		:  Dict=0.1    ,     lowercase_		:  Optional[int]=0.1    ,     lowercase_		:  int=0.02    ,     lowercase_		:  int=1E-5    ,     lowercase_		:  Any="group"    ,     lowercase_		:  int="gelu"    ,     lowercase_		:  Any=(512, 512, 512, 512, 512, 512, 512)    ,     lowercase_		:  Optional[Any]=(5, 2, 2, 2, 2, 2, 2)    ,     lowercase_		:  str=(10, 3, 3, 3, 3, 2, 2)    ,     lowercase_		:  Optional[int]=False    ,     lowercase_		:  List[Any]=128    ,     lowercase_		:  List[str]=16    ,     lowercase_		:  Dict=False    ,     lowercase_		:  List[str]=True    ,     lowercase_		:  int=0.05    ,     lowercase_		:  Tuple=10    ,     lowercase_		:  str=2    ,     lowercase_		:  Union[str, Any]=0.0    ,     lowercase_		:  List[str]=10    ,     lowercase_		:  Optional[Any]=0    ,     lowercase_		:  Optional[int]="sum"    ,     lowercase_		:  Union[str, Any]=False    ,     lowercase_		:  Dict=False    ,     lowercase_		:  Tuple=256    ,     lowercase_		:  Tuple=0    ,     lowercase_		:  Optional[Any]=1    ,     lowercase_		:  Any=2    ,     **lowercase_		:  str    ,     )      ->		List[Any]:
             """simple docstring"""




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

             # ctc loss
             _lowerCamelCase :	Optional[Any]						=ctc_loss_reduction
             _lowerCamelCase :	Any						=ctc_zero_infinity






      @property
      def  lowerCamelCase (      self		:  Dict				)      ->		int:
             """simple docstring"""




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






import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin




class A						(     UpperCamelCase_  ):
      UpperCamelCase__							:						Optional[Any]   ='AutoFeatureExtractor'
      UpperCamelCase__							:						List[str]   ='Speech2Text2Tokenizer'






      def __init__(      self		:  str    ,     lowercase_		:  Dict    ,     lowercase_		:  Optional[int]				)      ->		str:
             """simple docstring"""




             super().__init__(lowercase_    ,     lowercase_				)
             _lowerCamelCase :	Optional[Any]						=self.feature_extractor
             _lowerCamelCase :	Tuple						=False






      def __call__(      self		:  Tuple    ,     *lowercase_		:  str    ,     **lowercase_		:  List[Any]				)      ->		List[str]:
             """simple docstring"""




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

             if "raw_speech" in kwargs:
                    warnings.warn('Using `raw_speech` as a keyword argument is deprecated. Use `audio` instead.'				)
                    _lowerCamelCase :	List[str]						=kwargs.pop('raw_speech'				)
             else:
                    _lowerCamelCase :	str						=kwargs.pop('audio'    ,     lowercase_				)
             _lowerCamelCase :	Optional[Any]						=kwargs.pop('sampling_rate'    ,     lowercase_				)
             _lowerCamelCase :	List[str]						=kwargs.pop('text'    ,     lowercase_				)
             if len(lowercase_				) > 0:
                    _lowerCamelCase :	Dict						=args[0]
                    _lowerCamelCase :	Optional[Any]						=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 audio is not None:
                    _lowerCamelCase :	List[Any]						=self.feature_extractor(lowercase_    ,     *lowercase_    ,     sampling_rate=lowercase_    ,     **lowercase_				)
             if text is not None:
                    _lowerCamelCase :	Tuple						=self.tokenizer(lowercase_    ,     **lowercase_				)

             if text is None:
                    return inputs
             elif audio is None:
                    return encodings
             else:
                    _lowerCamelCase :	Dict						=encodings['input_ids']
                    return inputs






      def  lowerCamelCase (      self		:  str    ,     *lowercase_		:  List[Any]    ,     **lowercase_		:  Any				)      ->		Union[str, Any]:
             """simple docstring"""




             return self.tokenizer.batch_decode(*lowercase_    ,     **lowercase_				)






      def  lowerCamelCase (      self		:  Optional[int]    ,     *lowercase_		:  Dict    ,     **lowercase_		:  Optional[int]				)      ->		str:
             """simple docstring"""




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






      @contextmanager
      def  lowerCamelCase (      self		:  Optional[Any]				)      ->		Tuple:
             """simple docstring"""




             warnings.warn(
                 '`as_target_processor` is deprecated and will be removed in v5 of Transformers. You can process your '
                 'labels by using the argument `text` of the regular `__call__` method (either in the same call as '
                 'your audio inputs, or in a separate call.'				)
             _lowerCamelCase :	Optional[Any]						=True
             _lowerCamelCase :	List[Any]						=self.tokenizer
             yield
             _lowerCamelCase :	Optional[int]						=self.feature_extractor
             _lowerCamelCase :	List[str]						=False


