





import unittest

from transformers import MPNetConfig, 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 (
          MPNetForMaskedLM,
          MPNetForMultipleChoice,
          MPNetForQuestionAnswering,
          MPNetForSequenceClassification,
          MPNetForTokenClassification,
          MPNetModel,
      )

class 		UpperCamelCase__ :



     '''simple docstring'''

     def __init__(							self						:    Tuple						,lowerCamelCase__						:    Optional[int]						,lowerCamelCase__						:    Any=13						,lowerCamelCase__						:    Tuple=7						,lowerCamelCase__						:    Optional[int]=True						,lowerCamelCase__						:    Optional[Any]=True						,lowerCamelCase__						:    List[Any]=False						,lowerCamelCase__						:    Tuple=True						,lowerCamelCase__						:    List[Any]=99						,lowerCamelCase__						:    Dict=64						,lowerCamelCase__						:    List[Any]=5						,lowerCamelCase__						:    Tuple=4						,lowerCamelCase__						:    Optional[Any]=64						,lowerCamelCase__						:    Union[str, Any]="gelu"						,lowerCamelCase__						:    Optional[int]=0.1						,lowerCamelCase__						:    List[str]=0.1						,lowerCamelCase__						:    Tuple=512						,lowerCamelCase__						:    Tuple=16						,lowerCamelCase__						:    List[str]=2						,lowerCamelCase__						:    Tuple=0.02						,lowerCamelCase__						:    Any=3						,lowerCamelCase__						:    str=4						,lowerCamelCase__						:    List[Any]=None						,)     ->		Union[str, Any]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						parent
           SCREAMING_SNAKE_CASE		=						batch_size
           SCREAMING_SNAKE_CASE		=						seq_length
           SCREAMING_SNAKE_CASE		=						is_training
           SCREAMING_SNAKE_CASE		=						use_input_mask
           SCREAMING_SNAKE_CASE		=						use_token_type_ids
           SCREAMING_SNAKE_CASE		=						use_labels
           SCREAMING_SNAKE_CASE		=						vocab_size
           SCREAMING_SNAKE_CASE		=						hidden_size
           SCREAMING_SNAKE_CASE		=						num_hidden_layers
           SCREAMING_SNAKE_CASE		=						num_attention_heads
           SCREAMING_SNAKE_CASE		=						intermediate_size
           SCREAMING_SNAKE_CASE		=						hidden_act
           SCREAMING_SNAKE_CASE		=						hidden_dropout_prob
           SCREAMING_SNAKE_CASE		=						attention_probs_dropout_prob
           SCREAMING_SNAKE_CASE		=						max_position_embeddings
           SCREAMING_SNAKE_CASE		=						type_vocab_size
           SCREAMING_SNAKE_CASE		=						type_sequence_label_size
           SCREAMING_SNAKE_CASE		=						initializer_range
           SCREAMING_SNAKE_CASE		=						num_labels
           SCREAMING_SNAKE_CASE		=						num_choices
           SCREAMING_SNAKE_CASE		=						scope






     def 				SCREAMING_SNAKE_CASE__  (							self						:    List[str]       )     ->		str:




           '''simple docstring'''


           return MPNetConfig.from_pretrained("""microsoft/mpnet-base"""       )






     def 				SCREAMING_SNAKE_CASE__  (							self						:    Dict       )     ->		Any:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						ids_tensor([self.batch_size, self.seq_length]						,self.vocab_size       )

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

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

           SCREAMING_SNAKE_CASE		=						self.get_config()
           return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels






     def 				SCREAMING_SNAKE_CASE__  (							self						:    Optional[Any]       )     ->		int:




           '''simple docstring'''


           return MPNetConfig(
               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						,initializer_range=self.initializer_range						,)






     def 				SCREAMING_SNAKE_CASE__  (							self						:    Any						,lowerCamelCase__						:    Tuple						,lowerCamelCase__						:    Union[str, Any]						,lowerCamelCase__						:    Tuple						,lowerCamelCase__						:    List[str]						,lowerCamelCase__						:    Optional[Any]						,lowerCamelCase__						:    Dict       )     ->		List[Any]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						MPNetModel(config=lowerCamelCase__       )
           model.to(lowerCamelCase__       )
           model.eval()
           SCREAMING_SNAKE_CASE		=						model(lowerCamelCase__						,lowerCamelCase__       )
           SCREAMING_SNAKE_CASE		=						model(lowerCamelCase__       )
           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						:    Any						,lowerCamelCase__						:    Optional[int]						,lowerCamelCase__						:    Tuple						,lowerCamelCase__						:    Tuple						,lowerCamelCase__						:    Union[str, Any]						,lowerCamelCase__						:    Dict						,lowerCamelCase__						:    Tuple       )     ->		int:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						MPNetForQuestionAnswering(config=lowerCamelCase__       )
           model.to(lowerCamelCase__       )
           model.eval()
           SCREAMING_SNAKE_CASE		=						model(
               lowerCamelCase__						,attention_mask=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						:    Any						,lowerCamelCase__						:    List[Any]						,lowerCamelCase__						:    Optional[Any]						,lowerCamelCase__						:    List[str]						,lowerCamelCase__						:    Optional[Any]						,lowerCamelCase__						:    Union[str, Any]						,lowerCamelCase__						:    Tuple       )     ->		List[Any]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						self.num_labels
           SCREAMING_SNAKE_CASE		=						MPNetForSequenceClassification(lowerCamelCase__       )
           model.to(lowerCamelCase__       )
           model.eval()
           SCREAMING_SNAKE_CASE		=						model(lowerCamelCase__						,attention_mask=lowerCamelCase__						,labels=lowerCamelCase__       )
           self.parent.assertEqual(result.logits.shape						,(self.batch_size, self.num_labels)       )






     def 				SCREAMING_SNAKE_CASE__  (							self						:    Tuple						,lowerCamelCase__						:    int						,lowerCamelCase__						:    List[Any]						,lowerCamelCase__						:    Dict						,lowerCamelCase__						:    str						,lowerCamelCase__						:    List[str]						,lowerCamelCase__						:    Tuple       )     ->		str:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						self.num_choices
           SCREAMING_SNAKE_CASE		=						MPNetForMultipleChoice(config=lowerCamelCase__       )
           model.to(lowerCamelCase__       )
           model.eval()
           SCREAMING_SNAKE_CASE		=						input_ids.unsqueeze(1       ).expand(-1						,self.num_choices						,-1       ).contiguous()
           SCREAMING_SNAKE_CASE		=						input_mask.unsqueeze(1       ).expand(-1						,self.num_choices						,-1       ).contiguous()
           SCREAMING_SNAKE_CASE		=						model(
               lowerCamelCase__						,attention_mask=lowerCamelCase__						,labels=lowerCamelCase__						,)
           self.parent.assertEqual(result.logits.shape						,(self.batch_size, self.num_choices)       )






     def 				SCREAMING_SNAKE_CASE__  (							self						:    str						,lowerCamelCase__						:    Any						,lowerCamelCase__						:    Optional[int]						,lowerCamelCase__						:    Optional[int]						,lowerCamelCase__						:    Dict						,lowerCamelCase__						:    Tuple						,lowerCamelCase__						:    str       )     ->		Any:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						self.num_labels
           SCREAMING_SNAKE_CASE		=						MPNetForTokenClassification(config=lowerCamelCase__       )
           model.to(lowerCamelCase__       )
           model.eval()
           SCREAMING_SNAKE_CASE		=						model(lowerCamelCase__						,attention_mask=lowerCamelCase__						,labels=lowerCamelCase__       )
           self.parent.assertEqual(result.logits.shape						,(self.batch_size, self.seq_length, self.num_labels)       )






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




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						self.prepare_config_and_inputs()
           ((SCREAMING_SNAKE_CASE),					(SCREAMING_SNAKE_CASE),					(SCREAMING_SNAKE_CASE),					(SCREAMING_SNAKE_CASE),					(SCREAMING_SNAKE_CASE),					(SCREAMING_SNAKE_CASE))		=						config_and_inputs
           SCREAMING_SNAKE_CASE		=						{"""input_ids""": input_ids, """attention_mask""": input_mask}
           return config, inputs_dict

