


'''simple docstring'''





import unittest

from transformers import ElectraConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
    import torch

    from transformers import (
        MODEL_FOR_PRETRAINING_MAPPING,
        ElectraForCausalLM,
        ElectraForMaskedLM,
        ElectraForMultipleChoice,
        ElectraForPreTraining,
        ElectraForQuestionAnswering,
        ElectraForSequenceClassification,
        ElectraForTokenClassification,
        ElectraModel,
    )
    from transformers.models.electra.modeling_electra import ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST




class 							UpperCAmelCase :


 def __init__(			self       :  List[str] ,					__lowerCamelCase       :  List[str] ,					__lowerCamelCase       :  List[str]=1_3 ,					__lowerCamelCase       :  str=7 ,					__lowerCamelCase       :  Tuple=True ,					__lowerCamelCase       :  str=True ,					__lowerCamelCase       :  Any=True ,					__lowerCamelCase       :  Any=True ,					__lowerCamelCase       :  Dict=9_9 ,					__lowerCamelCase       :  Optional[int]=3_2 ,					__lowerCamelCase       :  Optional[Any]=5 ,					__lowerCamelCase       :  Dict=4 ,					__lowerCamelCase       :  int=3_7 ,					__lowerCamelCase       :  List[Any]="gelu" ,					__lowerCamelCase       :  Tuple=0.1 ,					__lowerCamelCase       :  Any=0.1 ,					__lowerCamelCase       :  Optional[int]=5_1_2 ,					__lowerCamelCase       :  Tuple=1_6 ,					__lowerCamelCase       :  List[str]=2 ,					__lowerCamelCase       :  Optional[int]=0.02 ,					__lowerCamelCase       :  int=3 ,					__lowerCamelCase       :  int=4 ,					__lowerCamelCase       :  Optional[int]=None ,					):
    UpperCAmelCase__  :Union[str, Any]            =			parent
    UpperCAmelCase__  :Optional[int]            =			batch_size
    UpperCAmelCase__  :Dict            =			seq_length
    UpperCAmelCase__  :Tuple            =			is_training
    UpperCAmelCase__  :Any            =			use_input_mask
    UpperCAmelCase__  :Tuple            =			use_token_type_ids
    UpperCAmelCase__  :str            =			use_labels
    UpperCAmelCase__  :Union[str, Any]            =			vocab_size
    UpperCAmelCase__  :Optional[Any]            =			hidden_size
    UpperCAmelCase__  :str            =			num_hidden_layers
    UpperCAmelCase__  :Optional[Any]            =			num_attention_heads
    UpperCAmelCase__  :Optional[Any]            =			intermediate_size
    UpperCAmelCase__  :Dict            =			hidden_act
    UpperCAmelCase__  :Optional[Any]            =			hidden_dropout_prob
    UpperCAmelCase__  :List[str]            =			attention_probs_dropout_prob
    UpperCAmelCase__  :List[str]            =			max_position_embeddings
    UpperCAmelCase__  :str            =			type_vocab_size
    UpperCAmelCase__  :List[str]            =			type_sequence_label_size
    UpperCAmelCase__  :int            =			initializer_range
    UpperCAmelCase__  :Optional[Any]            =			num_labels
    UpperCAmelCase__  :int            =			num_choices
    UpperCAmelCase__  :int            =			scope


 def 					__SCREAMING_SNAKE_CASE				(			self       :  Any   ):
    UpperCAmelCase__  :str            =			ids_tensor([self.batch_size, self.seq_length] ,					self.vocab_size   )

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

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

    UpperCAmelCase__  :List[str]            =			None
    UpperCAmelCase__  :Union[str, Any]            =			None
    UpperCAmelCase__  :Any            =			None
    if self.use_labels:
       UpperCAmelCase__  :Any            =			ids_tensor([self.batch_size] ,					self.type_sequence_label_size   )
       UpperCAmelCase__  :Optional[int]            =			ids_tensor([self.batch_size, self.seq_length] ,					self.num_labels   )
       UpperCAmelCase__  :Dict            =			ids_tensor([self.batch_size] ,					self.num_choices   )
       UpperCAmelCase__  :int            =			ids_tensor([self.batch_size, self.seq_length] ,					1   )

    UpperCAmelCase__  :Union[str, Any]            =			self.get_config()

    return (
        config,
        input_ids,
        token_type_ids,
        input_mask,
        sequence_labels,
        token_labels,
        choice_labels,
        fake_token_labels,
    )


 def 					__SCREAMING_SNAKE_CASE				(			self       :  Any   ):
    return ElectraConfig(
        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 ,					is_decoder=__lowerCamelCase ,					initializer_range=self.initializer_range ,					)


 def 					__SCREAMING_SNAKE_CASE				(			self       :  Dict   ):
    (
        (
        UpperCAmelCase__
    )      ,	(
        UpperCAmelCase__
    )      ,	(
        UpperCAmelCase__
    )      ,	(
        UpperCAmelCase__
    )      ,	(
        UpperCAmelCase__
    )      ,	(
        UpperCAmelCase__
    )      ,	(
        UpperCAmelCase__
    )      ,	(
        UpperCAmelCase__
    )      ,	
    )  :Dict            =			self.prepare_config_and_inputs()

    UpperCAmelCase__  :List[Any]            =			True
    UpperCAmelCase__  :Optional[int]            =			floats_tensor([self.batch_size, self.seq_length, self.hidden_size]   )
    UpperCAmelCase__  :Any            =			ids_tensor([self.batch_size, self.seq_length] ,					vocab_size=2   )

    return (
        config,
        input_ids,
        token_type_ids,
        input_mask,
        sequence_labels,
        token_labels,
        choice_labels,
        encoder_hidden_states,
        encoder_attention_mask,
    )


 def 					__SCREAMING_SNAKE_CASE				(			self       :  str ,					__lowerCamelCase       :  Union[str, Any] ,					__lowerCamelCase       :  List[str] ,					__lowerCamelCase       :  Optional[Any] ,					__lowerCamelCase       :  Optional[int] ,					__lowerCamelCase       :  Dict ,					__lowerCamelCase       :  List[str] ,					__lowerCamelCase       :  Optional[Any] ,					__lowerCamelCase       :  Dict ,					):
    UpperCAmelCase__  :List[Any]            =			ElectraModel(config=__lowerCamelCase   )
    model.to(__lowerCamelCase   )
    model.eval()
    UpperCAmelCase__  :List[str]            =			model(__lowerCamelCase ,					attention_mask=__lowerCamelCase ,					token_type_ids=__lowerCamelCase   )
    UpperCAmelCase__  :List[str]            =			model(__lowerCamelCase ,					token_type_ids=__lowerCamelCase   )
    UpperCAmelCase__  :Union[str, Any]            =			model(__lowerCamelCase   )
    self.parent.assertEqual(result.last_hidden_state.shape ,					(self.batch_size, self.seq_length, self.hidden_size)   )


 def 					__SCREAMING_SNAKE_CASE				(			self       :  Optional[int] ,					__lowerCamelCase       :  List[str] ,					__lowerCamelCase       :  Union[str, Any] ,					__lowerCamelCase       :  List[str] ,					__lowerCamelCase       :  List[str] ,					__lowerCamelCase       :  List[str] ,					__lowerCamelCase       :  Optional[Any] ,					__lowerCamelCase       :  List[str] ,					__lowerCamelCase       :  Optional[Any] ,					__lowerCamelCase       :  Union[str, Any] ,					):
    UpperCAmelCase__  :Any            =			True
    UpperCAmelCase__  :List[str]            =			ElectraModel(__lowerCamelCase   )
    model.to(__lowerCamelCase   )
    model.eval()
    UpperCAmelCase__  :Union[str, Any]            =			model(
        __lowerCamelCase ,					attention_mask=__lowerCamelCase ,					token_type_ids=__lowerCamelCase ,					encoder_hidden_states=__lowerCamelCase ,					encoder_attention_mask=__lowerCamelCase ,					)
    UpperCAmelCase__  :Optional[Any]            =			model(
        __lowerCamelCase ,					attention_mask=__lowerCamelCase ,					token_type_ids=__lowerCamelCase ,					encoder_hidden_states=__lowerCamelCase ,					)
    UpperCAmelCase__  :Optional[int]            =			model(__lowerCamelCase ,					attention_mask=__lowerCamelCase ,					token_type_ids=__lowerCamelCase   )
    self.parent.assertEqual(result.last_hidden_state.shape ,					(self.batch_size, self.seq_length, self.hidden_size)   )


 def 					__SCREAMING_SNAKE_CASE				(			self       :  int ,					__lowerCamelCase       :  List[str] ,					__lowerCamelCase       :  Optional[int] ,					__lowerCamelCase       :  int ,					__lowerCamelCase       :  Dict ,					__lowerCamelCase       :  List[str] ,					__lowerCamelCase       :  List[Any] ,					__lowerCamelCase       :  Dict ,					__lowerCamelCase       :  Union[str, Any] ,					):
    UpperCAmelCase__  :List[str]            =			ElectraForMaskedLM(config=__lowerCamelCase   )
    model.to(__lowerCamelCase   )
    model.eval()
    UpperCAmelCase__  :List[str]            =			model(__lowerCamelCase ,					attention_mask=__lowerCamelCase ,					token_type_ids=__lowerCamelCase ,					labels=__lowerCamelCase   )
    self.parent.assertEqual(result.logits.shape ,					(self.batch_size, self.seq_length, self.vocab_size)   )


 def 					__SCREAMING_SNAKE_CASE				(			self       :  Any ,					__lowerCamelCase       :  Dict ,					__lowerCamelCase       :  Union[str, Any] ,					__lowerCamelCase       :  Any ,					__lowerCamelCase       :  int ,					__lowerCamelCase       :  int ,					__lowerCamelCase       :  str ,					__lowerCamelCase       :  Optional[Any] ,					__lowerCamelCase       :  List[str] ,					__lowerCamelCase       :  Optional[int] ,					):
    UpperCAmelCase__  :Optional[Any]            =			ElectraForCausalLM(config=__lowerCamelCase   )
    model.to(__lowerCamelCase   )
    model.eval()
    UpperCAmelCase__  :List[Any]            =			model(__lowerCamelCase ,					attention_mask=__lowerCamelCase ,					token_type_ids=__lowerCamelCase ,					labels=__lowerCamelCase   )
    self.parent.assertEqual(result.logits.shape ,					(self.batch_size, self.seq_length, self.vocab_size)   )


 def 					__SCREAMING_SNAKE_CASE				(			self       :  int ,					__lowerCamelCase       :  str ,					__lowerCamelCase       :  Dict ,					__lowerCamelCase       :  Union[str, Any] ,					__lowerCamelCase       :  int ,					__lowerCamelCase       :  List[str] ,					__lowerCamelCase       :  List[str] ,					__lowerCamelCase       :  Any ,					__lowerCamelCase       :  Tuple ,					):
    UpperCAmelCase__  :str            =			self.num_labels
    UpperCAmelCase__  :Optional[Any]            =			ElectraForTokenClassification(config=__lowerCamelCase   )
    model.to(__lowerCamelCase   )
    model.eval()
    UpperCAmelCase__  :int            =			model(__lowerCamelCase ,					attention_mask=__lowerCamelCase ,					token_type_ids=__lowerCamelCase ,					labels=__lowerCamelCase   )
    self.parent.assertEqual(result.logits.shape ,					(self.batch_size, self.seq_length, self.num_labels)   )


 def 					__SCREAMING_SNAKE_CASE				(			self       :  Optional[int] ,					__lowerCamelCase       :  List[str] ,					__lowerCamelCase       :  Optional[int] ,					__lowerCamelCase       :  Optional[Any] ,					__lowerCamelCase       :  str ,					__lowerCamelCase       :  Tuple ,					__lowerCamelCase       :  str ,					__lowerCamelCase       :  Tuple ,					__lowerCamelCase       :  Optional[Any] ,					):
    UpperCAmelCase__  :List[Any]            =			self.num_labels
    UpperCAmelCase__  :str            =			ElectraForPreTraining(config=__lowerCamelCase   )
    model.to(__lowerCamelCase   )
    model.eval()
    UpperCAmelCase__  :str            =			model(__lowerCamelCase ,					attention_mask=__lowerCamelCase ,					token_type_ids=__lowerCamelCase ,					labels=__lowerCamelCase   )
    self.parent.assertEqual(result.logits.shape ,					(self.batch_size, self.seq_length)   )


 def 					__SCREAMING_SNAKE_CASE				(			self       :  Dict ,					__lowerCamelCase       :  Optional[int] ,					__lowerCamelCase       :  int ,					__lowerCamelCase       :  str ,					__lowerCamelCase       :  Union[str, Any] ,					__lowerCamelCase       :  Optional[Any] ,					__lowerCamelCase       :  Any ,					__lowerCamelCase       :  int ,					__lowerCamelCase       :  Tuple ,					):
    UpperCAmelCase__  :List[str]            =			self.num_labels
    UpperCAmelCase__  :int            =			ElectraForSequenceClassification(__lowerCamelCase   )
    model.to(__lowerCamelCase   )
    model.eval()
    UpperCAmelCase__  :Dict            =			model(__lowerCamelCase ,					attention_mask=__lowerCamelCase ,					token_type_ids=__lowerCamelCase ,					labels=__lowerCamelCase   )
    self.parent.assertEqual(result.logits.shape ,					(self.batch_size, self.num_labels)   )


 def 					__SCREAMING_SNAKE_CASE				(			self       :  Any ,					__lowerCamelCase       :  Dict ,					__lowerCamelCase       :  Union[str, Any] ,					__lowerCamelCase       :  str ,					__lowerCamelCase       :  List[Any] ,					__lowerCamelCase       :  Optional[int] ,					__lowerCamelCase       :  List[Any] ,					__lowerCamelCase       :  Optional[int] ,					__lowerCamelCase       :  Union[str, Any] ,					):
    UpperCAmelCase__  :List[str]            =			ElectraForQuestionAnswering(config=__lowerCamelCase   )
    model.to(__lowerCamelCase   )
    model.eval()
    UpperCAmelCase__  :Optional[Any]            =			model(
        __lowerCamelCase ,					attention_mask=__lowerCamelCase ,					token_type_ids=__lowerCamelCase ,					start_positions=__lowerCamelCase ,					end_positions=__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 					__SCREAMING_SNAKE_CASE				(			self       :  List[str] ,					__lowerCamelCase       :  Optional[int] ,					__lowerCamelCase       :  Dict ,					__lowerCamelCase       :  Optional[Any] ,					__lowerCamelCase       :  Optional[Any] ,					__lowerCamelCase       :  List[Any] ,					__lowerCamelCase       :  List[str] ,					__lowerCamelCase       :  List[Any] ,					__lowerCamelCase       :  Union[str, Any] ,					):
    UpperCAmelCase__  :Any            =			self.num_choices
    UpperCAmelCase__  :int            =			ElectraForMultipleChoice(config=__lowerCamelCase   )
    model.to(__lowerCamelCase   )
    model.eval()
    UpperCAmelCase__  :Dict            =			input_ids.unsqueeze(1   ).expand(-1 ,					self.num_choices ,					-1   ).contiguous()
    UpperCAmelCase__  :Dict            =			token_type_ids.unsqueeze(1   ).expand(-1 ,					self.num_choices ,					-1   ).contiguous()
    UpperCAmelCase__  :Union[str, Any]            =			input_mask.unsqueeze(1   ).expand(-1 ,					self.num_choices ,					-1   ).contiguous()
    UpperCAmelCase__  :int            =			model(
        __lowerCamelCase ,					attention_mask=__lowerCamelCase ,					token_type_ids=__lowerCamelCase ,					labels=__lowerCamelCase ,					)
    self.parent.assertEqual(result.logits.shape ,					(self.batch_size, self.num_choices)   )





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




@require_torch
class 							UpperCAmelCase ( _snake_case	,   _snake_case	,   unittest.TestCase	):
 UpperCAmelCase				=				(
     (
         ElectraModel,
         ElectraForPreTraining,
         ElectraForMaskedLM,
         ElectraForCausalLM,
         ElectraForMultipleChoice,
         ElectraForTokenClassification,
         ElectraForSequenceClassification,
         ElectraForQuestionAnswering,
     )
     if is_torch_available()
     else ()
 )
 UpperCAmelCase				=				(
     {
         "feature-extraction": ElectraModel,
         "fill-mask": ElectraForMaskedLM,
         "question-answering": ElectraForQuestionAnswering,
         "text-classification": ElectraForSequenceClassification,
         "text-generation": ElectraForCausalLM,
         "token-classification": ElectraForTokenClassification,
         "zero-shot": ElectraForSequenceClassification,
     }
     if is_torch_available()
     else {}
 )
 UpperCAmelCase				=				True


 def 					__SCREAMING_SNAKE_CASE				(			self       :  str ,					__lowerCamelCase       :  Optional[int] ,					__lowerCamelCase       :  Optional[int] ,					__lowerCamelCase       :  List[str]=False   ):
    UpperCAmelCase__  :Dict            =			super()._prepare_for_class(__lowerCamelCase ,					__lowerCamelCase ,					return_labels=__lowerCamelCase   )

    if return_labels:
       if model_class in get_values(__lowerCamelCase   ):
          UpperCAmelCase__  :List[str]            =			torch.zeros(
              (self.model_tester.batch_size, self.model_tester.seq_length) ,					dtype=torch.long ,					device=__lowerCamelCase   )
    return inputs_dict


 def 					__SCREAMING_SNAKE_CASE				(			self       :  Any   ):
    UpperCAmelCase__  :List[Any]            =			ElectraModelTester(self   )
    UpperCAmelCase__  :Union[str, Any]            =			ConfigTester(self ,					config_class=__lowerCamelCase ,					hidden_size=3_7   )


 def 					__SCREAMING_SNAKE_CASE				(			self       :  Optional[Any]   ):
    self.config_tester.run_common_tests()


 def 					__SCREAMING_SNAKE_CASE				(			self       :  str   ):
    UpperCAmelCase__  :Any            =			self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_electra_model(*__lowerCamelCase   )


 def 					__SCREAMING_SNAKE_CASE				(			self       :  List[Any]   ):
    UpperCAmelCase__  :Any            =			self.model_tester.prepare_config_and_inputs_for_decoder()
    self.model_tester.create_and_check_electra_model_as_decoder(*__lowerCamelCase   )


 def 					__SCREAMING_SNAKE_CASE				(			self       :  Any   ):
    UpperCAmelCase__  :str            =			self.model_tester.prepare_config_and_inputs()
    for type in ["absolute", "relative_key", "relative_key_query"]:
       UpperCAmelCase__  :Union[str, Any]            =			type
       self.model_tester.create_and_check_electra_model(*__lowerCamelCase   )


 def 					__SCREAMING_SNAKE_CASE				(			self       :  Union[str, Any]   ):
    UpperCAmelCase__  :Any            =			self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_electra_for_masked_lm(*__lowerCamelCase   )


 def 					__SCREAMING_SNAKE_CASE				(			self       :  List[str]   ):
    UpperCAmelCase__  :str            =			self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_electra_for_token_classification(*__lowerCamelCase   )


 def 					__SCREAMING_SNAKE_CASE				(			self       :  Union[str, Any]   ):
    UpperCAmelCase__  :Optional[int]            =			self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_electra_for_pretraining(*__lowerCamelCase   )


 def 					__SCREAMING_SNAKE_CASE				(			self       :  List[Any]   ):
    UpperCAmelCase__  :str            =			self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_electra_for_sequence_classification(*__lowerCamelCase   )


 def 					__SCREAMING_SNAKE_CASE				(			self       :  Tuple   ):
    UpperCAmelCase__  :Dict            =			self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_electra_for_question_answering(*__lowerCamelCase   )


 def 					__SCREAMING_SNAKE_CASE				(			self       :  Optional[Any]   ):
    UpperCAmelCase__  :List[str]            =			self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_electra_for_multiple_choice(*__lowerCamelCase   )


 @slow
 def 					__SCREAMING_SNAKE_CASE				(			self       :  Union[str, Any]   ):
    for model_name in ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
       UpperCAmelCase__  :int            =			ElectraModel.from_pretrained(__lowerCamelCase   )
       self.assertIsNotNone(__lowerCamelCase   )





 def 					__SCREAMING_SNAKE_CASE				(			self       :  Union[str, Any]   ):
    UpperCAmelCase__  :Optional[Any]            =			self.model_tester.prepare_config_and_inputs_for_decoder()
    self.model_tester.create_and_check_electra_for_causal_lm(*__lowerCamelCase   )




@require_torch
class 							UpperCAmelCase ( unittest.TestCase	):


 @slow
 def 					__SCREAMING_SNAKE_CASE				(			self       :  int   ):
    UpperCAmelCase__  :int            =			ElectraModel.from_pretrained('''google/electra-small-discriminator'''   )
    UpperCAmelCase__  :int            =			torch.tensor([[0, 3_4_5, 2_3_2, 3_2_8, 7_4_0, 1_4_0, 1_6_9_5, 6_9, 6_0_7_8, 1_5_8_8, 2]]   )
    UpperCAmelCase__  :List[str]            =			torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]   )
    UpperCAmelCase__  :List[Any]            =			model(__lowerCamelCase ,					attention_mask=__lowerCamelCase   )[0]
    UpperCAmelCase__  :Tuple            =			torch.Size((1, 1_1, 2_5_6)   )
    self.assertEqual(output.shape ,					__lowerCamelCase   )
    UpperCAmelCase__  :Optional[Any]            =			torch.tensor(
        [[[0.44_71, 0.68_21, -0.32_65], [0.46_27, 0.52_55, -0.36_68], [0.45_32, 0.33_13, -0.43_44]]]   )

    self.assertTrue(torch.allclose(output[:, 1:4, 1:4] ,					__lowerCamelCase ,					atol=1e-4   )   )







