





from __future__ import annotations

import unittest

from transformers import DebertaVaConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
					import tensorflow as tf

					from transformers import (
					    TFDebertaVaForMaskedLM,
					    TFDebertaVaForQuestionAnswering,
					    TFDebertaVaForSequenceClassification,
					    TFDebertaVaForTokenClassification,
					    TFDebertaVaModel,
					)


class     A     :
			'''simple docstring'''




			def __init__(     self  :       List[Any]				,      __lowerCAmelCase  :       Optional[Any]				,      __lowerCAmelCase  :       Optional[int]=13				,      __lowerCAmelCase  :       List[str]=7				,      __lowerCAmelCase  :       Dict=True				,      __lowerCAmelCase  :       List[str]=True				,      __lowerCAmelCase  :       Any=True				,      __lowerCAmelCase  :       Union[str, Any]=True				,      __lowerCAmelCase  :       Optional[int]=99				,      __lowerCAmelCase  :       Optional[int]=32				,      __lowerCAmelCase  :       Any=2				,      __lowerCAmelCase  :       List[str]=4				,      __lowerCAmelCase  :       Optional[Any]=37				,      __lowerCAmelCase  :       Union[str, Any]="gelu"				,      __lowerCAmelCase  :       Dict=0.1				,      __lowerCAmelCase  :       List[Any]=0.1				,      __lowerCAmelCase  :       Dict=5_12				,      __lowerCAmelCase  :       Any=16				,      __lowerCAmelCase  :       List[str]=2				,      __lowerCAmelCase  :       Tuple=0.0_2				,      __lowerCAmelCase  :       Dict=False				,      __lowerCAmelCase  :       List[str]=True				,      __lowerCAmelCase  :       Tuple="None"				,      __lowerCAmelCase  :       List[Any]=3				,      __lowerCAmelCase  :       str=4				,      __lowerCAmelCase  :       Optional[Any]=None				,      )      ->      List[str]:







					"""simple docstring"""






					A__     =  parent
					A__     =  batch_size
					A__     =  seq_length
					A__     =  is_training
					A__     =  use_input_mask
					A__     =  use_token_type_ids
					A__     =  use_labels
					A__     =  vocab_size
					A__     =  hidden_size
					A__     =  num_hidden_layers
					A__     =  num_attention_heads
					A__     =  intermediate_size
					A__     =  hidden_act
					A__     =  hidden_dropout_prob
					A__     =  attention_probs_dropout_prob
					A__     =  max_position_embeddings
					A__     =  type_vocab_size
					A__     =  type_sequence_label_size
					A__     =  initializer_range
					A__     =  num_labels
					A__     =  num_choices
					A__     =  relative_attention
					A__     =  position_biased_input
					A__     =  pos_att_type
					A__     =  scope






			def   a_			(     self  :       Dict  )      ->      Tuple:







					"""simple docstring"""






					A__     =  ids_tensor([self.batch_size, self.seq_length]				,      self.vocab_size  )

					A__     =  None
					if self.use_input_mask:
							A__     =  random_attention_mask([self.batch_size, self.seq_length]  )

					A__     =  None
					if self.use_token_type_ids:
							A__     =  ids_tensor([self.batch_size, self.seq_length]				,      self.type_vocab_size  )

					A__     =  None
					A__     =  None
					A__     =  None
					if self.use_labels:
							A__     =  ids_tensor([self.batch_size]				,      self.type_sequence_label_size  )
							A__     =  ids_tensor([self.batch_size, self.seq_length]				,      self.num_labels  )

					A__     =  DebertaVaConfig(
					    vocab_size=self.vocab_size				,      hidden_size=self.hidden_size				,      num_hidden_layers=self.num_hidden_layers				,      num_attention_heads=self.num_attention_heads				,      intermediate_size=self.intermediate_size				,      hidden_act=self.hidden_act				,      hidden_dropout_prob=self.hidden_dropout_prob				,      attention_probs_dropout_prob=self.attention_probs_dropout_prob				,      max_position_embeddings=self.max_position_embeddings				,      type_vocab_size=self.type_vocab_size				,      relative_attention=self.relative_attention				,      position_biased_input=self.position_biased_input				,      initializer_range=self.initializer_range				,      return_dict=__lowerCAmelCase				,      )

					return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels






			def   a_			(     self  :       Optional[Any]				,      __lowerCAmelCase  :       List[Any]				,      __lowerCAmelCase  :       Any				,      __lowerCAmelCase  :       List[Any]				,      __lowerCAmelCase  :       Optional[Any]				,      __lowerCAmelCase  :       List[str]				,      __lowerCAmelCase  :       List[Any]				,      __lowerCAmelCase  :       List[str]  )      ->      str:







					"""simple docstring"""






					A__     =  TFDebertaVaModel(config=__lowerCAmelCase  )
					A__     =  {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}

					A__     =  [input_ids, input_mask]
					A__     =  model(__lowerCAmelCase  )

					A__     =  model(__lowerCAmelCase  )

					self.parent.assertEqual(result.last_hidden_state.shape				,      (self.batch_size, self.seq_length, self.hidden_size)  )






			def   a_			(     self  :       List[str]				,      __lowerCAmelCase  :       Union[str, Any]				,      __lowerCAmelCase  :       Any				,      __lowerCAmelCase  :       int				,      __lowerCAmelCase  :       Optional[Any]				,      __lowerCAmelCase  :       Union[str, Any]				,      __lowerCAmelCase  :       Union[str, Any]				,      __lowerCAmelCase  :       Tuple  )      ->      Union[str, Any]:







					"""simple docstring"""






					A__     =  TFDebertaVaForMaskedLM(config=__lowerCAmelCase  )
					A__     =  {
					    """input_ids""": input_ids,
					    """attention_mask""": input_mask,
					    """token_type_ids""": token_type_ids,
					}
					A__     =  model(__lowerCAmelCase  )
					self.parent.assertEqual(result.logits.shape				,      (self.batch_size, self.seq_length, self.vocab_size)  )






			def   a_			(     self  :       List[str]				,      __lowerCAmelCase  :       Union[str, Any]				,      __lowerCAmelCase  :       Optional[Any]				,      __lowerCAmelCase  :       Tuple				,      __lowerCAmelCase  :       Tuple				,      __lowerCAmelCase  :       int				,      __lowerCAmelCase  :       Union[str, Any]				,      __lowerCAmelCase  :       Any  )      ->      Optional[int]:







					"""simple docstring"""






					A__     =  self.num_labels
					A__     =  TFDebertaVaForSequenceClassification(config=__lowerCAmelCase  )
					A__     =  {
					    """input_ids""": input_ids,
					    """attention_mask""": input_mask,
					    """token_type_ids""": token_type_ids,
					}

					A__     =  model(__lowerCAmelCase  )
					self.parent.assertEqual(result.logits.shape				,      (self.batch_size, self.num_labels)  )






			def   a_			(     self  :       Dict				,      __lowerCAmelCase  :       Optional[Any]				,      __lowerCAmelCase  :       Dict				,      __lowerCAmelCase  :       List[Any]				,      __lowerCAmelCase  :       List[Any]				,      __lowerCAmelCase  :       Dict				,      __lowerCAmelCase  :       Optional[int]				,      __lowerCAmelCase  :       int  )      ->      int:







					"""simple docstring"""






					A__     =  self.num_labels
					A__     =  TFDebertaVaForTokenClassification(config=__lowerCAmelCase  )
					A__     =  {
					    """input_ids""": input_ids,
					    """attention_mask""": input_mask,
					    """token_type_ids""": token_type_ids,
					}
					A__     =  model(__lowerCAmelCase  )
					self.parent.assertEqual(result.logits.shape				,      (self.batch_size, self.seq_length, self.num_labels)  )






			def   a_			(     self  :       List[str]				,      __lowerCAmelCase  :       str				,      __lowerCAmelCase  :       Dict				,      __lowerCAmelCase  :       Any				,      __lowerCAmelCase  :       Optional[int]				,      __lowerCAmelCase  :       str				,      __lowerCAmelCase  :       Dict				,      __lowerCAmelCase  :       Optional[Any]  )      ->      Tuple:







					"""simple docstring"""






					A__     =  TFDebertaVaForQuestionAnswering(config=__lowerCAmelCase  )
					A__     =  {
					    """input_ids""": input_ids,
					    """attention_mask""": input_mask,
					    """token_type_ids""": token_type_ids,
					}

					A__     =  model(__lowerCAmelCase  )
					self.parent.assertEqual(result.start_logits.shape				,      (self.batch_size, self.seq_length)  )
					self.parent.assertEqual(result.end_logits.shape				,      (self.batch_size, self.seq_length)  )







			def   a_			(     self  :       List[Any]  )      ->      Any:







					"""simple docstring"""






					A__     =  self.prepare_config_and_inputs()
					(
					    (
					    A__
					) ,     (
					    A__
					) ,     (
					    A__
					) ,     (
					    A__
					) ,     (
					    A__
					) ,     (
					    A__
					) ,     (
					    A__
					) ,     
					)     =  config_and_inputs
					A__     =  {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
					return config, inputs_dict


@require_tf
class     A     (SCREAMING_SNAKE_CASE  ,	SCREAMING_SNAKE_CASE  ,	unittest.TestCase       ):
			'''simple docstring'''




			__lowerCamelCase      :			List[Any]							     =       (
			    (
			        TFDebertaVaModel,
			        TFDebertaVaForMaskedLM,
			        TFDebertaVaForQuestionAnswering,
			        TFDebertaVaForSequenceClassification,
			        TFDebertaVaForTokenClassification,
			    )
			    if is_tf_available()
			    else ()
			)
			__lowerCamelCase      :			Optional[int]							     =       (
			    {
			        '''feature-extraction''': TFDebertaVaModel,
			        '''fill-mask''': TFDebertaVaForMaskedLM,
			        '''question-answering''': TFDebertaVaForQuestionAnswering,
			        '''text-classification''': TFDebertaVaForSequenceClassification,
			        '''token-classification''': TFDebertaVaForTokenClassification,
			        '''zero-shot''': TFDebertaVaForSequenceClassification,
			    }
			    if is_tf_available()
			    else {}
			)

			__lowerCamelCase      :			List[Any]							     =       False
			__lowerCamelCase      :			Dict							     =       False






			def   a_			(     self  :       int  )      ->      int:







					"""simple docstring"""






					A__     =  TFDebertaVaModelTester(self  )
					A__     =  ConfigTester(self				,      config_class=__lowerCAmelCase				,      hidden_size=37  )






			def   a_			(     self  :       Optional[Any]  )      ->      Tuple:







					"""simple docstring"""






					self.config_tester.run_common_tests()






			def   a_			(     self  :       List[str]  )      ->      Optional[Any]:







					"""simple docstring"""






					A__     =  self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_model(*__lowerCAmelCase  )






			def   a_			(     self  :       Optional[Any]  )      ->      Optional[int]:







					"""simple docstring"""






					A__     =  self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_masked_lm(*__lowerCAmelCase  )






			def   a_			(     self  :       int  )      ->      str:







					"""simple docstring"""






					A__     =  self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_question_answering(*__lowerCAmelCase  )






			def   a_			(     self  :       Dict  )      ->      Any:







					"""simple docstring"""






					A__     =  self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_sequence_classification(*__lowerCAmelCase  )






			def   a_			(     self  :       Dict  )      ->      str:







					"""simple docstring"""






					A__     =  self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_token_classification(*__lowerCAmelCase  )







			@slow
			def   a_			(     self  :       Union[str, Any]  )      ->      Optional[Any]:







					"""simple docstring"""






					A__     =  TFDebertaVaModel.from_pretrained("""kamalkraj/deberta-v2-xlarge"""  )
					self.assertIsNotNone(__lowerCAmelCase  )


@require_tf
class     A     (unittest.TestCase       ):
			'''simple docstring'''




			@unittest.skip(reason="""Model not available yet"""  )
			def   a_			(     self  :       Optional[Any]  )      ->      Optional[int]:







					"""simple docstring"""






					pass







			@slow
			def   a_			(     self  :       List[str]  )      ->      Optional[int]:







					"""simple docstring"""






					A__     =  TFDebertaVaModel.from_pretrained("""kamalkraj/deberta-v2-xlarge"""  )
					A__     =  tf.constant([[0, 3_14_14, 2_32, 3_28, 7_40, 11_40, 1_26_95, 69, 4_60_78, 15_88, 2]]  )
					A__     =  tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]  )
					A__     =  model(__lowerCAmelCase				,      attention_mask=__lowerCAmelCase  )[0]

					A__     =  tf.constant(
					    [[[0.2_3_5_6, 0.1_9_4_8, 0.0_3_6_9], [-0.1_0_6_3, 0.3_5_8_6, -0.5_1_5_2], [-0.6_3_9_9, -0.0_2_5_9, -0.2_5_2_5]]]  )
					tf.debugging.assert_near(output[:, 1:4, 1:4]				,      __lowerCAmelCase				,      atol=1e-4  )










