
'''simple docstring'''






from __future__ import annotations

import unittest

from transformers import AlbertConfig, 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
      from transformers.models.albert.modeling_tf_albert import (
          TF_ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
          TFAlbertForMaskedLM,
          TFAlbertForMultipleChoice,
          TFAlbertForPreTraining,
          TFAlbertForQuestionAnswering,
          TFAlbertForSequenceClassification,
          TFAlbertForTokenClassification,
          TFAlbertModel,
      )

class   SCREAMING_SNAKE_CASE_		:



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






        '''simple docstring'''




        lowercase  :		Dict						=      parent
        lowercase  :		Any						=      13
        lowercase  :		str						=      7
        lowercase  :		Optional[Any]						=      True
        lowercase  :		Any						=      True
        lowercase  :		Optional[int]						=      True
        lowercase  :		str						=      True
        lowercase  :		int						=      99
        lowercase  :		int						=      16
        lowercase  :		str						=      32
        lowercase  :		Tuple						=      2
        lowercase  :		int						=      4
        lowercase  :		int						=      37
        lowercase  :		List[str]						=      '''gelu'''
        lowercase  :		List[str]						=      0.1
        lowercase  :		Union[str, Any]						=      0.1
        lowercase  :		Any						=      512
        lowercase  :		int						=      16
        lowercase  :		Optional[Any]						=      2
        lowercase  :		Any						=      0.0_2
        lowercase  :		List[Any]						=      3
        lowercase  :		int						=      4
        lowercase  :		Tuple						=      None



 def    SCREAMING_SNAKE_CASE(  self ):






        '''simple docstring'''




        lowercase  :		List[str]						=      ids_tensor([self.batch_size, self.seq_length]   ,		self.vocab_size )

        lowercase  :		List[str]						=      None
        if self.use_input_mask:
               lowercase  :		Union[str, Any]						=      random_attention_mask([self.batch_size, self.seq_length] )

        lowercase  :		Tuple						=      None
        if self.use_token_type_ids:
               lowercase  :		Optional[int]						=      ids_tensor([self.batch_size, self.seq_length]   ,		self.type_vocab_size )

        lowercase  :		int						=      None
        lowercase  :		Tuple						=      None
        lowercase  :		int						=      None
        if self.use_labels:
               lowercase  :		Optional[int]						=      ids_tensor([self.batch_size]   ,		self.type_sequence_label_size )
               lowercase  :		Optional[Any]						=      ids_tensor([self.batch_size, self.seq_length]   ,		self.num_labels )
               lowercase  :		List[str]						=      ids_tensor([self.batch_size]   ,		self.num_choices )

        lowercase  :		str						=      AlbertConfig(
            vocab_size=self.vocab_size   ,		hidden_size=self.hidden_size   ,		embedding_size=self.embedding_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   ,		)

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



 def    SCREAMING_SNAKE_CASE(  self   ,		A   ,		A   ,		A   ,		A   ,		A   ,		A   ,		A ):






        '''simple docstring'''




        lowercase  :		List[Any]						=      TFAlbertModel(config=A )
        # inputs = {'input_ids': input_ids,
        #           'attention_mask': input_mask,
        #           'token_type_ids': token_type_ids}
        # sequence_output, pooled_output = model(**inputs)
        lowercase  :		List[Any]						=      {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
        lowercase  :		Union[str, Any]						=      model(A )

        lowercase  :		Optional[Any]						=      [input_ids, input_mask]
        lowercase  :		Union[str, Any]						=      model(A )

        lowercase  :		Dict						=      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    SCREAMING_SNAKE_CASE(  self   ,		A   ,		A   ,		A   ,		A   ,		A   ,		A   ,		A ):






        '''simple docstring'''




        lowercase  :		Union[str, Any]						=      self.num_labels
        lowercase  :		Optional[int]						=      TFAlbertForPreTraining(config=A )
        lowercase  :		List[str]						=      {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
        lowercase  :		str						=      model(A )
        self.parent.assertEqual(result.prediction_logits.shape   ,		(self.batch_size, self.seq_length, self.vocab_size) )
        self.parent.assertEqual(result.sop_logits.shape   ,		(self.batch_size, self.num_labels) )



 def    SCREAMING_SNAKE_CASE(  self   ,		A   ,		A   ,		A   ,		A   ,		A   ,		A   ,		A ):






        '''simple docstring'''




        lowercase  :		List[Any]						=      TFAlbertForMaskedLM(config=A )
        lowercase  :		Any						=      {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
        lowercase  :		Dict						=      model(A )
        self.parent.assertEqual(result.logits.shape   ,		(self.batch_size, self.seq_length, self.vocab_size) )



 def    SCREAMING_SNAKE_CASE(  self   ,		A   ,		A   ,		A   ,		A   ,		A   ,		A   ,		A ):






        '''simple docstring'''




        lowercase  :		str						=      self.num_labels
        lowercase  :		str						=      TFAlbertForSequenceClassification(config=A )
        lowercase  :		List[str]						=      {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
        lowercase  :		Any						=      model(A )
        self.parent.assertEqual(result.logits.shape   ,		(self.batch_size, self.num_labels) )



 def    SCREAMING_SNAKE_CASE(  self   ,		A   ,		A   ,		A   ,		A   ,		A   ,		A   ,		A ):






        '''simple docstring'''




        lowercase  :		str						=      TFAlbertForQuestionAnswering(config=A )
        lowercase  :		Optional[int]						=      {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
        lowercase  :		Union[str, Any]						=      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    SCREAMING_SNAKE_CASE(  self   ,		A   ,		A   ,		A   ,		A   ,		A   ,		A   ,		A ):






        '''simple docstring'''




        lowercase  :		str						=      self.num_choices
        lowercase  :		Optional[Any]						=      TFAlbertForMultipleChoice(config=A )
        lowercase  :		Any						=      tf.tile(tf.expand_dims(A   ,		1 )   ,		(1, self.num_choices, 1) )
        lowercase  :		Union[str, Any]						=      tf.tile(tf.expand_dims(A   ,		1 )   ,		(1, self.num_choices, 1) )
        lowercase  :		Any						=      tf.tile(tf.expand_dims(A   ,		1 )   ,		(1, self.num_choices, 1) )
        lowercase  :		Optional[Any]						=      {
            '''input_ids''': multiple_choice_inputs_ids,
            '''attention_mask''': multiple_choice_input_mask,
            '''token_type_ids''': multiple_choice_token_type_ids,
        }
        lowercase  :		Union[str, Any]						=      model(A )
        self.parent.assertListEqual(list(result['''logits'''].shape )   ,		[self.batch_size, self.num_choices] )



 def    SCREAMING_SNAKE_CASE(  self   ,		A   ,		A   ,		A   ,		A   ,		A   ,		A   ,		A ):






        '''simple docstring'''




        lowercase  :		Union[str, Any]						=      self.num_labels
        lowercase  :		List[str]						=      TFAlbertForTokenClassification(config=A )
        lowercase  :		Dict						=      {
            '''input_ids''': input_ids,
            '''attention_mask''': input_mask,
            '''token_type_ids''': token_type_ids,
        }
        lowercase  :		Any						=      model(A )
        self.parent.assertListEqual(list(result['''logits'''].shape )   ,		[self.batch_size, self.seq_length, self.num_labels] )





 def    SCREAMING_SNAKE_CASE(  self ):






        '''simple docstring'''




        lowercase  :		List[Any]						=      self.prepare_config_and_inputs()
        (
            lowercase     
        )  :		Optional[int]						=      config_and_inputs
        lowercase  :		str						=      {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
        return config, inputs_dict






@require_tf
class   SCREAMING_SNAKE_CASE_		(       lowerCamelCase_		,     lowerCamelCase_		,     unittest.TestCase				):
 __snake_case	:     Optional[int]			   =      (
     (
         TFAlbertModel,
         TFAlbertForPreTraining,
         TFAlbertForMaskedLM,
         TFAlbertForSequenceClassification,
         TFAlbertForQuestionAnswering,
         TFAlbertForTokenClassification,
         TFAlbertForMultipleChoice,
     )
     if is_tf_available()
     else ()
 )
 __snake_case	:     Tuple			   =      (
     {
         "feature-extraction": TFAlbertModel,
         "fill-mask": TFAlbertForMaskedLM,
         "question-answering": TFAlbertForQuestionAnswering,
         "text-classification": TFAlbertForSequenceClassification,
         "token-classification": TFAlbertForTokenClassification,
         "zero-shot": TFAlbertForSequenceClassification,
     }
     if is_tf_available()
     else {}
 )
 __snake_case	:     List[str]			   =      False
 __snake_case	:     Dict			   =      False



 def    SCREAMING_SNAKE_CASE(  self   ,		A   ,		A   ,		A=False ):






        '''simple docstring'''




        lowercase  :		Any						=      super()._prepare_for_class(A   ,		A   ,		return_labels=A )

        if return_labels:
               if model_class in get_values(A ):
                      lowercase  :		int						=      tf.zeros(self.model_tester.batch_size   ,		dtype=tf.intaa )

        return inputs_dict



 def    SCREAMING_SNAKE_CASE(  self ):






        '''simple docstring'''




        lowercase  :		Optional[Any]						=      TFAlbertModelTester(self )
        lowercase  :		str						=      ConfigTester(self   ,		config_class=A   ,		hidden_size=37 )



 def    SCREAMING_SNAKE_CASE(  self ):






        '''simple docstring'''




        self.config_tester.run_common_tests()



 def    SCREAMING_SNAKE_CASE(  self ):






        '''simple docstring'''




        lowercase  :		str						=      self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_albert_model(*A )



 def    SCREAMING_SNAKE_CASE(  self ):






        '''simple docstring'''




        lowercase  :		Tuple						=      self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_albert_for_pretraining(*A )



 def    SCREAMING_SNAKE_CASE(  self ):






        '''simple docstring'''




        lowercase  :		Optional[int]						=      self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_albert_for_masked_lm(*A )



 def    SCREAMING_SNAKE_CASE(  self ):






        '''simple docstring'''




        lowercase  :		Dict						=      self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_albert_for_multiple_choice(*A )



 def    SCREAMING_SNAKE_CASE(  self ):






        '''simple docstring'''




        lowercase  :		int						=      self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_albert_for_sequence_classification(*A )



 def    SCREAMING_SNAKE_CASE(  self ):






        '''simple docstring'''




        lowercase  :		Union[str, Any]						=      self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_albert_for_question_answering(*A )





 @slow
 def    SCREAMING_SNAKE_CASE(  self ):






        '''simple docstring'''




        for model_name in TF_ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
               lowercase  :		Tuple						=      TFAlbertModel.from_pretrained(A )
               self.assertIsNotNone(A )






@require_tf
class   SCREAMING_SNAKE_CASE_		(       unittest.TestCase				):



 @slow
 def    SCREAMING_SNAKE_CASE(  self ):






        '''simple docstring'''




        lowercase  :		str						=      TFAlbertForPreTraining.from_pretrained('''albert-base-v2''' )
        lowercase  :		Optional[int]						=      tf.constant([[0, 1, 2, 3, 4, 5]] )
        lowercase  :		Any						=      model(A )[0]

        lowercase  :		List[Any]						=      [1, 6, 30000]
        self.assertEqual(output.shape   ,		A )

        lowercase  :		Optional[Any]						=      tf.constant(
            [
                [
                    [4.5_9_5_6_6_8, 0.7_4_4_6_2_7_5_4, -1.8_1_8_1_4_7],
                    [4.5_9_5_4_3_4_7, 0.7_4_5_4_1_8_4, -1.8_1_8_8_2_5_8],
                    [4.5_9_5_4_9_0_5, 0.7_4_4_8_2_3_5, -1.8_1_8_2_3_1_6],
                ]
            ] )
        tf.debugging.assert_near(output[:, :3, :3]   ,		A   ,		atol=1E-4 )










'''simple docstring'''






def 		a_( lowerCamelCase   ,				lowerCamelCase      )				->list[tuple[int, int, int]]:






       '''simple docstring'''




       lowercase  :		Dict						=      sorted(lowerCamelCase   ,				key=lambda lowerCamelCase      : edge[2]      )

       lowercase  :		str						=      list(range(lowerCamelCase      )      )

       def find_parent(lowerCamelCase      ):
              if i != parent[i]:
                     lowercase  :		Optional[int]						=      find_parent(parent[i]      )
              return parent[i]

       lowercase  :		Union[str, Any]						=      0
       lowercase  :		Any						=      []

       for edge in edges:
              lowercase  :		Optional[Any]						=      find_parent(edge[0]      )
              lowercase  :		Any						=      find_parent(edge[1]      )
              if parent_a != parent_b:
                     minimum_spanning_tree_cost += edge[2]
                     minimum_spanning_tree.append(lowerCamelCase      )
                     lowercase  :		Optional[int]						=      parent_b

       return minimum_spanning_tree


if __name__ == "__main__":  # pragma: no cover
      lowercase	,	lowercase	:      List[Any]				=       list(map(int, input().strip().split()))
      lowercase	:      List[Any]				=       []

      for _ in range(num_edges):
            lowercase	,	lowercase	,	lowercase	:      Optional[Any]				=       (int(x) for x in input().strip().split())
            edges.append((nodea, nodea, cost))

      kruskal(num_nodes, edges)