'''simple docstring'''





__lowerCamelCase       				=	[
    ['''ab-e1''', '''ac-e3''', '''ad-e5''', '''bc-e4''', '''bd-e2''', '''be-e6''', '''bh-e12''', '''cd-e2''', '''ce-e4''',
     '''de-e1''', '''df-e8''', '''dg-e5''', '''dh-e10''', '''ef-e3''', '''eg-e2''', '''fg-e6''', '''gh-e6''', '''hi-e3'''],
    ['''ab-e1''', '''ac-e3''', '''ad-e5''', '''bc-e4''', '''bd-e2''', '''be-e6''', '''cd-e2''', '''de-e1''', '''df-e8''',
     '''ef-e3''', '''eg-e2''', '''fg-e6'''],
    ['''ab-e1''', '''ac-e3''', '''bc-e4''', '''bd-e2''', '''de-e1''', '''df-e8''', '''dg-e5''', '''ef-e3''', '''eg-e2''',
     '''eh-e12''', '''fg-e6''', '''fh-e10''', '''gh-e6'''],
    ['''ab-e1''', '''ac-e3''', '''bc-e4''', '''bd-e2''', '''bh-e12''', '''cd-e2''', '''df-e8''', '''dh-e10'''],
    ['''ab-e1''', '''ac-e3''', '''ad-e5''', '''bc-e4''', '''bd-e2''', '''cd-e2''', '''ce-e4''', '''de-e1''', '''df-e8''',
     '''dg-e5''', '''ef-e3''', '''eg-e2''', '''fg-e6''']
]


