"""simple docstring"""







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 							__snake_case:


    '''simple docstring'''





    def __init__(  self					,       __lowerCamelCase					,       __lowerCamelCase=13					,       __lowerCamelCase=7					,       __lowerCamelCase=True					,       __lowerCamelCase=True					,       __lowerCamelCase=True					,       __lowerCamelCase=True					,       __lowerCamelCase=99					,       __lowerCamelCase=32					,       __lowerCamelCase=2					,       __lowerCamelCase=4					,       __lowerCamelCase=37					,       __lowerCamelCase="gelu"					,       __lowerCamelCase=0.1					,       __lowerCamelCase=0.1					,       __lowerCamelCase=512					,       __lowerCamelCase=16					,       __lowerCamelCase=2					,       __lowerCamelCase=0.02					,       __lowerCamelCase=3					,       __lowerCamelCase=4					,       __lowerCamelCase=None					,       ):




         '''simple docstring'''



         __A					:					Dict								=		parent
         __A					:					Tuple								=		13
         __A					:					Optional[Any]								=		7
         __A					:					Optional[Any]								=		True
         __A					:					str								=		True
         __A					:					List[str]								=		True
         __A					:					Union[str, Any]								=		True
         __A					:					List[str]								=		99
         __A					:					Any								=		32
         __A					:					Dict								=		2
         __A					:					List[str]								=		4
         __A					:					List[str]								=		37
         __A					:					List[Any]								=		'''gelu'''
         __A					:					Optional[Any]								=		0.1
         __A					:					List[Any]								=		0.1
         __A					:					Any								=		512
         __A					:					Union[str, Any]								=		16
         __A					:					List[str]								=		False
         __A					:					Any								=		-1
         __A					:					int								=		True
         __A					:					Optional[Any]								=		2
         __A					:					Optional[int]								=		0.02
         __A					:					Optional[Any]								=		3
         __A					:					str								=		4
         __A					:					int								=		None
    def 						_a							(  self	):




         '''simple docstring'''



         __A					:					Optional[int]								=		ids_tensor([self.batch_size, self.seq_length]					,       self.vocab_size	)

         __A					:					Optional[int]								=		None
         if self.use_input_mask:
              __A					:					Any								=		random_attention_mask([self.batch_size, self.seq_length]	)

         __A					:					Union[str, Any]								=		None
         if self.use_token_type_ids:
              __A					:					int								=		ids_tensor([self.batch_size, self.seq_length]					,       self.type_vocab_size	)

         __A					:					Dict								=		None
         __A					:					Optional[int]								=		None
         __A					:					str								=		None
         if self.use_labels:
              __A					:					Dict								=		ids_tensor([self.batch_size]					,       self.type_sequence_label_size	)
              __A					:					Any								=		ids_tensor([self.batch_size, self.seq_length]					,       self.num_labels	)

         __A					:					str								=		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=lowerCAmelCase__					,       )

         return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels
    def 						_a							(  self					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase	):




         '''simple docstring'''



         __A					:					Any								=		TFDebertaModel(config=lowerCAmelCase__	)
         __A					:					List[str]								=		{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}

         __A					:					int								=		[input_ids, input_mask]
         __A					:					Union[str, Any]								=		model(lowerCAmelCase__	)

         __A					:					List[str]								=		model(lowerCAmelCase__	)

         self.parent.assertEqual(result.last_hidden_state.shape					,       (self.batch_size, self.seq_length, self.hidden_size)	)
    def 						_a							(  self					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase	):




         '''simple docstring'''



         __A					:					int								=		TFDebertaForMaskedLM(config=lowerCAmelCase__	)
         __A					:					Tuple								=		{
             '''input_ids''': input_ids,
             '''attention_mask''': input_mask,
             '''token_type_ids''': token_type_ids,
         }
         __A					:					Optional[Any]								=		model(lowerCAmelCase__	)
         self.parent.assertEqual(result.logits.shape					,       (self.batch_size, self.seq_length, self.vocab_size)	)
    def 						_a							(  self					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase	):




         '''simple docstring'''



         __A					:					List[Any]								=		self.num_labels
         __A					:					int								=		TFDebertaForSequenceClassification(config=lowerCAmelCase__	)
         __A					:					Union[str, Any]								=		{
             '''input_ids''': input_ids,
             '''attention_mask''': input_mask,
             '''token_type_ids''': token_type_ids,
         }

         __A					:					Any								=		model(lowerCAmelCase__	)
         self.parent.assertEqual(result.logits.shape					,       (self.batch_size, self.num_labels)	)
    def 						_a							(  self					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase	):




         '''simple docstring'''



         __A					:					int								=		self.num_labels
         __A					:					Optional[int]								=		TFDebertaForTokenClassification(config=lowerCAmelCase__	)
         __A					:					Tuple								=		{
             '''input_ids''': input_ids,
             '''attention_mask''': input_mask,
             '''token_type_ids''': token_type_ids,
         }
         __A					:					Optional[Any]								=		model(lowerCAmelCase__	)
         self.parent.assertEqual(result.logits.shape					,       (self.batch_size, self.seq_length, self.num_labels)	)
    def 						_a							(  self					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase	):




         '''simple docstring'''



         __A					:					List[str]								=		TFDebertaForQuestionAnswering(config=lowerCAmelCase__	)
         __A					:					str								=		{
             '''input_ids''': input_ids,
             '''attention_mask''': input_mask,
             '''token_type_ids''': token_type_ids,
         }

         __A					:					List[str]								=		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	):




         '''simple docstring'''



         __A					:					Tuple								=		self.prepare_config_and_inputs()
         (
             __A				
         )					:					List[Any]								=		config_and_inputs
         __A					:					Dict								=		{'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
         return config, inputs_dict







@require_tf
class 							__snake_case(					_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 						_a							(  self	):




         '''simple docstring'''



         __A					:					str								=		TFDebertaModelTester(self	)
         __A					:					int								=		ConfigTester(self					,       config_class=lowerCAmelCase__					,       hidden_size=37	)
    def 						_a							(  self	):




         '''simple docstring'''



         self.config_tester.run_common_tests()
    def 						_a							(  self	):




         '''simple docstring'''



         __A					:					Optional[Any]								=		self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*lowerCAmelCase__	)
    def 						_a							(  self	):




         '''simple docstring'''



         __A					:					List[Any]								=		self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_masked_lm(*lowerCAmelCase__	)
    def 						_a							(  self	):




         '''simple docstring'''



         __A					:					str								=		self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_question_answering(*lowerCAmelCase__	)
    def 						_a							(  self	):




         '''simple docstring'''



         __A					:					List[Any]								=		self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_sequence_classification(*lowerCAmelCase__	)
    def 						_a							(  self	):




         '''simple docstring'''



         __A					:					Optional[int]								=		self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_token_classification(*lowerCAmelCase__	)

    @slow
    def 						_a							(  self	):




         '''simple docstring'''



         __A					:					Tuple								=		TFDebertaModel.from_pretrained('kamalkraj/deberta-base'	)
         self.assertIsNotNone(lowerCAmelCase__	)







@require_tf
class 							__snake_case(					unittest.TestCase	):


    '''simple docstring'''





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




         '''simple docstring'''



         pass

    @slow
    def 						_a							(  self	):




         '''simple docstring'''



         __A					:					Union[str, Any]								=		TFDebertaModel.from_pretrained('kamalkraj/deberta-base'	)
         __A					:					List[Any]								=		tf.constant([[0, 31414, 232, 328, 740, 1140, 12695, 69, 46078, 1588, 2]]	)
         __A					:					str								=		tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]	)
         __A					:					Tuple								=		model(lowerCAmelCase__					,       attention_mask=lowerCAmelCase__	)[0]

         __A					:					Union[str, Any]								=		tf.constant(
             [
                 [
                     [-0.59_85_58_96, -0.80_55_25_66, -0.8_46_21_35],
                     [1.4_48_40_25, -0.93_48_37_94, -0.80_59_30_85],
                     [0.3_12_27_41, 0.00_31_60_59, -1.4_13_13_77],
                 ]
             ]	)
         tf.debugging.assert_near(output[:, 1:4, 1:4]					,       lowerCAmelCase__					,       atol=1e-4	)










