




import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin
from .feature_extraction_wavaveca import WavaVecaFeatureExtractor
from .tokenization_wavaveca import WavaVecaCTCTokenizer




class       a__	( UpperCamelCase__				):
     a		:      Dict		 =     """Wav2Vec2FeatureExtractor"""
     a		:      Optional[Any]		 =     """AutoTokenizer"""







     def __init__(     self  ,		A  ,		A			)  ->   Union[str, Any]:



          '''simple docstring'''



          super().__init__(A  ,		A			)
          a     =				self.feature_extractor
          a     =				False







     @classmethod
     def       lowerCAmelCase_    (     cls  ,		A  ,		**A			)  ->   Tuple:



          '''simple docstring'''



          try:
               return super().from_pretrained(A  ,		**A			)
          except OSError:
               warnings.warn(
                   F'''Loading a tokenizer inside {cls.__name__} from a config that does not'''
                   " include a `tokenizer_class` attribute is deprecated and will be "
                   "removed in v5. Please add `'tokenizer_class': 'Wav2Vec2CTCTokenizer'`"
                   " attribute to either your `config.json` or `tokenizer_config.json` "
                   "file to suppress this warning: "  ,		A  ,		)

               a     =				WavaVecaFeatureExtractor.from_pretrained(A  ,		**A			)
               a     =				WavaVecaCTCTokenizer.from_pretrained(A  ,		**A			)

               return cls(feature_extractor=A  ,		tokenizer=A			)







     def __call__(     self  ,		*A  ,		**A			)  ->   Optional[int]:



          '''simple docstring'''



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

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

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







     def       lowerCAmelCase_    (     self  ,		*A  ,		**A			)  ->   Union[str, Any]:



          '''simple docstring'''



          if self._in_target_context_manager:
               return self.current_processor.pad(*A  ,		**A			)

          a     =				kwargs.pop("input_features"  ,		A			)
          a     =				kwargs.pop("labels"  ,		A			)
          if len(A			) > 0:
               a     =				args[0]
               a     =				args[1:]

          if input_features is not None:
               a     =				self.feature_extractor.pad(A  ,		*A  ,		**A			)
          if labels is not None:
               a     =				self.tokenizer.pad(A  ,		**A			)

          if labels is None:
               return input_features
          elif input_features is None:
               return labels
          else:
               a     =				labels["input_ids"]
               return input_features







     def       lowerCAmelCase_    (     self  ,		*A  ,		**A			)  ->   str:



          '''simple docstring'''



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







     def       lowerCAmelCase_    (     self  ,		*A  ,		**A			)  ->   int:



          '''simple docstring'''



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







     @contextmanager
     def       lowerCAmelCase_    (     self			)  ->   Dict:



          '''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."			)
          a     =				True
          a     =				self.tokenizer
          yield
          a     =				self.feature_extractor
          a     =				False







import functools
import operator

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


lowercase__				:      Any	   = logging.get_logger(__name__)

lowercase__				:      int	   = {
    "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       a__	( UpperCamelCase__				):
     a		:      Optional[Any]		 =     """sew-d"""







     def __init__(     self  ,		A=32  ,		A=768  ,		A=12  ,		A=12  ,		A=3072  ,		A=2  ,		A=512  ,		A=256  ,		A=True  ,		A=True  ,		A=("p2c", "c2p")  ,		A="layer_norm"  ,		A="gelu_python"  ,		A=0.1  ,		A=0.1  ,		A=0.1  ,		A=0.0  ,		A=0.1  ,		A=0.0_2  ,		A=1e-7  ,		A=1e-5  ,		A="group"  ,		A="gelu"  ,		A=(64, 128, 128, 128, 128, 256, 256, 256, 256, 512, 512, 512, 512)  ,		A=(5, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1)  ,		A=(10, 3, 1, 3, 1, 3, 1, 3, 1, 2, 1, 2, 1)  ,		A=False  ,		A=128  ,		A=16  ,		A=True  ,		A=0.0_5  ,		A=10  ,		A=2  ,		A=0.0  ,		A=10  ,		A=0  ,		A="mean"  ,		A=False  ,		A=False  ,		A=256  ,		A=0  ,		A=1  ,		A=2  ,		**A  ,		)  ->   Dict:



          '''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       lowerCAmelCase_    (     self			)  ->   List[str]:



          '''simple docstring'''



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