def 					a__    (				UpperCamelCase_	:			List[str]	):
   UpperCAmelCase__  :str            =			set()
   for row in edge_array:
      for item in row:
         distinct_edge.add(item[0]	)
   return list(UpperCamelCase_	)


def 					a__    (				UpperCamelCase_	:			Tuple,      UpperCamelCase_	:			List[Any]	):
   UpperCAmelCase__  :int            =			['''0'''] * len(UpperCamelCase_	)
   for i, row in enumerate(UpperCamelCase_	):
      for item in row:
         if distinct_edge in item[0]:
            UpperCAmelCase__  :List[Any]            =			'''1'''
            break
   return "".join(UpperCamelCase_	)


def 					a__    (				UpperCamelCase_	:			Optional[int]	):
   UpperCAmelCase__  :Any            =			get_distinct_edge(UpperCamelCase_	)
   UpperCAmelCase__  :Dict            =			{}

   for item in distinct_edge:
      UpperCAmelCase__  :List[str]            =			get_bitcode(UpperCamelCase_,      UpperCamelCase_	)
      # print('bit',bit)
      # bt=''.join(bit)
      UpperCAmelCase__  :int            =			bit.count('''1'''	)
      UpperCAmelCase__  :Tuple            =			[s, bit]
   # Store [Distinct edge, WT(Bitcode), Bitcode] in descending order
   UpperCAmelCase__  :str            =			[
       [k, v[0], v[1]]
       for k, v in sorted(frequency_table.items(),      key=lambda UpperCamelCase_	: v[1][0],      reverse=UpperCamelCase_	)
   ]
   return sorted_frequency_table


