'''simple docstring'''

from __future__ import annotations

import unittest

from transformers import MobileBertConfig, is_tf_available
from transformers.models.auto import get_values
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 (
							    TF_MODEL_FOR_PRETRAINING_MAPPING,
							    TFMobileBertForMaskedLM,
							    TFMobileBertForMultipleChoice,
							    TFMobileBertForNextSentencePrediction,
							    TFMobileBertForPreTraining,
							    TFMobileBertForQuestionAnswering,
							    TFMobileBertForSequenceClassification,
							    TFMobileBertForTokenClassification,
							    TFMobileBertModel,
							)
@require_tf
class   SCREAMING_SNAKE_CASE			(						__lowercase    ,			__lowercase    ,			unittest.TestCase):







		"""simple docstring"""
		lowercase   :      str       =							(
		    (
		        TFMobileBertModel,
		        TFMobileBertForMaskedLM,
		        TFMobileBertForNextSentencePrediction,
		        TFMobileBertForPreTraining,
		        TFMobileBertForQuestionAnswering,
		        TFMobileBertForSequenceClassification,
		        TFMobileBertForTokenClassification,
		        TFMobileBertForMultipleChoice,
		    )
		    if is_tf_available()
		    else ()
		)
		lowercase   :      Union[str, Any]       =							(
		    {
		        'feature-extraction': TFMobileBertModel,
		        'fill-mask': TFMobileBertForMaskedLM,
		        'question-answering': TFMobileBertForQuestionAnswering,
		        'text-classification': TFMobileBertForSequenceClassification,
		        'token-classification': TFMobileBertForTokenClassification,
		        'zero-shot': TFMobileBertForSequenceClassification,
		    }
		    if is_tf_available()
		    else {}
		)
		lowercase   :      List[str]       =							False
		lowercase   :      str       =							False






		def 		UpperCamelCase__       (   self		,						__A		,						__A		,						__A=False				) ->     Optional[int]:
								_lowerCAmelCase										=super()._prepare_for_class(__A		,						__A		,						return_labels=__A				)

								if return_labels:
														if model_class in get_values(__A				):
																				_lowerCAmelCase										=tf.zeros(self.model_tester.batch_size		,						dtype=tf.intaa				)

								return inputs_dict
		class   SCREAMING_SNAKE_CASE			(						__lowercase):







				"""simple docstring"""






				def __init__(   self		,						__A		,						__A=13		,						__A=7		,						__A=True		,						__A=True		,						__A=True		,						__A=True		,						__A=99		,						__A=32		,						__A=32		,						__A=2		,						__A=4		,						__A=37		,						__A="gelu"		,						__A=0.1		,						__A=0.1		,						__A=512		,						__A=16		,						__A=2		,						__A=0.02		,						__A=3		,						__A=4		,						__A=None		,						) ->     Any:
										_lowerCAmelCase										=parent
										_lowerCAmelCase										=batch_size
										_lowerCAmelCase										=seq_length
										_lowerCAmelCase										=is_training
										_lowerCAmelCase										=use_input_mask
										_lowerCAmelCase										=use_token_type_ids
										_lowerCAmelCase										=use_labels
										_lowerCAmelCase										=vocab_size
										_lowerCAmelCase										=hidden_size
										_lowerCAmelCase										=num_hidden_layers
										_lowerCAmelCase										=num_attention_heads
										_lowerCAmelCase										=intermediate_size
										_lowerCAmelCase										=hidden_act
										_lowerCAmelCase										=hidden_dropout_prob
										_lowerCAmelCase										=attention_probs_dropout_prob
										_lowerCAmelCase										=max_position_embeddings
										_lowerCAmelCase										=type_vocab_size
										_lowerCAmelCase										=type_sequence_label_size
										_lowerCAmelCase										=initializer_range
										_lowerCAmelCase										=num_labels
										_lowerCAmelCase										=num_choices
										_lowerCAmelCase										=scope
										_lowerCAmelCase										=embedding_size






				def 		UpperCamelCase__       (   self				) ->     str:
										_lowerCAmelCase										=ids_tensor([self.batch_size, self.seq_length]		,						self.vocab_size				)

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

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

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

										_lowerCAmelCase										=MobileBertConfig(
										    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		,						initializer_range=self.initializer_range		,						embedding_size=self.embedding_size		,						)

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






				def 		UpperCamelCase__       (   self		,						__A		,						__A		,						__A		,						__A		,						__A		,						__A		,						__A				) ->     Union[str, Any]:
										_lowerCAmelCase										=TFMobileBertModel(config=__A				)
										_lowerCAmelCase										={'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
										_lowerCAmelCase										=model(__A				)

										_lowerCAmelCase										=[input_ids, input_mask]
										_lowerCAmelCase										=model(__A				)

										_lowerCAmelCase										=model(__A				)

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






				def 		UpperCamelCase__       (   self		,						__A		,						__A		,						__A		,						__A		,						__A		,						__A		,						__A				) ->     int:
										_lowerCAmelCase										=TFMobileBertForMaskedLM(config=__A				)
										_lowerCAmelCase										={'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
										_lowerCAmelCase										=model(__A				)
										self.parent.assertEqual(result.logits.shape		,						(self.batch_size, self.seq_length, self.vocab_size)				)






				def 		UpperCamelCase__       (   self		,						__A		,						__A		,						__A		,						__A		,						__A		,						__A		,						__A				) ->     int:
										_lowerCAmelCase										=TFMobileBertForNextSentencePrediction(config=__A				)
										_lowerCAmelCase										={'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
										_lowerCAmelCase										=model(__A				)
										self.parent.assertEqual(result.logits.shape		,						(self.batch_size, 2)				)






				def 		UpperCamelCase__       (   self		,						__A		,						__A		,						__A		,						__A		,						__A		,						__A		,						__A				) ->     Optional[int]:
										_lowerCAmelCase										=TFMobileBertForPreTraining(config=__A				)
										_lowerCAmelCase										={'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
										_lowerCAmelCase										=model(__A				)
										self.parent.assertEqual(
										    result.prediction_logits.shape		,						(self.batch_size, self.seq_length, self.vocab_size)				)
										self.parent.assertEqual(result.seq_relationship_logits.shape		,						(self.batch_size, 2)				)






				def 		UpperCamelCase__       (   self		,						__A		,						__A		,						__A		,						__A		,						__A		,						__A		,						__A				) ->     List[Any]:
										_lowerCAmelCase										=self.num_labels
										_lowerCAmelCase										=TFMobileBertForSequenceClassification(config=__A				)
										_lowerCAmelCase										={'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
										_lowerCAmelCase										=model(__A				)
										self.parent.assertEqual(result.logits.shape		,						(self.batch_size, self.num_labels)				)






				def 		UpperCamelCase__       (   self		,						__A		,						__A		,						__A		,						__A		,						__A		,						__A		,						__A				) ->     Any:
										_lowerCAmelCase										=self.num_choices
										_lowerCAmelCase										=TFMobileBertForMultipleChoice(config=__A				)
										_lowerCAmelCase										=tf.tile(tf.expand_dims(__A		,						1				)		,						(1, self.num_choices, 1)				)
										_lowerCAmelCase										=tf.tile(tf.expand_dims(__A		,						1				)		,						(1, self.num_choices, 1)				)
										_lowerCAmelCase										=tf.tile(tf.expand_dims(__A		,						1				)		,						(1, self.num_choices, 1)				)
										_lowerCAmelCase										={
										    'input_ids': multiple_choice_inputs_ids,
										    'attention_mask': multiple_choice_input_mask,
										    'token_type_ids': multiple_choice_token_type_ids,
										}
										_lowerCAmelCase										=model(__A				)
										self.parent.assertEqual(result.logits.shape		,						(self.batch_size, self.num_choices)				)






				def 		UpperCamelCase__       (   self		,						__A		,						__A		,						__A		,						__A		,						__A		,						__A		,						__A				) ->     List[Any]:
										_lowerCAmelCase										=self.num_labels
										_lowerCAmelCase										=TFMobileBertForTokenClassification(config=__A				)
										_lowerCAmelCase										={'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
										_lowerCAmelCase										=model(__A				)
										self.parent.assertEqual(result.logits.shape		,						(self.batch_size, self.seq_length, self.num_labels)				)






				def 		UpperCamelCase__       (   self		,						__A		,						__A		,						__A		,						__A		,						__A		,						__A		,						__A				) ->     Optional[int]:
										_lowerCAmelCase										=TFMobileBertForQuestionAnswering(config=__A				)
										_lowerCAmelCase										={'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
										_lowerCAmelCase										=model(__A				)
										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 		UpperCamelCase__       (   self				) ->     List[Any]:
										_lowerCAmelCase										=self.prepare_config_and_inputs()
										(
										    (
										    _lowerCAmelCase
										)						,				(
										    _lowerCAmelCase
										)						,				(
										    _lowerCAmelCase
										)						,				(
										    _lowerCAmelCase
										)						,				(
										    _lowerCAmelCase
										)						,				(
										    _lowerCAmelCase
										)						,				(
										    _lowerCAmelCase
										)						,				
										)										=config_and_inputs
										_lowerCAmelCase										={'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
										return config, inputs_dict






		def 		UpperCamelCase__       (   self				) ->     List[str]:
								_lowerCAmelCase										=TFMobileBertModelTest.TFMobileBertModelTester(self				)
								_lowerCAmelCase										=ConfigTester(self		,						config_class=__A		,						hidden_size=37				)






		def 		UpperCamelCase__       (   self				) ->     Optional[int]:
								self.config_tester.run_common_tests()






		def 		UpperCamelCase__       (   self				) ->     Tuple:
								_lowerCAmelCase										=self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_mobilebert_model(*__A				)






		def 		UpperCamelCase__       (   self				) ->     Optional[Any]:
								_lowerCAmelCase										=self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_mobilebert_for_masked_lm(*__A				)






		def 		UpperCamelCase__       (   self				) ->     List[Any]:
								_lowerCAmelCase										=self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_mobilebert_for_multiple_choice(*__A				)






		def 		UpperCamelCase__       (   self				) ->     Optional[Any]:
								_lowerCAmelCase										=self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_mobilebert_for_next_sequence_prediction(*__A				)






		def 		UpperCamelCase__       (   self				) ->     int:
								_lowerCAmelCase										=self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_mobilebert_for_pretraining(*__A				)






		def 		UpperCamelCase__       (   self				) ->     Union[str, Any]:
								_lowerCAmelCase										=self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_mobilebert_for_question_answering(*__A				)






		def 		UpperCamelCase__       (   self				) ->     str:
								_lowerCAmelCase										=self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_mobilebert_for_sequence_classification(*__A				)






		def 		UpperCamelCase__       (   self				) ->     Dict:
								_lowerCAmelCase										=self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_mobilebert_for_token_classification(*__A				)






		@slow
		def 		UpperCamelCase__       (   self				) ->     Tuple:
								# for model_name in TF_MOBILEBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
								for model_name in ["google/mobilebert-uncased"]:
														_lowerCAmelCase										=TFMobileBertModel.from_pretrained(__A				)
														self.assertIsNotNone(__A				)

@require_tf
class   SCREAMING_SNAKE_CASE			(						unittest.TestCase):







		"""simple docstring"""






		@slow
		def 		UpperCamelCase__       (   self				) ->     Optional[Any]:
								_lowerCAmelCase										=TFMobileBertForPreTraining.from_pretrained('google/mobilebert-uncased'				)
								_lowerCAmelCase										=tf.constant([[0, 1, 2, 3, 4, 5]]				)
								_lowerCAmelCase										=model(__A				)[0]

								_lowerCAmelCase										=[1, 6, 3_0522]
								self.assertEqual(output.shape		,						__A				)

								_lowerCAmelCase										=tf.constant(
								    [
								        [
								            [-4.5_919_547, -9.248_295, -9.645_256],
								            [-6.7_306_175, -6.440_284, -6.6_052_837],
								            [-7.2_743_506, -6.7_847_915, -6.024_673],
								        ]
								    ]				)
								tf.debugging.assert_near(output[:, :3, :3]		,						__A		,						atol=1E-4				)






'''simple docstring'''

lowercase_     		= {
    '''A''': '''.-''', '''B''': '''-...''', '''C''': '''-.-.''', '''D''': '''-..''', '''E''': '''.''', '''F''': '''..-.''', '''G''': '''--.''',
    '''H''': '''....''', '''I''': '''..''', '''J''': '''.---''', '''K''': '''-.-''', '''L''': '''.-..''', '''M''': '''--''', '''N''': '''-.''',
    '''O''': '''---''', '''P''': '''.--.''', '''Q''': '''--.-''', '''R''': '''.-.''', '''S''': '''...''', '''T''': '''-''', '''U''': '''..-''',
    '''V''': '''...-''', '''W''': '''.--''', '''X''': '''-..-''', '''Y''': '''-.--''', '''Z''': '''--..''', '''1''': '''.----''',
    '''2''': '''..---''', '''3''': '''...--''', '''4''': '''....-''', '''5''': '''.....''', '''6''': '''-....''', '''7''': '''--...''',
    '''8''': '''---..''', '''9''': '''----.''', '''0''': '''-----''', '''&''': '''.-...''', '''@''': '''.--.-.''',
    ''':''': '''---...''', ''',''': '''--..--''', '''.''': '''.-.-.-''', '''\'''': '''.----.''', '''"''': '''.-..-.''',
    '''?''': '''..--..''', '''/''': '''-..-.''', '''=''': '''-...-''', '''+''': '''.-.-.''', '''-''': '''-....-''',
    '''(''': '''-.--.''', ''')''': '''-.--.-''', '''!''': '''-.-.--''', ''' ''': '''/'''
}  # Exclamation mark is not in ITU-R recommendation
# fmt: on
lowercase_     		= {value: key for key, value in MORSE_CODE_DICT.items()}



def 							UpperCamelCase__			(			a__      ):


						'''simple docstring'''






						return " ".join(MORSE_CODE_DICT[char] for char in message.upper()      )



def 							UpperCamelCase__			(			a__      ):


						'''simple docstring'''






						return "".join(REVERSE_DICT[char] for char in message.split()      )



def 							UpperCamelCase__			(			):


						'''simple docstring'''






						_lowerCAmelCase										='Morse code here!'
						print(a__      )
						_lowerCAmelCase										=encrypt(a__      )
						print(a__      )
						_lowerCAmelCase										=decrypt(a__      )
						print(a__      )


if __name__ == "__main__":
							main()