import warnings
from contextlib import contextmanager

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


class     A     (SCREAMING_SNAKE_CASE       ):
			'''simple docstring'''




			__lowerCamelCase      :			Dict							     =       '''Wav2Vec2FeatureExtractor'''
			__lowerCamelCase      :			str							     =       '''AutoTokenizer'''






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







					"""simple docstring"""






					super().__init__(__lowerCAmelCase				,      __lowerCAmelCase  )
					A__     =  self.feature_extractor
					A__     =  False






			@classmethod
			def   a_			(     cls  :       Union[str, Any]				,      __lowerCAmelCase  :       Optional[Any]				,      **__lowerCAmelCase  :       Union[str, Any]  )      ->      int:







					"""simple docstring"""






					try:
							return super().from_pretrained(__lowerCAmelCase				,      **__lowerCAmelCase  )
					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: """				,      __lowerCAmelCase				,      )

							A__     =  WavaVecaFeatureExtractor.from_pretrained(__lowerCAmelCase				,      **__lowerCAmelCase  )
							A__     =  WavaVecaCTCTokenizer.from_pretrained(__lowerCAmelCase				,      **__lowerCAmelCase  )

							return cls(feature_extractor=__lowerCAmelCase				,      tokenizer=__lowerCAmelCase  )






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







					"""simple docstring"""






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

					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"""				,      __lowerCAmelCase  )
					A__     =  kwargs.pop("""sampling_rate"""				,      __lowerCAmelCase  )
					A__     =  kwargs.pop("""text"""				,      __lowerCAmelCase  )
					if len(__lowerCAmelCase  ) > 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(__lowerCAmelCase				,      *__lowerCAmelCase				,      sampling_rate=__lowerCAmelCase				,      **__lowerCAmelCase  )
					if text is not None:
							A__     =  self.tokenizer(__lowerCAmelCase				,      **__lowerCAmelCase  )

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






			def   a_			(     self  :       List[str]				,      *__lowerCAmelCase  :       Optional[Any]				,      **__lowerCAmelCase  :       Tuple  )      ->      List[str]:







					"""simple docstring"""






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

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

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

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






			def   a_			(     self  :       Optional[int]				,      *__lowerCAmelCase  :       List[str]				,      **__lowerCAmelCase  :       List[Any]  )      ->      Dict:







					"""simple docstring"""






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






			def   a_			(     self  :       Any				,      *__lowerCAmelCase  :       List[str]				,      **__lowerCAmelCase  :       Union[str, Any]  )      ->      List[str]:







					"""simple docstring"""






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







			@contextmanager
			def   a_			(     self  :       Union[str, Any]  )      ->      int:







					"""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