def 					a__    (				UpperCamelCase_	:			Optional[int]	):
   UpperCAmelCase__  :int            =			{}
   for _, item in enumerate(UpperCamelCase_	):
      nodes.setdefault(item[2],      []	).append(item[0]	)
   return nodes


def 					a__    (				UpperCamelCase_	:			Any	):
   UpperCAmelCase__  :Any            =			{}
   for key, value in nodes.items():
      UpperCAmelCase__  :Optional[int]            =			value
   return cluster


def 					a__    (				UpperCamelCase_	:			Tuple	):
   return [i * 100 / len(UpperCamelCase_	) for i in cluster]


def 					a__    (				):
   print('''\nNodes\n'''	)
   for key, value in nodes.items():
      print(UpperCamelCase_,      UpperCamelCase_	)
   print('''\nSupport\n'''	)
   print(UpperCamelCase_	)
   print('''\n Cluster \n'''	)
   for key, value in sorted(cluster.items(),      reverse=UpperCamelCase_	):
      print(UpperCamelCase_,      UpperCamelCase_	)
   print('''\n Graph\n'''	)
   for key, value in graph.items():
      print(UpperCamelCase_,      UpperCamelCase_	)
   print('''\n Edge List of Frequent subgraphs \n'''	)
   for edge_list in freq_subgraph_edge_list:
      print(UpperCamelCase_	)