"""simple docstring"""




import os
import sys
import time

from . import transposition_cipher as trans_cipher





def 			a_							(				):
						_UpperCamelCase     :   Dict      =       '''Prehistoric Men.txt'''
						_UpperCamelCase     :   Optional[Any]      =       '''Output.txt'''
						_UpperCamelCase     :   Any      =       int(input('''Enter key: '''  )  )
						_UpperCamelCase     :   Optional[Any]      =       input('''Encrypt/Decrypt [e/d]: '''  )

						if not os.path.exists(_lowercase  ):
												print(F"""File {input_file} does not exist. Quitting..."""  )
												sys.exit()
						if os.path.exists(_lowercase  ):
												print(F"""Overwrite {output_file}? [y/n]"""  )
												_UpperCamelCase     :   Optional[int]      =       input('''> '''  )
												if not response.lower().startswith('''y'''  ):
																		sys.exit()

						_UpperCamelCase     :   List[str]      =       time.time()
						if mode.lower().startswith('''e'''  ):
												with open(_lowercase  ) as f:
																		_UpperCamelCase     :   Optional[int]      =       f.read()
												_UpperCamelCase     :   List[str]      =       trans_cipher.encrypt_message(_lowercase			,		_lowercase  )
						elif mode.lower().startswith('''d'''  ):
												with open(_lowercase  ) as f:
																		_UpperCamelCase     :   Dict      =       f.read()
												_UpperCamelCase     :   Any      =       trans_cipher.decrypt_message(_lowercase			,		_lowercase  )

						with open(_lowercase			,		'''w'''  ) as output_obj:
												output_obj.write(_lowercase  )

						_UpperCamelCase     :   List[str]      =       round(time.time() - start_time			,		2  )
						print(('''Done (''', total_time, '''seconds )''')  )


if __name__ == "__main__":
						main()



