
"""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     lowercase(_lowercase    ,						_lowercase    ,						unittest.TestCase       ):
     __snake_case:	Tuple						=     (
         (
             TFMobileBertModel,
             TFMobileBertForMaskedLM,
             TFMobileBertForNextSentencePrediction,
             TFMobileBertForPreTraining,
             TFMobileBertForQuestionAnswering,
             TFMobileBertForSequenceClassification,
             TFMobileBertForTokenClassification,
             TFMobileBertForMultipleChoice,
         )
         if is_tf_available()
         else ()
     )
     __snake_case:	int						=     (
         {
             'feature-extraction': TFMobileBertModel,
             'fill-mask': TFMobileBertForMaskedLM,
             'question-answering': TFMobileBertForQuestionAnswering,
             'text-classification': TFMobileBertForSequenceClassification,
             'token-classification': TFMobileBertForTokenClassification,
             'zero-shot': TFMobileBertForSequenceClassification,
         }
         if is_tf_available()
         else {}
     )
     __snake_case:	int						=     False
     __snake_case:	Any						=     False



     def 			lowercase__  (							self     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE=False   )		->     int:







         """simple docstring"""



         a__		=			super()._prepare_for_class(__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				return_labels=__SCREAMING_SNAKE_CASE   )

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

         return inputs_dict







     class     lowercase(_lowercase       ):



          def __init__(							self     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE=1_3     ,				__SCREAMING_SNAKE_CASE=7     ,				__SCREAMING_SNAKE_CASE=True     ,				__SCREAMING_SNAKE_CASE=True     ,				__SCREAMING_SNAKE_CASE=True     ,				__SCREAMING_SNAKE_CASE=True     ,				__SCREAMING_SNAKE_CASE=9_9     ,				__SCREAMING_SNAKE_CASE=3_2     ,				__SCREAMING_SNAKE_CASE=3_2     ,				__SCREAMING_SNAKE_CASE=2     ,				__SCREAMING_SNAKE_CASE=4     ,				__SCREAMING_SNAKE_CASE=3_7     ,				__SCREAMING_SNAKE_CASE="gelu"     ,				__SCREAMING_SNAKE_CASE=0.1     ,				__SCREAMING_SNAKE_CASE=0.1     ,				__SCREAMING_SNAKE_CASE=5_1_2     ,				__SCREAMING_SNAKE_CASE=1_6     ,				__SCREAMING_SNAKE_CASE=2     ,				__SCREAMING_SNAKE_CASE=0.02     ,				__SCREAMING_SNAKE_CASE=3     ,				__SCREAMING_SNAKE_CASE=4     ,				__SCREAMING_SNAKE_CASE=None     ,				)		->     Tuple:







              """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__		=			scope
              a__		=			embedding_size



          def 			lowercase__  (							self   )		->     Dict:







              """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__		=			ids_tensor([self.batch_size]     ,				self.num_choices   )

              a__		=			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 			lowercase__  (							self     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE   )		->     Dict:







              """simple docstring"""



              a__		=			TFMobileBertModel(config=__SCREAMING_SNAKE_CASE   )
              a__		=			{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
              a__		=			model(__SCREAMING_SNAKE_CASE   )

              a__		=			[input_ids, input_mask]
              a__		=			model(__SCREAMING_SNAKE_CASE   )

              a__		=			model(__SCREAMING_SNAKE_CASE   )

              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 			lowercase__  (							self     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE   )		->     Any:







              """simple docstring"""



              a__		=			TFMobileBertForMaskedLM(config=__SCREAMING_SNAKE_CASE   )
              a__		=			{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
              a__		=			model(__SCREAMING_SNAKE_CASE   )
              self.parent.assertEqual(result.logits.shape     ,				(self.batch_size, self.seq_length, self.vocab_size)   )



          def 			lowercase__  (							self     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE   )		->     str:







              """simple docstring"""



              a__		=			TFMobileBertForNextSentencePrediction(config=__SCREAMING_SNAKE_CASE   )
              a__		=			{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
              a__		=			model(__SCREAMING_SNAKE_CASE   )
              self.parent.assertEqual(result.logits.shape     ,				(self.batch_size, 2)   )



          def 			lowercase__  (							self     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE   )		->     str:







              """simple docstring"""



              a__		=			TFMobileBertForPreTraining(config=__SCREAMING_SNAKE_CASE   )
              a__		=			{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
              a__		=			model(__SCREAMING_SNAKE_CASE   )
              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 			lowercase__  (							self     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE   )		->     Tuple:







              """simple docstring"""



              a__		=			self.num_labels
              a__		=			TFMobileBertForSequenceClassification(config=__SCREAMING_SNAKE_CASE   )
              a__		=			{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
              a__		=			model(__SCREAMING_SNAKE_CASE   )
              self.parent.assertEqual(result.logits.shape     ,				(self.batch_size, self.num_labels)   )



          def 			lowercase__  (							self     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE   )		->     Dict:







              """simple docstring"""



              a__		=			self.num_choices
              a__		=			TFMobileBertForMultipleChoice(config=__SCREAMING_SNAKE_CASE   )
              a__		=			tf.tile(tf.expand_dims(__SCREAMING_SNAKE_CASE     ,				1   )     ,				(1, self.num_choices, 1)   )
              a__		=			tf.tile(tf.expand_dims(__SCREAMING_SNAKE_CASE     ,				1   )     ,				(1, self.num_choices, 1)   )
              a__		=			tf.tile(tf.expand_dims(__SCREAMING_SNAKE_CASE     ,				1   )     ,				(1, self.num_choices, 1)   )
              a__		=			{
                  'input_ids': multiple_choice_inputs_ids,
                  'attention_mask': multiple_choice_input_mask,
                  'token_type_ids': multiple_choice_token_type_ids,
              }
              a__		=			model(__SCREAMING_SNAKE_CASE   )
              self.parent.assertEqual(result.logits.shape     ,				(self.batch_size, self.num_choices)   )



          def 			lowercase__  (							self     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE   )		->     Dict:







              """simple docstring"""



              a__		=			self.num_labels
              a__		=			TFMobileBertForTokenClassification(config=__SCREAMING_SNAKE_CASE   )
              a__		=			{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
              a__		=			model(__SCREAMING_SNAKE_CASE   )
              self.parent.assertEqual(result.logits.shape     ,				(self.batch_size, self.seq_length, self.num_labels)   )



          def 			lowercase__  (							self     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE   )		->     str:







              """simple docstring"""



              a__		=			TFMobileBertForQuestionAnswering(config=__SCREAMING_SNAKE_CASE   )
              a__		=			{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
              a__		=			model(__SCREAMING_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 			lowercase__  (							self   )		->     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




     def 			lowercase__  (							self   )		->     Optional[Any]:







         """simple docstring"""



         a__		=			TFMobileBertModelTest.TFMobileBertModelTester(self   )
         a__		=			ConfigTester(self     ,				config_class=__SCREAMING_SNAKE_CASE     ,				hidden_size=3_7   )



     def 			lowercase__  (							self   )		->     Optional[int]:







         """simple docstring"""



         self.config_tester.run_common_tests()



     def 			lowercase__  (							self   )		->     Optional[Any]:







         """simple docstring"""



         a__		=			self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_mobilebert_model(*__SCREAMING_SNAKE_CASE   )



     def 			lowercase__  (							self   )		->     Tuple:







         """simple docstring"""



         a__		=			self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_mobilebert_for_masked_lm(*__SCREAMING_SNAKE_CASE   )



     def 			lowercase__  (							self   )		->     Any:







         """simple docstring"""



         a__		=			self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_mobilebert_for_multiple_choice(*__SCREAMING_SNAKE_CASE   )



     def 			lowercase__  (							self   )		->     str:







         """simple docstring"""



         a__		=			self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_mobilebert_for_next_sequence_prediction(*__SCREAMING_SNAKE_CASE   )



     def 			lowercase__  (							self   )		->     Tuple:







         """simple docstring"""



         a__		=			self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_mobilebert_for_pretraining(*__SCREAMING_SNAKE_CASE   )



     def 			lowercase__  (							self   )		->     Any:







         """simple docstring"""



         a__		=			self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_mobilebert_for_question_answering(*__SCREAMING_SNAKE_CASE   )



     def 			lowercase__  (							self   )		->     Union[str, Any]:







         """simple docstring"""



         a__		=			self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_mobilebert_for_sequence_classification(*__SCREAMING_SNAKE_CASE   )



     def 			lowercase__  (							self   )		->     Optional[int]:







         """simple docstring"""



         a__		=			self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_mobilebert_for_token_classification(*__SCREAMING_SNAKE_CASE   )




     @slow
     def 			lowercase__  (							self   )		->     Optional[int]:







         """simple docstring"""



         for model_name in ["google/mobilebert-uncased"]:
             a__		=			TFMobileBertModel.from_pretrained(__SCREAMING_SNAKE_CASE   )
             self.assertIsNotNone(__SCREAMING_SNAKE_CASE   )







@require_tf
class     lowercase(unittest.TestCase       ):



     @slow
     def 			lowercase__  (							self   )		->     str:







         """simple docstring"""



         a__		=			TFMobileBertForPreTraining.from_pretrained('google/mobilebert-uncased'   )
         a__		=			tf.constant([[0, 1, 2, 3, 4, 5]]   )
         a__		=			model(__SCREAMING_SNAKE_CASE   )[0]

         a__		=			[1, 6, 3_0_5_2_2]
         self.assertEqual(output.shape     ,				__SCREAMING_SNAKE_CASE   )

         a__		=			tf.constant(
             [
                 [
                     [-4.5_91_95_47, -9.24_82_95, -9.64_52_56],
                     [-6.7_30_61_75, -6.44_02_84, -6.6_05_28_37],
                     [-7.2_74_35_06, -6.7_84_79_15, -6.02_46_73],
                 ]
             ]   )
         tf.debugging.assert_near(output[:, :3, :3]     ,				__SCREAMING_SNAKE_CASE     ,				atol=1e-4   )




"""simple docstring"""




from __future__ import annotations

a		:       str     						=       {
    'A': ['B', 'C', 'E'],
    'B': ['A', 'D', 'E'],
    'C': ['A', 'F', 'G'],
    'D': ['B'],
    'E': ['A', 'B', 'D'],
    'F': ['C'],
    'G': ['C'],
}







class     lowercase:



     def __init__(							self     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE   )		->     None:







         """simple docstring"""



         a__		=			graph
         # mapping node to its parent in resulting breadth first tree
         a__		=			{}
         a__		=			source_vertex



     def 			lowercase__  (							self   )		->     None:







         """simple docstring"""



         a__		=			{self.source_vertex}
         a__		=			None
         a__		=			[self.source_vertex]  # first in first out queue

         while queue:
             a__		=			queue.pop(0   )
             for adjacent_vertex in self.graph[vertex]:
                 if adjacent_vertex not in visited:
                     visited.add(__SCREAMING_SNAKE_CASE   )
                     a__		=			vertex
                     queue.append(__SCREAMING_SNAKE_CASE   )




     def 			lowercase__  (							self     ,				__SCREAMING_SNAKE_CASE   )		->     str:







         """simple docstring"""



         if target_vertex == self.source_vertex:
             return self.source_vertex

         a__		=			self.parent.get(__SCREAMING_SNAKE_CASE   )
         if target_vertex_parent is None:
             a__		=			(
                 f'No path from vertex: {self.source_vertex} to vertex: {target_vertex}'
             )
             raise ValueError(__SCREAMING_SNAKE_CASE   )

         return self.shortest_path(__SCREAMING_SNAKE_CASE   ) + f'->{target_vertex}'


if __name__ == "__main__":
    a		:       Optional[Any]     						=       Graph(graph, 'G')
    g.breath_first_search()
    print(g.shortest_path('D'))
    print(g.shortest_path('G'))
    print(g.shortest_path('Foo'))