def 					a__    (				UpperCamelCase_	:			Optional[int],      UpperCamelCase_	:			Any,      UpperCamelCase_	:			int,      UpperCamelCase_	:			Dict	):
   for i in cluster[ca]:
      UpperCAmelCase__  :int            =			0
      UpperCAmelCase__  :int            =			ca + 1
      while ca < max(cluster.keys()	):
         for j in cluster[ca]:
            if int(UpperCamelCase_,      2	) & int(UpperCamelCase_,      2	) == int(UpperCamelCase_,      2	):
               if tuple(nodes[i]	) in graph:
                  graph[tuple(nodes[i]	)].append(nodes[j]	)
               else:
                  UpperCAmelCase__  :int            =			[nodes[j]]
               count += 1
         if count == 0:
            UpperCAmelCase__  :List[Any]            =			ca + 1
         else:
            break


def 					a__    (				UpperCamelCase_	:			Optional[int],      UpperCamelCase_	:			List[str]	):
   UpperCAmelCase__  :List[Any]            =			cluster[max(cluster.keys()	)]
   UpperCAmelCase__  :Union[str, Any]            =			'''Header'''
   UpperCAmelCase__  :Optional[int]            =			{}
   for i in x:
      if (["Header"],) in graph:
         graph[(["Header"],)].append(x[i]	)
      else:
         UpperCAmelCase__  :Tuple            =			[x[i]]
   for i in x:
      UpperCAmelCase__  :Dict            =			[['''Header''']]
   UpperCAmelCase__  :Any            =			1
   while i < max(UpperCamelCase_	) - 1:
      create_edge(UpperCamelCase_,      UpperCamelCase_,      UpperCamelCase_,      UpperCamelCase_	)
      UpperCAmelCase__  :Union[str, Any]            =			i + 1
   return graph


