
"""simple docstring"""


import warnings
from contextlib import contextmanager

from ....processing_utils import ProcessorMixin



class 	__a	(   _lowerCAmelCase						):
       UpperCamelCase_		:       Tuple				=      '''MCTCTFeatureExtractor'''
       UpperCamelCase_		:       Dict				=      '''AutoTokenizer'''






       def __init__(	self			:				Any							,   UpperCAmelCase_			:				List[str]							,   UpperCAmelCase_			:				Union[str, Any]      )->	Optional[Any]:







              """simple docstring"""
              super().__init__(UpperCAmelCase_							,   UpperCAmelCase_      )
              UpperCamelCase       			=		self.feature_extractor
              UpperCamelCase       			=		False






       def __call__(	self			:				Any							,   *UpperCAmelCase_			:				List[Any]							,   **UpperCAmelCase_			:				str      )->	Optional[Any]:







              """simple docstring"""
              # For backward compatibility
              if self._in_target_context_manager:
                     return self.current_processor(*UpperCAmelCase_							,   **UpperCAmelCase_      )

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

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






       def 						_SCREAMING_SNAKE_CASE							(	self			:				str							,   *UpperCAmelCase_			:				int							,   **UpperCAmelCase_			:				Dict      )->	Optional[Any]:







              """simple docstring"""
              return self.tokenizer.batch_decode(*UpperCAmelCase_							,   **UpperCAmelCase_      )






       def 						_SCREAMING_SNAKE_CASE							(	self			:				List[Any]							,   *UpperCAmelCase_			:				Any							,   **UpperCAmelCase_			:				Dict      )->	str:







              """simple docstring"""
              # For backward compatibility
              if self._in_target_context_manager:
                     return self.current_processor.pad(*UpperCAmelCase_							,   **UpperCAmelCase_      )

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

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

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






       def 						_SCREAMING_SNAKE_CASE							(	self			:				str							,   *UpperCAmelCase_			:				Dict							,   **UpperCAmelCase_			:				str      )->	Optional[Any]:







              """simple docstring"""
              return self.tokenizer.decode(*UpperCAmelCase_							,   **UpperCAmelCase_      )






       @contextmanager
       def 						_SCREAMING_SNAKE_CASE							(	self			:				Tuple      )->	Optional[Any]:







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







"""simple docstring"""


import torch
import torch.nn as nn
from transformers.modeling_utils import ModuleUtilsMixin
from transformers.models.ta.modeling_ta import TaBlock, TaConfig, TaLayerNorm

from ...configuration_utils import ConfigMixin, register_to_config
from ...models import ModelMixin



class 	__a	(   _lowerCAmelCase     ,  _lowerCAmelCase     ,  _lowerCAmelCase						):






       @register_to_config
       def __init__(	self			:				Union[str, Any]							,   UpperCAmelCase_			:				int							,   UpperCAmelCase_			:				int							,   UpperCAmelCase_			:				int							,   UpperCAmelCase_			:				float							,   UpperCAmelCase_			:				int							,   UpperCAmelCase_			:				int							,   UpperCAmelCase_			:				int							,   UpperCAmelCase_			:				int							,   UpperCAmelCase_			:				str							,   UpperCAmelCase_			:				bool = False							,   )->	str:







              """simple docstring"""
              super().__init__()

              UpperCamelCase       			=		nn.Embedding(UpperCAmelCase_							,   UpperCAmelCase_      )

              UpperCamelCase       			=		nn.Embedding(UpperCAmelCase_							,   UpperCAmelCase_      )
              UpperCamelCase       			=		False

              UpperCamelCase       			=		nn.Dropout(p=UpperCAmelCase_      )

              UpperCamelCase       			=		TaConfig(
                  vocab_size=UpperCAmelCase_							,   d_model=UpperCAmelCase_							,   num_heads=UpperCAmelCase_							,   d_kv=UpperCAmelCase_							,   d_ff=UpperCAmelCase_							,   dropout_rate=UpperCAmelCase_							,   feed_forward_proj=UpperCAmelCase_							,   is_decoder=UpperCAmelCase_							,   is_encoder_decoder=UpperCAmelCase_							,   )

              UpperCamelCase       			=		nn.ModuleList()
              for lyr_num in range(UpperCAmelCase_      ):
                     UpperCamelCase       			=		TaBlock(UpperCAmelCase_      )
                     self.encoders.append(UpperCAmelCase_      )

              UpperCamelCase       			=		TaLayerNorm(UpperCAmelCase_      )
              UpperCamelCase       			=		nn.Dropout(p=UpperCAmelCase_      )






       def 						_SCREAMING_SNAKE_CASE							(	self			:				int							,   UpperCAmelCase_			:				int							,   UpperCAmelCase_			:				str      )->	List[Any]:







              """simple docstring"""
              UpperCamelCase       			=		self.token_embedder(UpperCAmelCase_      )

              UpperCamelCase       			=		encoder_input_tokens.shape[1]
              UpperCamelCase       			=		torch.arange(UpperCAmelCase_							,   device=encoder_input_tokens.device      )
              x += self.position_encoding(UpperCAmelCase_      )

              UpperCamelCase       			=		self.dropout_pre(UpperCAmelCase_      )

              # inverted the attention mask
              UpperCamelCase       			=		encoder_input_tokens.size()
              UpperCamelCase       			=		self.get_extended_attention_mask(UpperCAmelCase_							,   UpperCAmelCase_      )

              for lyr in self.encoders:
                     UpperCamelCase       			=		lyr(UpperCAmelCase_							,   UpperCAmelCase_      )[0]
              UpperCamelCase       			=		self.layer_norm(UpperCAmelCase_      )

              return self.dropout_post(UpperCAmelCase_      ), encoder_inputs_mask





