




import functools
import operator

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


UpperCamelCase								=					logging.get_logger(__name__)

UpperCamelCase								=					{
    '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 			__lowerCamelCase	(   UpperCamelCase__   ):




    """simple docstring"""

    snake_case__ =				"sew-d"


    def __init__(	self					:					Union[str, Any]       ,     SCREAMING_SNAKE_CASE__					:					List[str]=32       ,     SCREAMING_SNAKE_CASE__					:					Union[str, Any]=768       ,     SCREAMING_SNAKE_CASE__					:					Dict=12       ,     SCREAMING_SNAKE_CASE__					:					Any=12       ,     SCREAMING_SNAKE_CASE__					:					List[str]=3_072       ,     SCREAMING_SNAKE_CASE__					:					Tuple=2       ,     SCREAMING_SNAKE_CASE__					:					Dict=512       ,     SCREAMING_SNAKE_CASE__					:					str=256       ,     SCREAMING_SNAKE_CASE__					:					Any=True       ,     SCREAMING_SNAKE_CASE__					:					Optional[int]=True       ,     SCREAMING_SNAKE_CASE__					:					Optional[Any]=("p2c", "c2p")       ,     SCREAMING_SNAKE_CASE__					:					int="layer_norm"       ,     SCREAMING_SNAKE_CASE__					:					Union[str, Any]="gelu_python"       ,     SCREAMING_SNAKE_CASE__					:					List[str]=0.1       ,     SCREAMING_SNAKE_CASE__					:					Any=0.1       ,     SCREAMING_SNAKE_CASE__					:					Optional[Any]=0.1       ,     SCREAMING_SNAKE_CASE__					:					Any=0.0       ,     SCREAMING_SNAKE_CASE__					:					Tuple=0.1       ,     SCREAMING_SNAKE_CASE__					:					str=0.02       ,     SCREAMING_SNAKE_CASE__					:					Optional[Any]=1e-7       ,     SCREAMING_SNAKE_CASE__					:					List[str]=1e-5       ,     SCREAMING_SNAKE_CASE__					:					int="group"       ,     SCREAMING_SNAKE_CASE__					:					int="gelu"       ,     SCREAMING_SNAKE_CASE__					:					int=(64, 128, 128, 128, 128, 256, 256, 256, 256, 512, 512, 512, 512)       ,     SCREAMING_SNAKE_CASE__					:					Tuple=(5, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1)       ,     SCREAMING_SNAKE_CASE__					:					Optional[Any]=(10, 3, 1, 3, 1, 3, 1, 3, 1, 2, 1, 2, 1)       ,     SCREAMING_SNAKE_CASE__					:					Optional[int]=False       ,     SCREAMING_SNAKE_CASE__					:					Tuple=128       ,     SCREAMING_SNAKE_CASE__					:					List[str]=16       ,     SCREAMING_SNAKE_CASE__					:					Tuple=True       ,     SCREAMING_SNAKE_CASE__					:					int=0.05       ,     SCREAMING_SNAKE_CASE__					:					int=10       ,     SCREAMING_SNAKE_CASE__					:					Optional[int]=2       ,     SCREAMING_SNAKE_CASE__					:					Optional[Any]=0.0       ,     SCREAMING_SNAKE_CASE__					:					int=10       ,     SCREAMING_SNAKE_CASE__					:					List[Any]=0       ,     SCREAMING_SNAKE_CASE__					:					Any="mean"       ,     SCREAMING_SNAKE_CASE__					:					Any=False       ,     SCREAMING_SNAKE_CASE__					:					str=False       ,     SCREAMING_SNAKE_CASE__					:					Union[str, Any]=256       ,     SCREAMING_SNAKE_CASE__					:					List[str]=0       ,     SCREAMING_SNAKE_CASE__					:					Tuple=1       ,     SCREAMING_SNAKE_CASE__					:					str=2       ,     **SCREAMING_SNAKE_CASE__					:					int       ,     )				->	str:
         super().__init__(**SCREAMING_SNAKE_CASE__       ,     pad_token_id=SCREAMING_SNAKE_CASE__       ,     bos_token_id=SCREAMING_SNAKE_CASE__       ,     eos_token_id=SCREAMING_SNAKE_CASE__       )
         lowerCAmelCase__          =			hidden_size
         lowerCAmelCase__          =			feat_extract_norm
         lowerCAmelCase__          =			feat_extract_activation
         lowerCAmelCase__          =			list(SCREAMING_SNAKE_CASE__       )
         lowerCAmelCase__          =			list(SCREAMING_SNAKE_CASE__       )
         lowerCAmelCase__          =			list(SCREAMING_SNAKE_CASE__       )
         lowerCAmelCase__          =			conv_bias
         lowerCAmelCase__          =			num_conv_pos_embeddings
         lowerCAmelCase__          =			num_conv_pos_embedding_groups
         lowerCAmelCase__          =			len(self.conv_dim       )
         lowerCAmelCase__          =			num_hidden_layers
         lowerCAmelCase__          =			intermediate_size
         lowerCAmelCase__          =			squeeze_factor
         lowerCAmelCase__          =			max_position_embeddings
         lowerCAmelCase__          =			position_buckets
         lowerCAmelCase__          =			share_att_key
         lowerCAmelCase__          =			relative_attention
         lowerCAmelCase__          =			norm_rel_ebd
         lowerCAmelCase__          =			list(SCREAMING_SNAKE_CASE__       )
         lowerCAmelCase__          =			hidden_act
         lowerCAmelCase__          =			num_attention_heads
         lowerCAmelCase__          =			hidden_dropout
         lowerCAmelCase__          =			attention_dropout
         lowerCAmelCase__          =			activation_dropout
         lowerCAmelCase__          =			feat_proj_dropout
         lowerCAmelCase__          =			final_dropout
         lowerCAmelCase__          =			layer_norm_eps
         lowerCAmelCase__          =			feature_layer_norm_eps
         lowerCAmelCase__          =			initializer_range
         lowerCAmelCase__          =			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
         lowerCAmelCase__          =			apply_spec_augment
         lowerCAmelCase__          =			mask_time_prob
         lowerCAmelCase__          =			mask_time_length
         lowerCAmelCase__          =			mask_time_min_masks
         lowerCAmelCase__          =			mask_feature_prob
         lowerCAmelCase__          =			mask_feature_length
         lowerCAmelCase__          =			mask_feature_min_masks

         # ctc loss
         lowerCAmelCase__          =			ctc_loss_reduction
         lowerCAmelCase__          =			ctc_zero_infinity

         # sequence classification
         lowerCAmelCase__          =			use_weighted_layer_sum
         lowerCAmelCase__          =			classifier_proj_size


    @property
    def        a				(	self					:					List[Any]       )				->	Dict:
         return functools.reduce(operator.mul       ,     self.conv_stride       ,     1       )






import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin





class 			__lowerCamelCase	(   UpperCamelCase__   ):




    """simple docstring"""

    snake_case__ =				"Speech2TextFeatureExtractor"
    snake_case__ =				"Speech2TextTokenizer"


    def __init__(	self					:					int       ,     SCREAMING_SNAKE_CASE__					:					Dict       ,     SCREAMING_SNAKE_CASE__					:					Tuple       )				->	Optional[Any]:
         super().__init__(SCREAMING_SNAKE_CASE__       ,     SCREAMING_SNAKE_CASE__       )
         lowerCAmelCase__          =			self.feature_extractor
         lowerCAmelCase__          =			False


    def __call__(	self					:					str       ,     *SCREAMING_SNAKE_CASE__					:					int       ,     **SCREAMING_SNAKE_CASE__					:					int       )				->	Optional[Any]:
         # For backward compatibility
         if self._in_target_context_manager:
              return self.current_processor(*SCREAMING_SNAKE_CASE__       ,     **SCREAMING_SNAKE_CASE__       )

         if "raw_speech" in kwargs:
              warnings.warn("Using `raw_speech` as a keyword argument is deprecated. Use `audio` instead."       )
              lowerCAmelCase__          =			kwargs.pop("raw_speech"       )
         else:
              lowerCAmelCase__          =			kwargs.pop("audio"       ,     SCREAMING_SNAKE_CASE__       )
         lowerCAmelCase__          =			kwargs.pop("sampling_rate"       ,     SCREAMING_SNAKE_CASE__       )
         lowerCAmelCase__          =			kwargs.pop("text"       ,     SCREAMING_SNAKE_CASE__       )
         if len(SCREAMING_SNAKE_CASE__       ) > 0:
              lowerCAmelCase__          =			args[0]
              lowerCAmelCase__          =			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__          =			self.feature_extractor(SCREAMING_SNAKE_CASE__       ,     *SCREAMING_SNAKE_CASE__       ,     sampling_rate=SCREAMING_SNAKE_CASE__       ,     **SCREAMING_SNAKE_CASE__       )
         if text is not None:
              lowerCAmelCase__          =			self.tokenizer(SCREAMING_SNAKE_CASE__       ,     **SCREAMING_SNAKE_CASE__       )

         if text is None:
              return inputs
         elif audio is None:
              return encodings
         else:
              lowerCAmelCase__          =			encodings["input_ids"]
              return inputs


    def        a				(	self					:					str       ,     *SCREAMING_SNAKE_CASE__					:					Dict       ,     **SCREAMING_SNAKE_CASE__					:					int       )				->	Union[str, Any]:
         return self.tokenizer.batch_decode(*SCREAMING_SNAKE_CASE__       ,     **SCREAMING_SNAKE_CASE__       )


    def        a				(	self					:					Dict       ,     *SCREAMING_SNAKE_CASE__					:					Optional[int]       ,     **SCREAMING_SNAKE_CASE__					:					Optional[int]       )				->	Optional[Any]:
         return self.tokenizer.decode(*SCREAMING_SNAKE_CASE__       ,     **SCREAMING_SNAKE_CASE__       )


    @contextmanager
    def        a				(	self					:					Union[str, Any]       )				->	Any:
         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__          =			True
         lowerCAmelCase__          =			self.tokenizer
         yield
         lowerCAmelCase__          =			self.feature_extractor
         lowerCAmelCase__          =			False
