


'''simple docstring'''






import unittest

from transformers import ErnieMConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

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


if is_torch_available():
 import torch

 from transformers import (
     ErnieMForInformationExtraction,
     ErnieMForMultipleChoice,
     ErnieMForQuestionAnswering,
     ErnieMForSequenceClassification,
     ErnieMForTokenClassification,
     ErnieMModel,
 )
 from transformers.models.ernie_m.modeling_ernie_m import ERNIE_M_PRETRAINED_MODEL_ARCHIVE_LIST




class 			a  :
 def __init__(			self   ,					__magic_name__   ,					__magic_name__=13   ,					__magic_name__=7   ,					__magic_name__=True   ,					__magic_name__=True   ,					__magic_name__=True   ,					__magic_name__=99   ,					__magic_name__=32   ,					__magic_name__=5   ,					__magic_name__=4   ,					__magic_name__=37   ,					__magic_name__="gelu"   ,					__magic_name__=0.1   ,					__magic_name__=0.1   ,					__magic_name__=5_12   ,					__magic_name__=16   ,					__magic_name__=2   ,					__magic_name__=0.0_2   ,					__magic_name__=3   ,					__magic_name__=4   ,					__magic_name__=None   ,					)       ->				Any:
      _a         =				parent
      _a         =				batch_size
      _a         =				seq_length
      _a         =				is_training
      _a         =				use_input_mask
      _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
 def 				__UpperCAmelCase		(			self    )       ->				List[Any]:
      _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
      _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         =				self.get_config()

      return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels
 def 				__UpperCAmelCase		(			self    )       ->				Dict:
      _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         =				self.get_config()

      return config, input_ids, input_mask
 def 				__UpperCAmelCase		(			self    )       ->				Tuple:
      return ErnieMConfig(
          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   ,					)
 def 				__UpperCAmelCase		(			self   ,					__magic_name__   ,					__magic_name__   ,					__magic_name__   ,					__magic_name__   ,					__magic_name__   ,					__magic_name__    )       ->				Optional[Any]:
      _a         =				ErnieMModel(config=__SCREAMING_SNAKE_CASE    )
      model.to(__SCREAMING_SNAKE_CASE    )
      model.eval()
      _a         =				model(__SCREAMING_SNAKE_CASE   ,					return_dict=__SCREAMING_SNAKE_CASE    )
      self.parent.assertEqual(result.last_hidden_state.shape   ,					(self.batch_size, self.seq_length, self.hidden_size)    )
 def 				__UpperCAmelCase		(			self   ,					__magic_name__   ,					__magic_name__   ,					__magic_name__   ,					__magic_name__   ,					__magic_name__   ,					__magic_name__    )       ->				str:
      _a         =				ErnieMForQuestionAnswering(config=__SCREAMING_SNAKE_CASE    )
      model.to(__SCREAMING_SNAKE_CASE    )
      model.eval()
      _a         =				model(
          __SCREAMING_SNAKE_CASE   ,					attention_mask=__SCREAMING_SNAKE_CASE   ,					start_positions=__SCREAMING_SNAKE_CASE   ,					end_positions=__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 				__UpperCAmelCase		(			self   ,					__magic_name__   ,					__magic_name__   ,					__magic_name__   ,					__magic_name__   ,					__magic_name__   ,					__magic_name__    )       ->				Tuple:
      _a         =				ErnieMForInformationExtraction(config=__SCREAMING_SNAKE_CASE    )
      model.to(__SCREAMING_SNAKE_CASE    )
      model.eval()
      _a         =				torch.ones_like(__SCREAMING_SNAKE_CASE   ,					dtype=torch.floataa    )
      _a         =				model(
          __SCREAMING_SNAKE_CASE   ,					attention_mask=__SCREAMING_SNAKE_CASE   ,					start_positions=__SCREAMING_SNAKE_CASE   ,					end_positions=__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 				__UpperCAmelCase		(			self   ,					__magic_name__   ,					__magic_name__   ,					__magic_name__   ,					__magic_name__   ,					__magic_name__   ,					__magic_name__    )       ->				List[Any]:
      _a         =				self.num_labels
      _a         =				ErnieMForSequenceClassification(__SCREAMING_SNAKE_CASE    )
      model.to(__SCREAMING_SNAKE_CASE    )
      model.eval()
      _a         =				model(__SCREAMING_SNAKE_CASE   ,					attention_mask=__SCREAMING_SNAKE_CASE   ,					labels=__SCREAMING_SNAKE_CASE    )
      self.parent.assertEqual(result.logits.shape   ,					(self.batch_size, self.num_labels)    )
 def 				__UpperCAmelCase		(			self   ,					__magic_name__   ,					__magic_name__   ,					__magic_name__   ,					__magic_name__   ,					__magic_name__   ,					__magic_name__    )       ->				str:
      _a         =				self.num_labels
      _a         =				ErnieMForTokenClassification(config=__SCREAMING_SNAKE_CASE    )
      model.to(__SCREAMING_SNAKE_CASE    )
      model.eval()
      input_ids.to(__SCREAMING_SNAKE_CASE    )
      input_mask.to(__SCREAMING_SNAKE_CASE    )
      token_labels.to(__SCREAMING_SNAKE_CASE    )

      _a         =				model(__SCREAMING_SNAKE_CASE   ,					attention_mask=__SCREAMING_SNAKE_CASE   ,					labels=__SCREAMING_SNAKE_CASE    )

      self.parent.assertEqual(result.logits.shape   ,					(self.batch_size, self.seq_length, self.num_labels)    )
 def 				__UpperCAmelCase		(			self   ,					__magic_name__   ,					__magic_name__   ,					__magic_name__   ,					__magic_name__   ,					__magic_name__   ,					__magic_name__    )       ->				List[str]:
      _a         =				self.num_choices
      _a         =				ErnieMForMultipleChoice(config=__SCREAMING_SNAKE_CASE    )
      model.to(__SCREAMING_SNAKE_CASE    )
      model.eval()
      _a         =				input_ids.unsqueeze(1    ).expand(-1   ,					self.num_choices   ,					-1    ).contiguous()
      _a         =				input_mask.unsqueeze(1    ).expand(-1   ,					self.num_choices   ,					-1    ).contiguous()
      _a         =				model(
          __SCREAMING_SNAKE_CASE   ,					attention_mask=__SCREAMING_SNAKE_CASE   ,					labels=__SCREAMING_SNAKE_CASE   ,					)
      self.parent.assertEqual(result.logits.shape   ,					(self.batch_size, self.num_choices)    )




 def 				__UpperCAmelCase		(			self    )       ->				int:
      _a         =				self.prepare_config_and_inputs()
      (
          (
          _a 
      )   , (
          _a 
      )   , (
          _a 
      )   , (
          _a 
      )   , (
          _a 
      )   , (
          _a 
      )   ,  
      )         =				config_and_inputs
      _a         =				{'input_ids': input_ids, 'attention_mask': input_mask}
      return config, inputs_dict





@require_torch
class 			a  (  __lowerCAmelCase	,					__lowerCAmelCase	,					unittest.TestCase							):
 _lowerCAmelCase			       =						(
     (
         ErnieMModel,
         ErnieMForMultipleChoice,
         ErnieMForQuestionAnswering,
         ErnieMForSequenceClassification,
         ErnieMForTokenClassification,
     )
     if is_torch_available()
     else ()
 )
 _lowerCAmelCase			       =						()
 _lowerCAmelCase			       =						(
     {
         """feature-extraction""": ErnieMModel,
         """question-answering""": ErnieMForQuestionAnswering,
         """text-classification""": ErnieMForSequenceClassification,
         """token-classification""": ErnieMForTokenClassification,
         """zero-shot""": ErnieMForSequenceClassification,
     }
     if is_torch_available()
     else {}
 )
 _lowerCAmelCase			       =						False
 def 				__UpperCAmelCase		(			self   ,					__magic_name__   ,					__magic_name__   ,					__magic_name__   ,					__magic_name__   ,					__magic_name__    )       ->				Tuple:

      if pipeline_test_casse_name == "QAPipelineTests":
           return True

      return False
 def 				__UpperCAmelCase		(			self    )       ->				Dict:
      _a         =				ErnieMModelTester(self    )
      _a         =				ConfigTester(self   ,					config_class=__SCREAMING_SNAKE_CASE   ,					hidden_size=37    )
 def 				__UpperCAmelCase		(			self    )       ->				Tuple:
      self.config_tester.run_common_tests()
 def 				__UpperCAmelCase		(			self    )       ->				Dict:
      _a         =				self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_model(*__SCREAMING_SNAKE_CASE    )
 def 				__UpperCAmelCase		(			self    )       ->				Dict:
      _a         =				self.model_tester.prepare_config_and_inputs()
      for type in ["absolute", "relative_key", "relative_key_query"]:
           _a         =				type
           self.model_tester.create_and_check_model(*__SCREAMING_SNAKE_CASE    )
 def 				__UpperCAmelCase		(			self    )       ->				Any:
      _a         =				self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_multiple_choice(*__SCREAMING_SNAKE_CASE    )
 def 				__UpperCAmelCase		(			self    )       ->				Any:
      _a         =				self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_question_answering(*__SCREAMING_SNAKE_CASE    )
 def 				__UpperCAmelCase		(			self    )       ->				Optional[Any]:
      _a         =				self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_sequence_classification(*__SCREAMING_SNAKE_CASE    )
 def 				__UpperCAmelCase		(			self    )       ->				Tuple:
      _a         =				self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_information_extraction(*__SCREAMING_SNAKE_CASE    )
 def 				__UpperCAmelCase		(			self    )       ->				Optional[Any]:
      _a         =				self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_token_classification(*__SCREAMING_SNAKE_CASE    )




 @slow
 def 				__UpperCAmelCase		(			self    )       ->				int:

      for model_name in ERNIE_M_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
           _a         =				ErnieMModel.from_pretrained(__SCREAMING_SNAKE_CASE    )
           self.assertIsNotNone(__SCREAMING_SNAKE_CASE    )





@require_torch
class 			a  (  unittest.TestCase							):
 @slow
 def 				__UpperCAmelCase		(			self    )       ->				Dict:
      _a         =				ErnieMModel.from_pretrained('susnato/ernie-m-base_pytorch'    )
      model.eval()
      _a         =				torch.tensor([[0, 1, 2, 3, 4, 5]]    )
      _a         =				model(__SCREAMING_SNAKE_CASE    )[0]

      # TODO Replace vocab size
      _a         =				7_68

      _a         =				torch.Size((1, 6, hidden_size)    )
      self.assertEqual(output.shape   ,					__SCREAMING_SNAKE_CASE    )

      _a         =				torch.tensor(
          [[[-0.0_0_1_2, 0.1_2_4_5, -0.0_2_1_4], [-0.0_7_4_2, 0.0_2_4_4, -0.0_7_7_1], [-0.0_3_3_3, 0.1_1_6_4, -0.1_5_5_4]]]    )

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








"""simple docstring"""


a__       :  Optional[Any]       		=					{
    """A""": ("""ABCDEFGHIJKLM""", """NOPQRSTUVWXYZ"""),
    """B""": ("""ABCDEFGHIJKLM""", """NOPQRSTUVWXYZ"""),
    """C""": ("""ABCDEFGHIJKLM""", """ZNOPQRSTUVWXY"""),
    """D""": ("""ABCDEFGHIJKLM""", """ZNOPQRSTUVWXY"""),
    """E""": ("""ABCDEFGHIJKLM""", """YZNOPQRSTUVWX"""),
    """F""": ("""ABCDEFGHIJKLM""", """YZNOPQRSTUVWX"""),
    """G""": ("""ABCDEFGHIJKLM""", """XYZNOPQRSTUVW"""),
    """H""": ("""ABCDEFGHIJKLM""", """XYZNOPQRSTUVW"""),
    """I""": ("""ABCDEFGHIJKLM""", """WXYZNOPQRSTUV"""),
    """J""": ("""ABCDEFGHIJKLM""", """WXYZNOPQRSTUV"""),
    """K""": ("""ABCDEFGHIJKLM""", """VWXYZNOPQRSTU"""),
    """L""": ("""ABCDEFGHIJKLM""", """VWXYZNOPQRSTU"""),
    """M""": ("""ABCDEFGHIJKLM""", """UVWXYZNOPQRST"""),
    """N""": ("""ABCDEFGHIJKLM""", """UVWXYZNOPQRST"""),
    """O""": ("""ABCDEFGHIJKLM""", """TUVWXYZNOPQRS"""),
    """P""": ("""ABCDEFGHIJKLM""", """TUVWXYZNOPQRS"""),
    """Q""": ("""ABCDEFGHIJKLM""", """STUVWXYZNOPQR"""),
    """R""": ("""ABCDEFGHIJKLM""", """STUVWXYZNOPQR"""),
    """S""": ("""ABCDEFGHIJKLM""", """RSTUVWXYZNOPQ"""),
    """T""": ("""ABCDEFGHIJKLM""", """RSTUVWXYZNOPQ"""),
    """U""": ("""ABCDEFGHIJKLM""", """QRSTUVWXYZNOP"""),
    """V""": ("""ABCDEFGHIJKLM""", """QRSTUVWXYZNOP"""),
    """W""": ("""ABCDEFGHIJKLM""", """PQRSTUVWXYZNO"""),
    """X""": ("""ABCDEFGHIJKLM""", """PQRSTUVWXYZNO"""),
    """Y""": ("""ABCDEFGHIJKLM""", """OPQRSTUVWXYZN"""),
    """Z""": ("""ABCDEFGHIJKLM""", """OPQRSTUVWXYZN"""),
}





def 				a__      (	_UpperCAmelCase						)     ->	list[tuple[str, str]]:

 '''simple docstring'''






 return [alphabet[char] for char in key.upper()]





def 				a__      (	_UpperCAmelCase						,  _UpperCAmelCase						)     ->	str:

 '''simple docstring'''






 snake_case__     				=					""
 snake_case__     				=					0
 snake_case__     				=					generate_table(_UpperCAmelCase						)
 for char in words.upper():
  cipher += get_opponent(table[count]						,  _UpperCAmelCase						)
  snake_case__     				=					(count + 1) % len(_UpperCAmelCase						)
 return cipher





def 				a__      (	_UpperCAmelCase						,  _UpperCAmelCase						)     ->	str:

 '''simple docstring'''






 return encrypt(_UpperCAmelCase						,  _UpperCAmelCase						)





def 				a__      (	_UpperCAmelCase						,  _UpperCAmelCase						)     ->	tuple[int, int]:

 '''simple docstring'''






 snake_case__     				=					0 if char in table[0] else 1
 snake_case__     				=					table[row].index(_UpperCAmelCase						)
 return row, col





def 				a__      (	_UpperCAmelCase						,  _UpperCAmelCase						)     ->	str:

 '''simple docstring'''






 snake_case__				, snake_case__     				=					get_position(_UpperCAmelCase						,  char.upper()						)
 if row == 1:
  return table[0][col]
 else:
  return table[1][col] if row == 0 else char


if __name__ == "__main__":
   import doctest

   doctest.testmod()  # Fist ensure that all our tests are passing...
   a__       :  int       		=					input("""Enter key: """).strip()
   a__       :  Optional[int]       		=					input("""Enter text to encrypt: """).strip()
   a__       :  Dict       		=					encrypt(key, text)

   print(f'''Encrypted: {cipher_text}''')
   print(f'''Decrypted with key: {decrypt(key, cipher_text)}''')

