

from __future__ import annotations

import unittest

from transformers import DebertaConfig, 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 (
     TFDebertaForMaskedLM,
     TFDebertaForQuestionAnswering,
     TFDebertaForSequenceClassification,
     TFDebertaForTokenClassification,
     TFDebertaModel,
 )



class 						a_			:



      """simple docstring"""







      def __init__( self	:				Tuple     ,snake_case	:				Union[str, Any]     ,snake_case	:				List[str]=13     ,snake_case	:				Union[str, Any]=7     ,snake_case	:				List[Any]=True     ,snake_case	:				Optional[int]=True     ,snake_case	:				Union[str, Any]=True     ,snake_case	:				Dict=True     ,snake_case	:				Any=99     ,snake_case	:				int=32     ,snake_case	:				Optional[int]=2     ,snake_case	:				Tuple=4     ,snake_case	:				Union[str, Any]=37     ,snake_case	:				Optional[Any]="gelu"     ,snake_case	:				Union[str, Any]=0.1     ,snake_case	:				Union[str, Any]=0.1     ,snake_case	:				Union[str, Any]=512     ,snake_case	:				List[str]=16     ,snake_case	:				List[str]=2     ,snake_case	:				Optional[int]=0.02     ,snake_case	:				int=3     ,snake_case	:				Optional[int]=4     ,snake_case	:				Tuple=None     ,):
           SCREAMING_SNAKE_CASE 		=parent
           SCREAMING_SNAKE_CASE 		=13
           SCREAMING_SNAKE_CASE 		=7
           SCREAMING_SNAKE_CASE 		=True
           SCREAMING_SNAKE_CASE 		=True
           SCREAMING_SNAKE_CASE 		=True
           SCREAMING_SNAKE_CASE 		=True
           SCREAMING_SNAKE_CASE 		=99
           SCREAMING_SNAKE_CASE 		=32
           SCREAMING_SNAKE_CASE 		=2
           SCREAMING_SNAKE_CASE 		=4
           SCREAMING_SNAKE_CASE 		=37
           SCREAMING_SNAKE_CASE 		='gelu'
           SCREAMING_SNAKE_CASE 		=0.1
           SCREAMING_SNAKE_CASE 		=0.1
           SCREAMING_SNAKE_CASE 		=512
           SCREAMING_SNAKE_CASE 		=16
           SCREAMING_SNAKE_CASE 		=False
           SCREAMING_SNAKE_CASE 		=-1
           SCREAMING_SNAKE_CASE 		=True
           SCREAMING_SNAKE_CASE 		=2
           SCREAMING_SNAKE_CASE 		=0.02
           SCREAMING_SNAKE_CASE 		=3
           SCREAMING_SNAKE_CASE 		=4
           SCREAMING_SNAKE_CASE 		=None
      def 			_lowerCAmelCase	( self	:				Tuple							):
           SCREAMING_SNAKE_CASE 		=ids_tensor([self.batch_size, self.seq_length]     ,self.vocab_size							)

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

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

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

           SCREAMING_SNAKE_CASE 		=DebertaConfig(
               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     ,max_relative_positions=self.max_relative_positions     ,position_biased_input=self.position_biased_input     ,initializer_range=self.initializer_range     ,return_dict=snake_case     ,)

           return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels
      def 			_lowerCAmelCase	( self	:				int     ,snake_case	:				List[str]     ,snake_case	:				Union[str, Any]     ,snake_case	:				Optional[Any]     ,snake_case	:				int     ,snake_case	:				int     ,snake_case	:				Dict     ,snake_case	:				List[Any]							):
           SCREAMING_SNAKE_CASE 		=TFDebertaModel(config=snake_case							)
           SCREAMING_SNAKE_CASE 		={'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}

           SCREAMING_SNAKE_CASE 		=[input_ids, input_mask]
           SCREAMING_SNAKE_CASE 		=model(snake_case							)

           SCREAMING_SNAKE_CASE 		=model(snake_case							)

           self.parent.assertEqual(result.last_hidden_state.shape     ,(self.batch_size, self.seq_length, self.hidden_size)							)
      def 			_lowerCAmelCase	( self	:				Tuple     ,snake_case	:				str     ,snake_case	:				Any     ,snake_case	:				Optional[int]     ,snake_case	:				Tuple     ,snake_case	:				str     ,snake_case	:				str     ,snake_case	:				Optional[Any]							):
           SCREAMING_SNAKE_CASE 		=TFDebertaForMaskedLM(config=snake_case							)
           SCREAMING_SNAKE_CASE 		={
               'input_ids': input_ids,
               'attention_mask': input_mask,
               'token_type_ids': token_type_ids,
           }
           SCREAMING_SNAKE_CASE 		=model(snake_case							)
           self.parent.assertEqual(result.logits.shape     ,(self.batch_size, self.seq_length, self.vocab_size)							)
      def 			_lowerCAmelCase	( self	:				int     ,snake_case	:				Union[str, Any]     ,snake_case	:				Optional[int]     ,snake_case	:				int     ,snake_case	:				Optional[int]     ,snake_case	:				List[str]     ,snake_case	:				int     ,snake_case	:				Optional[Any]							):
           SCREAMING_SNAKE_CASE 		=self.num_labels
           SCREAMING_SNAKE_CASE 		=TFDebertaForSequenceClassification(config=snake_case							)
           SCREAMING_SNAKE_CASE 		={
               'input_ids': input_ids,
               'attention_mask': input_mask,
               'token_type_ids': token_type_ids,
           }

           SCREAMING_SNAKE_CASE 		=model(snake_case							)
           self.parent.assertEqual(result.logits.shape     ,(self.batch_size, self.num_labels)							)
      def 			_lowerCAmelCase	( self	:				Optional[int]     ,snake_case	:				str     ,snake_case	:				int     ,snake_case	:				List[Any]     ,snake_case	:				int     ,snake_case	:				Dict     ,snake_case	:				Optional[int]     ,snake_case	:				Tuple							):
           SCREAMING_SNAKE_CASE 		=self.num_labels
           SCREAMING_SNAKE_CASE 		=TFDebertaForTokenClassification(config=snake_case							)
           SCREAMING_SNAKE_CASE 		={
               'input_ids': input_ids,
               'attention_mask': input_mask,
               'token_type_ids': token_type_ids,
           }
           SCREAMING_SNAKE_CASE 		=model(snake_case							)
           self.parent.assertEqual(result.logits.shape     ,(self.batch_size, self.seq_length, self.num_labels)							)
      def 			_lowerCAmelCase	( self	:				Any     ,snake_case	:				List[Any]     ,snake_case	:				int     ,snake_case	:				Any     ,snake_case	:				str     ,snake_case	:				Tuple     ,snake_case	:				Tuple     ,snake_case	:				Any							):
           SCREAMING_SNAKE_CASE 		=TFDebertaForQuestionAnswering(config=snake_case							)
           SCREAMING_SNAKE_CASE 		={
               'input_ids': input_ids,
               'attention_mask': input_mask,
               'token_type_ids': token_type_ids,
           }

           SCREAMING_SNAKE_CASE 		=model(snake_case							)
           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 			_lowerCAmelCase	( self	:				str							):
           SCREAMING_SNAKE_CASE 		=self.prepare_config_and_inputs()
           (
               (
               SCREAMING_SNAKE_CASE
           )		,    (
               SCREAMING_SNAKE_CASE
           )		,    (
               SCREAMING_SNAKE_CASE
           )		,    (
               SCREAMING_SNAKE_CASE
           )		,    (
               SCREAMING_SNAKE_CASE
           )		,    (
               SCREAMING_SNAKE_CASE
           )		,    (
               SCREAMING_SNAKE_CASE
           )		,    
           ) 		=config_and_inputs
           SCREAMING_SNAKE_CASE 		={'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
           return config, inputs_dict







@require_tf
class 						a_			(				lowerCamelCase_					,     lowerCamelCase_					,     unittest.TestCase	):



      """simple docstring"""







      __UpperCAmelCase     						= (
          (
              TFDebertaModel,
              TFDebertaForMaskedLM,
              TFDebertaForQuestionAnswering,
              TFDebertaForSequenceClassification,
              TFDebertaForTokenClassification,
          )
          if is_tf_available()
          else ()
      )
      __UpperCAmelCase     						= (
          {
              'feature-extraction': TFDebertaModel,
              'fill-mask': TFDebertaForMaskedLM,
              'question-answering': TFDebertaForQuestionAnswering,
              'text-classification': TFDebertaForSequenceClassification,
              'token-classification': TFDebertaForTokenClassification,
              'zero-shot': TFDebertaForSequenceClassification,
          }
          if is_tf_available()
          else {}
      )

      __UpperCAmelCase     						= False
      __UpperCAmelCase     						= False
      def 			_lowerCAmelCase	( self	:				Any							):
           SCREAMING_SNAKE_CASE 		=TFDebertaModelTester(self							)
           SCREAMING_SNAKE_CASE 		=ConfigTester(self     ,config_class=snake_case     ,hidden_size=37							)
      def 			_lowerCAmelCase	( self	:				Any							):
           self.config_tester.run_common_tests()
      def 			_lowerCAmelCase	( self	:				Optional[int]							):
           SCREAMING_SNAKE_CASE 		=self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_model(*snake_case							)
      def 			_lowerCAmelCase	( self	:				Union[str, Any]							):
           SCREAMING_SNAKE_CASE 		=self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_masked_lm(*snake_case							)
      def 			_lowerCAmelCase	( self	:				Dict							):
           SCREAMING_SNAKE_CASE 		=self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_question_answering(*snake_case							)
      def 			_lowerCAmelCase	( self	:				Optional[int]							):
           SCREAMING_SNAKE_CASE 		=self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_sequence_classification(*snake_case							)
      def 			_lowerCAmelCase	( self	:				Any							):
           SCREAMING_SNAKE_CASE 		=self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_token_classification(*snake_case							)


      @slow
      def 			_lowerCAmelCase	( self	:				Tuple							):
           SCREAMING_SNAKE_CASE 		=TFDebertaModel.from_pretrained('kamalkraj/deberta-base'							)
           self.assertIsNotNone(snake_case							)







@require_tf
class 						a_			(				unittest.TestCase	):



      """simple docstring"""







      @unittest.skip(reason='Model not available yet'							)
      def 			_lowerCAmelCase	( self	:				Dict							):
           pass


      @slow
      def 			_lowerCAmelCase	( self	:				Any							):
           SCREAMING_SNAKE_CASE 		=TFDebertaModel.from_pretrained('kamalkraj/deberta-base'							)
           SCREAMING_SNAKE_CASE 		=tf.constant([[0, 31414, 232, 328, 740, 1140, 12695, 69, 46078, 1588, 2]]							)
           SCREAMING_SNAKE_CASE 		=tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]							)
           SCREAMING_SNAKE_CASE 		=model(snake_case     ,attention_mask=snake_case							)[0]

           SCREAMING_SNAKE_CASE 		=tf.constant(
               [
                   [
                       [-0.59_855_896, -0.80_552_566, -0.8_462_135],
                       [1.4_484_025, -0.93_483_794, -0.80_593_085],
                       [0.3_122_741, 0.00_316_059, -1.4_131_377],
                   ]
               ]							)
           tf.debugging.assert_near(output[:, 1:4, 1:4]     ,snake_case     ,atol=1e-4							)




import numpy as np







def      snake_case__							(  lowerCAmelCase_     ):





     """simple docstring"""







     SCREAMING_SNAKE_CASE 		=np.exp(lowerCAmelCase_     )

     # Add up the all the exponentials
     SCREAMING_SNAKE_CASE 		=np.sum(lowerCAmelCase_     )

     # Divide every exponent by the sum of all exponents
     SCREAMING_SNAKE_CASE 		=exponent_vector / sum_of_exponents

     return softmax_vector


if __name__ == "__main__":
 print(softmax((0,)))