def 					a__    (				UpperCamelCase_	:			Optional[Any],      UpperCamelCase_	:			int,      UpperCamelCase_	:			Any,      UpperCamelCase_	:			Dict=None	):
   UpperCAmelCase__  :Tuple            =			(path or []) + [start]
   if start == end:
      paths.append(UpperCamelCase_	)
   for node in graph[start]:
      if tuple(UpperCamelCase_	) not in path:
         my_dfs(UpperCamelCase_,      tuple(UpperCamelCase_	),      UpperCamelCase_,      UpperCamelCase_	)


def 					a__    (				UpperCamelCase_	:			Dict,      UpperCamelCase_	:			int,      UpperCamelCase_	:			List[Any]	):
   UpperCAmelCase__  :List[str]            =			int(s / 100 * (len(UpperCamelCase_	) - 1)	)
   for i in cluster[k]:
      my_dfs(UpperCamelCase_,      tuple(cluster[k][i]	),      (['''Header'''],)	)


def 					a__    (				UpperCamelCase_	:			List[Any]	):
   UpperCAmelCase__  :int            =			[]
   for edges in paths:
      UpperCAmelCase__  :List[Any]            =			[]
      for j in range(len(UpperCamelCase_	) - 1	):
         UpperCAmelCase__  :Any            =			list(edges[j]	)
         for e in temp:
            UpperCAmelCase__  :str            =			(e[0], e[1])
            el.append(UpperCamelCase_	)
      freq_sub_el.append(UpperCamelCase_	)
   return freq_sub_el


def 					a__    (				UpperCamelCase_	:			Dict	):
   for i in range(len(UpperCamelCase_	)	):
      for j in range(len(edge_array[i]	)	):
         UpperCAmelCase__  :Dict            =			edge_array[i][j].split('''-'''	)
         UpperCAmelCase__  :Optional[Any]            =			t


if __name__ == "__main__":
    preprocess(edge_array)
    __lowerCamelCase       				=	get_frequency_table(edge_array)
    __lowerCamelCase       				=	get_nodes(frequency_table)
    __lowerCamelCase       				=	get_cluster(nodes)
    __lowerCamelCase       				=	get_support(cluster)
    __lowerCamelCase       				=	construct_graph(cluster, nodes)
    find_freq_subgraph_given_support(60, cluster, graph)
    __lowerCamelCase       				=	[]
    __lowerCamelCase       				=	freq_subgraphs_edge_list(paths)
    print_all()



