'''simple docstring'''

import unittest

from transformers import 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, floats_tensor, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
      import torch

      from transformers import (
          RemBertConfig,
          RemBertForCausalLM,
          RemBertForMaskedLM,
          RemBertForMultipleChoice,
          RemBertForQuestionAnswering,
          RemBertForSequenceClassification,
          RemBertForTokenClassification,
          RemBertModel,
      )
      from transformers.models.rembert.modeling_rembert import REMBERT_PRETRAINED_MODEL_ARCHIVE_LIST




class    lowerCamelCase__  :



   def __init__(    self					,      lowerCAmelCase__					,      lowerCAmelCase__=13					,      lowerCAmelCase__=7					,      lowerCAmelCase__=True					,      lowerCAmelCase__=True					,      lowerCAmelCase__=True					,      lowerCAmelCase__=True					,      lowerCAmelCase__=99					,      lowerCAmelCase__=32					,      lowerCAmelCase__=18					,      lowerCAmelCase__=43					,      lowerCAmelCase__=5					,      lowerCAmelCase__=4					,      lowerCAmelCase__=37					,      lowerCAmelCase__="gelu"					,      lowerCAmelCase__=0.1					,      lowerCAmelCase__=0.1					,      lowerCAmelCase__=512					,      lowerCAmelCase__=16					,      lowerCAmelCase__=2					,      lowerCAmelCase__=0.02					,      lowerCAmelCase__=3					,      lowerCAmelCase__=4					,      lowerCAmelCase__=None					,      )				->     Any:
        """simple docstring"""





        _UpperCamelCase  :Optional[int]       =parent
        _UpperCamelCase  :List[Any]       =batch_size
        _UpperCamelCase  :List[str]       =seq_length
        _UpperCamelCase  :Dict       =is_training
        _UpperCamelCase  :Union[str, Any]       =use_input_mask
        _UpperCamelCase  :Union[str, Any]       =use_token_type_ids
        _UpperCamelCase  :Dict       =use_labels
        _UpperCamelCase  :Any       =vocab_size
        _UpperCamelCase  :Any       =hidden_size
        _UpperCamelCase  :List[str]       =input_embedding_size
        _UpperCamelCase  :Union[str, Any]       =output_embedding_size
        _UpperCamelCase  :Optional[Any]       =num_hidden_layers
        _UpperCamelCase  :int       =num_attention_heads
        _UpperCamelCase  :str       =intermediate_size
        _UpperCamelCase  :Optional[Any]       =hidden_act
        _UpperCamelCase  :Optional[Any]       =hidden_dropout_prob
        _UpperCamelCase  :Optional[Any]       =attention_probs_dropout_prob
        _UpperCamelCase  :Optional[int]       =max_position_embeddings
        _UpperCamelCase  :Tuple       =type_vocab_size
        _UpperCamelCase  :Tuple       =type_sequence_label_size
        _UpperCamelCase  :Tuple       =initializer_range
        _UpperCamelCase  :Union[str, Any]       =num_labels
        _UpperCamelCase  :int       =num_choices
        _UpperCamelCase  :Union[str, Any]       =scope



   def  _UpperCamelCase		(    self     )				->     str:
        """simple docstring"""





        _UpperCamelCase  :Optional[Any]       =ids_tensor([self.batch_size, self.seq_length]					,      self.vocab_size     )

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

        _UpperCamelCase  :Dict       =None
        if self.use_token_type_ids:
             _UpperCamelCase  :Optional[Any]       =ids_tensor([self.batch_size, self.seq_length]					,      self.type_vocab_size     )

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

        _UpperCamelCase  :Any       =RemBertConfig(
            vocab_size=self.vocab_size					,      hidden_size=self.hidden_size					,      input_embedding_size=self.input_embedding_size					,      output_embedding_size=self.output_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					,      is_decoder=lowerCAmelCase__					,      initializer_range=self.initializer_range					,      )

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



   def  _UpperCamelCase		(    self     )				->     List[Any]:
        """simple docstring"""





        (
            (
            _UpperCamelCase
        )       ,      (
            _UpperCamelCase
        )       ,      (
            _UpperCamelCase
        )       ,      (
            _UpperCamelCase
        )       ,      (
            _UpperCamelCase
        )       ,      (
            _UpperCamelCase
        )       ,      (
            _UpperCamelCase
        )       ,      
        )  :Tuple       =self.prepare_config_and_inputs()

        _UpperCamelCase  :List[str]       =True
        _UpperCamelCase  :Tuple       =floats_tensor([self.batch_size, self.seq_length, self.hidden_size]     )
        _UpperCamelCase  :Optional[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  _UpperCamelCase		(    self					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__     )				->     int:
        """simple docstring"""





        _UpperCamelCase  :List[str]       =RemBertModel(config=lowerCAmelCase__     )
        model.to(lowerCAmelCase__     )
        model.eval()
        _UpperCamelCase  :Optional[int]       =model(lowerCAmelCase__					,      attention_mask=lowerCAmelCase__					,      token_type_ids=lowerCAmelCase__     )
        _UpperCamelCase  :List[Any]       =model(lowerCAmelCase__					,      token_type_ids=lowerCAmelCase__     )
        _UpperCamelCase  :List[Any]       =model(lowerCAmelCase__     )
        self.parent.assertEqual(result.last_hidden_state.shape					,      (self.batch_size, self.seq_length, self.hidden_size)     )



   def  _UpperCamelCase		(    self					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      )				->     List[str]:
        """simple docstring"""





        _UpperCamelCase  :Optional[int]       =True
        _UpperCamelCase  :Any       =RemBertModel(lowerCAmelCase__     )
        model.to(lowerCAmelCase__     )
        model.eval()
        _UpperCamelCase  :Optional[Any]       =model(
            lowerCAmelCase__					,      attention_mask=lowerCAmelCase__					,      token_type_ids=lowerCAmelCase__					,      encoder_hidden_states=lowerCAmelCase__					,      encoder_attention_mask=lowerCAmelCase__					,      )
        _UpperCamelCase  :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  _UpperCamelCase		(    self					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      )				->     Optional[int]:
        """simple docstring"""





        _UpperCamelCase  :Dict       =RemBertForCausalLM(config=lowerCAmelCase__     )
        model.to(lowerCAmelCase__     )
        model.eval()
        _UpperCamelCase  :Union[str, 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  _UpperCamelCase		(    self					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__     )				->     Dict:
        """simple docstring"""





        _UpperCamelCase  :str       =RemBertForMaskedLM(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, self.vocab_size)     )



   def  _UpperCamelCase		(    self					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      )				->     Dict:
        """simple docstring"""





        _UpperCamelCase  :int       =True
        _UpperCamelCase  :Tuple       =True
        _UpperCamelCase  :Union[str, Any]       =RemBertForCausalLM(config=lowerCAmelCase__     )
        model.to(lowerCAmelCase__     )
        model.eval()

        # first forward pass
        _UpperCamelCase  :Optional[int]       =model(
            lowerCAmelCase__					,      attention_mask=lowerCAmelCase__					,      encoder_hidden_states=lowerCAmelCase__					,      encoder_attention_mask=lowerCAmelCase__					,      use_cache=lowerCAmelCase__					,      )
        _UpperCamelCase  :Tuple       =outputs.past_key_values

        # create hypothetical multiple next token and extent to next_input_ids
        _UpperCamelCase  :Dict       =ids_tensor((self.batch_size, 3)					,      config.vocab_size     )
        _UpperCamelCase  :List[Any]       =ids_tensor((self.batch_size, 3)					,      vocab_size=2     )

        # append to next input_ids and
        _UpperCamelCase  :str       =torch.cat([input_ids, next_tokens]					,      dim=-1     )
        _UpperCamelCase  :Optional[Any]       =torch.cat([input_mask, next_mask]					,      dim=-1     )

        _UpperCamelCase  :int       =model(
            lowerCAmelCase__					,      attention_mask=lowerCAmelCase__					,      encoder_hidden_states=lowerCAmelCase__					,      encoder_attention_mask=lowerCAmelCase__					,      output_hidden_states=lowerCAmelCase__					,      )["""hidden_states"""][0]
        _UpperCamelCase  :Optional[Any]       =model(
            lowerCAmelCase__					,      attention_mask=lowerCAmelCase__					,      encoder_hidden_states=lowerCAmelCase__					,      encoder_attention_mask=lowerCAmelCase__					,      past_key_values=lowerCAmelCase__					,      output_hidden_states=lowerCAmelCase__					,      )["""hidden_states"""][0]

        # select random slice
        _UpperCamelCase  :List[str]       =ids_tensor((1,)					,      output_from_past.shape[-1]     ).item()
        _UpperCamelCase  :int       =output_from_no_past[:, -3:, random_slice_idx].detach()
        _UpperCamelCase  :Dict       =output_from_past[:, :, random_slice_idx].detach()

        self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1]     )

        # test that outputs are equal for slice
        self.parent.assertTrue(torch.allclose(lowerCAmelCase__					,      lowerCAmelCase__					,      atol=1e-3     )     )



   def  _UpperCamelCase		(    self					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__     )				->     Dict:
        """simple docstring"""





        _UpperCamelCase  :Optional[Any]       =RemBertForQuestionAnswering(config=lowerCAmelCase__     )
        model.to(lowerCAmelCase__     )
        model.eval()
        _UpperCamelCase  :List[str]       =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  _UpperCamelCase		(    self					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__     )				->     str:
        """simple docstring"""





        _UpperCamelCase  :str       =self.num_labels
        _UpperCamelCase  :Optional[int]       =RemBertForSequenceClassification(lowerCAmelCase__     )
        model.to(lowerCAmelCase__     )
        model.eval()
        _UpperCamelCase  :Tuple       =model(lowerCAmelCase__					,      attention_mask=lowerCAmelCase__					,      token_type_ids=lowerCAmelCase__					,      labels=lowerCAmelCase__     )
        self.parent.assertEqual(result.logits.shape					,      (self.batch_size, self.num_labels)     )



   def  _UpperCamelCase		(    self					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__     )				->     List[str]:
        """simple docstring"""





        _UpperCamelCase  :Optional[Any]       =self.num_labels
        _UpperCamelCase  :Union[str, Any]       =RemBertForTokenClassification(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  _UpperCamelCase		(    self					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__     )				->     int:
        """simple docstring"""





        _UpperCamelCase  :Optional[Any]       =self.num_choices
        _UpperCamelCase  :str       =RemBertForMultipleChoice(config=lowerCAmelCase__     )
        model.to(lowerCAmelCase__     )
        model.eval()
        _UpperCamelCase  :List[Any]       =input_ids.unsqueeze(1     ).expand(-1					,      self.num_choices					,      -1     ).contiguous()
        _UpperCamelCase  :List[Any]       =token_type_ids.unsqueeze(1     ).expand(-1					,      self.num_choices					,      -1     ).contiguous()
        _UpperCamelCase  :Any       =input_mask.unsqueeze(1     ).expand(-1					,      self.num_choices					,      -1     ).contiguous()
        _UpperCamelCase  :List[Any]       =model(
            lowerCAmelCase__					,      attention_mask=lowerCAmelCase__					,      token_type_ids=lowerCAmelCase__					,      labels=lowerCAmelCase__					,      )
        self.parent.assertEqual(result.logits.shape					,      (self.batch_size, self.num_choices)     )




   def  _UpperCamelCase		(    self     )				->     Optional[int]:
        """simple docstring"""





        _UpperCamelCase  :Union[str, Any]       =self.prepare_config_and_inputs()
        (
            (
            _UpperCamelCase
        )       ,      (
            _UpperCamelCase
        )       ,      (
            _UpperCamelCase
        )       ,      (
            _UpperCamelCase
        )       ,      (
            _UpperCamelCase
        )       ,      (
            _UpperCamelCase
        )       ,      (
            _UpperCamelCase
        )       ,      
        )  :str       =config_and_inputs
        _UpperCamelCase  :List[Any]       ={"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
        return config, inputs_dict




@require_torch
class    lowerCamelCase__  (   __snake_case       ,				__snake_case       ,				unittest.TestCase     ):
   __UpperCAmelCase           =						(
       (
           RemBertModel,
           RemBertForMaskedLM,
           RemBertForCausalLM,
           RemBertForMultipleChoice,
           RemBertForQuestionAnswering,
           RemBertForSequenceClassification,
           RemBertForTokenClassification,
       )
       if is_torch_available()
       else ()
   )
   __UpperCAmelCase           =						(RemBertForCausalLM,) if is_torch_available() else ()
   __UpperCAmelCase           =						(
       {
           """feature-extraction""": RemBertModel,
           """fill-mask""": RemBertForMaskedLM,
           """question-answering""": RemBertForQuestionAnswering,
           """text-classification""": RemBertForSequenceClassification,
           """text-generation""": RemBertForCausalLM,
           """token-classification""": RemBertForTokenClassification,
           """zero-shot""": RemBertForSequenceClassification,
       }
       if is_torch_available()
       else {}
   )



   def  _UpperCamelCase		(    self     )				->     Optional[int]:
        """simple docstring"""





        _UpperCamelCase  :List[str]       =RemBertModelTester(self     )
        _UpperCamelCase  :Optional[Any]       =ConfigTester(self					,      config_class=lowerCAmelCase__					,      hidden_size=37     )



   def  _UpperCamelCase		(    self     )				->     Optional[int]:
        """simple docstring"""





        self.config_tester.run_common_tests()



   def  _UpperCamelCase		(    self     )				->     Union[str, Any]:
        """simple docstring"""





        _UpperCamelCase  :List[Any]       =self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*lowerCAmelCase__     )



   def  _UpperCamelCase		(    self     )				->     Union[str, Any]:
        """simple docstring"""





        _UpperCamelCase  :Dict       =self.model_tester.prepare_config_and_inputs()
        for type in ["absolute", "relative_key", "relative_key_query"]:
             _UpperCamelCase  :int       =type
             self.model_tester.create_and_check_model(*lowerCAmelCase__     )



   def  _UpperCamelCase		(    self     )				->     int:
        """simple docstring"""





        _UpperCamelCase  :int       =self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_masked_lm(*lowerCAmelCase__     )



   def  _UpperCamelCase		(    self     )				->     Dict:
        """simple docstring"""





        _UpperCamelCase  :List[str]       =self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_multiple_choice(*lowerCAmelCase__     )



   def  _UpperCamelCase		(    self     )				->     Optional[Any]:
        """simple docstring"""





        _UpperCamelCase  :Tuple       =self.model_tester.prepare_config_and_inputs_for_decoder()
        self.model_tester.create_and_check_decoder_model_past_large_inputs(*lowerCAmelCase__     )



   def  _UpperCamelCase		(    self     )				->     int:
        """simple docstring"""





        _UpperCamelCase  :Optional[int]       =self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_question_answering(*lowerCAmelCase__     )



   def  _UpperCamelCase		(    self     )				->     Dict:
        """simple docstring"""





        _UpperCamelCase  :int       =self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_sequence_classification(*lowerCAmelCase__     )



   def  _UpperCamelCase		(    self     )				->     Any:
        """simple docstring"""





        _UpperCamelCase  :Union[str, Any]       =self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_token_classification(*lowerCAmelCase__     )



   def  _UpperCamelCase		(    self     )				->     Optional[Any]:
        """simple docstring"""





        _UpperCamelCase  :Union[str, Any]       =self.model_tester.prepare_config_and_inputs_for_decoder()
        self.model_tester.create_and_check_model_as_decoder(*lowerCAmelCase__     )



   def  _UpperCamelCase		(    self     )				->     Union[str, Any]:
        """simple docstring"""





        (
            (
            _UpperCamelCase
        )       ,      (
            _UpperCamelCase
        )       ,      (
            _UpperCamelCase
        )       ,      (
            _UpperCamelCase
        )       ,      (
            _UpperCamelCase
        )       ,      (
            _UpperCamelCase
        )       ,      (
            _UpperCamelCase
        )       ,      (
            _UpperCamelCase
        )       ,      (
            _UpperCamelCase
        )       ,      
        )  :Dict       =self.model_tester.prepare_config_and_inputs_for_decoder()

        _UpperCamelCase  :str       =None

        self.model_tester.create_and_check_model_as_decoder(
            lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      )




   @slow
   def  _UpperCamelCase		(    self     )				->     Tuple:
        """simple docstring"""





        for model_name in REMBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
             _UpperCamelCase  :List[Any]       =RemBertModel.from_pretrained(lowerCAmelCase__     )
             self.assertIsNotNone(lowerCAmelCase__     )




@require_torch
class    lowerCamelCase__  (   unittest.TestCase     ):



   @slow
   def  _UpperCamelCase		(    self     )				->     Any:
        """simple docstring"""





        _UpperCamelCase  :str       =RemBertModel.from_pretrained("""google/rembert"""     )
        _UpperCamelCase  :Any       =torch.tensor([[312, 56_498, 313, 2_125, 313]]     )
        _UpperCamelCase  :str       =torch.tensor([[0, 0, 0, 1, 1]]     )
        with torch.no_grad():
             _UpperCamelCase  :Union[str, Any]       =model(lowerCAmelCase__					,      token_type_ids=lowerCAmelCase__					,      output_hidden_states=lowerCAmelCase__     )

        _UpperCamelCase  :int       =1_152

        _UpperCamelCase  :Optional[Any]       =torch.Size((1, 5, hidden_size)     )
        self.assertEqual(output["""last_hidden_state"""].shape					,      lowerCAmelCase__     )

        _UpperCamelCase  :Any       =torch.tensor(
            [
                [
                    [0.0754, -0.2022, 0.1904],
                    [-0.3354, -0.3692, -0.4791],
                    [-0.2314, -0.6729, -0.0749],
                    [-0.0396, -0.3105, -0.4234],
                    [-0.1571, -0.0525, 0.5353],
                ]
            ]     )

        # Running on the original tf implementation gives slightly different results here.
        # Not clear why this variations is present
        # TODO: Find reason for discrepancy
        # expected_original_implementation = [[
        #     [0.07630594074726105, -0.20146065950393677, 0.19107051193714142],
        #     [-0.3405614495277405, -0.36971670389175415, -0.4808273911476135],
        #     [-0.22587086260318756, -0.6656315922737122, -0.07844287157058716],
        #     [-0.04145475849509239, -0.3077218234539032, -0.42316967248916626],
        #     [-0.15887849032878876, -0.054529931396245956, 0.5356100797653198]
        # ]]

        self.assertTrue(torch.allclose(output["""last_hidden_state"""][:, :, :3]					,      lowerCAmelCase__					,      atol=1e-4     )     )
'''simple docstring'''

import numpy as np

_lowerCamelCase :				int														= [
    ["""a""", """b""", """c""", """d""", """e"""],
    ["""f""", """g""", """h""", """i""", """k"""],
    ["""l""", """m""", """n""", """o""", """p"""],
    ["""q""", """r""", """s""", """t""", """u"""],
    ["""v""", """w""", """x""", """y""", """z"""],
]




class    lowerCamelCase__  :



   def __init__(    self     )				->     None:
        """simple docstring"""





        _UpperCamelCase  :Any       =np.array(lowerCAmelCase__     )



   def  _UpperCamelCase		(    self					,      lowerCAmelCase__     )				->     np.ndarray:
        """simple docstring"""





        _UpperCamelCase       ,      _UpperCamelCase  :str       =np.where(letter == self.SQUARE     )
        _UpperCamelCase  :Union[str, Any]       =np.concatenate([indexa + 1, indexa + 1]     )
        return indexes



   def  _UpperCamelCase		(    self					,      lowerCAmelCase__					,      lowerCAmelCase__     )				->     str:
        """simple docstring"""





        return self.SQUARE[indexa - 1, indexa - 1]



   def  _UpperCamelCase		(    self					,      lowerCAmelCase__     )				->     str:
        """simple docstring"""





        _UpperCamelCase  :str       =message.lower()
        _UpperCamelCase  :List[Any]       =message.replace("""j"""					,      """i"""     )

        _UpperCamelCase  :List[str]       =""""""
        for letter_index in range(len(lowerCAmelCase__     )     ):
             if message[letter_index] != " ":
                  _UpperCamelCase  :Dict       =self.letter_to_numbers(message[letter_index]     )
                  _UpperCamelCase  :List[Any]       =encoded_message + str(numbers[0]     ) + str(numbers[1]     )
             elif message[letter_index] == " ":
                  _UpperCamelCase  :List[Any]       =encoded_message + """ """

        return encoded_message




   def  _UpperCamelCase		(    self					,      lowerCAmelCase__     )				->     str:
        """simple docstring"""





        _UpperCamelCase  :List[str]       =message.replace(""" """					,      """  """     )
        _UpperCamelCase  :Dict       =""""""
        for numbers_index in range(int(len(lowerCAmelCase__     ) / 2     )     ):
             if message[numbers_index * 2] != " ":
                  _UpperCamelCase  :Tuple       =message[numbers_index * 2]
                  _UpperCamelCase  :List[str]       =message[numbers_index * 2 + 1]

                  _UpperCamelCase  :Dict       =self.numbers_to_letter(int(lowerCAmelCase__     )					,      int(lowerCAmelCase__     )     )
                  _UpperCamelCase  :Union[str, Any]       =decoded_message + letter
             elif message[numbers_index * 2] == " ":
                  _UpperCamelCase  :Dict       =decoded_message + """ """

        return decoded_message