@require_torch
class 		UpperCamelCase__ (      lowerCAmelCase_							,      lowerCAmelCase_							,      unittest.TestCase   ):



     '''simple docstring'''

     __snake_case    :	List[Any]			=			(
         (
             MPNetForMaskedLM,
             MPNetForMultipleChoice,
             MPNetForQuestionAnswering,
             MPNetForSequenceClassification,
             MPNetForTokenClassification,
             MPNetModel,
         )
         if is_torch_available()
         else ()
     )
     __snake_case    :	str			=			(
         {
             "feature-extraction": MPNetModel,
             "fill-mask": MPNetForMaskedLM,
             "question-answering": MPNetForQuestionAnswering,
             "text-classification": MPNetForSequenceClassification,
             "token-classification": MPNetForTokenClassification,
             "zero-shot": MPNetForSequenceClassification,
         }
         if is_torch_available()
         else {}
     )
     __snake_case    :	Tuple			=			False
     __snake_case    :	Tuple			=			True






     def 				SCREAMING_SNAKE_CASE__  (							self						:    int       )     ->		Tuple:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						MPNetModelTester(self       )
           SCREAMING_SNAKE_CASE		=						ConfigTester(self						,config_class=lowerCamelCase__						,hidden_size=37       )






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




           '''simple docstring'''


           self.config_tester.run_common_tests()






     def 				SCREAMING_SNAKE_CASE__  (							self						:    Dict       )     ->		Optional[Any]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_mpnet_model(*lowerCamelCase__       )






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




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_mpnet_for_sequence_classification(*lowerCamelCase__       )






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




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_mpnet_for_multiple_choice(*lowerCamelCase__       )






     def 				SCREAMING_SNAKE_CASE__  (							self						:    Optional[int]       )     ->		Union[str, Any]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_mpnet_for_token_classification(*lowerCamelCase__       )






     def 				SCREAMING_SNAKE_CASE__  (							self						:    List[Any]       )     ->		Tuple:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_mpnet_for_question_answering(*lowerCamelCase__       )

@require_torch
class 		UpperCamelCase__ (      unittest.TestCase   ):



     '''simple docstring'''

     @slow
     def 				SCREAMING_SNAKE_CASE__  (							self						:    Tuple       )     ->		Tuple:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						MPNetModel.from_pretrained("""microsoft/mpnet-base"""       )
           SCREAMING_SNAKE_CASE		=						torch.tensor([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]       )
           SCREAMING_SNAKE_CASE		=						model(lowerCamelCase__       )[0]
           SCREAMING_SNAKE_CASE		=						torch.Size((1, 11, 768)       )
           self.assertEqual(output.shape						,lowerCamelCase__       )
           SCREAMING_SNAKE_CASE		=						torch.tensor(
               [[[-0.0550, 0.1943, -0.0740], [-0.0562, 0.2211, -0.0579], [-0.0437, 0.3337, -0.0641]]]       )
           # compare the actual values for a slice.
           self.assertTrue(torch.allclose(output[:, :3, :3]						,lowerCamelCase__						,atol=1e-4       )       )









import random

class 		UpperCamelCase__ :



     '''simple docstring'''

     @staticmethod
     def 				SCREAMING_SNAKE_CASE__  (							lowerCamelCase__						:    str       )     ->		tuple[list[int], list[int]]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						[ord(lowerCamelCase__       ) for i in text]
           SCREAMING_SNAKE_CASE		=						[]
           SCREAMING_SNAKE_CASE		=						[]
           for i in plain:
                 SCREAMING_SNAKE_CASE		=						random.randint(1						,300       )
                 SCREAMING_SNAKE_CASE		=						(i + k) * k
                 cipher.append(lowerCamelCase__       )
                 key.append(lowerCamelCase__       )
           return cipher, key






     @staticmethod
     def 				SCREAMING_SNAKE_CASE__  (							lowerCamelCase__						:    list[int]						,lowerCamelCase__						:    list[int]       )     ->		str:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						[]
           for i in range(len(lowerCamelCase__       )       ):
                 SCREAMING_SNAKE_CASE		=						int((cipher[i] - (key[i]) ** 2) / key[i]       )
                 plain.append(chr(lowerCamelCase__       )       )
           return "".join(lowerCamelCase__       )


if __name__ == "__main__":
      SCREAMING_SNAKE_CASE_   ,						SCREAMING_SNAKE_CASE_						   =       Onepad().encrypt("""Hello""")
      print(c, k)
      print(Onepad().decrypt(c, k))


