
from __future__ import annotations

import unittest

from transformers import MPNetConfig, is_tf_available
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.models.mpnet.modeling_tf_mpnet import (
       TFMPNetForMaskedLM,
       TFMPNetForMultipleChoice,
       TFMPNetForQuestionAnswering,
       TFMPNetForSequenceClassification,
       TFMPNetForTokenClassification,
       TFMPNetModel,
   )






class 						UpperCAmelCase	:



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


          '''simple docstring'''


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



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


          '''simple docstring'''


          snake_case :     Union[str, Any]           =   ids_tensor([self.batch_size, self.seq_length]					,		self.vocab_size				)

          snake_case :     List[str]           =   None
          if self.use_input_mask:
                 snake_case :     Tuple           =   random_attention_mask([self.batch_size, self.seq_length]				)

          snake_case :     Optional[Any]           =   None
          snake_case :     Any           =   None
          snake_case :     int           =   None
          if self.use_labels:
                 snake_case :     int           =   ids_tensor([self.batch_size]					,		self.type_sequence_label_size				)
                 snake_case :     int           =   ids_tensor([self.batch_size, self.seq_length]					,		self.num_labels				)
                 snake_case :     Dict           =   ids_tensor([self.batch_size]					,		self.num_choices				)

          snake_case :     List[str]           =   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					,		)
          return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels



   def        _SCREAMING_SNAKE_CASE     (self	:      List[str]					,		snake_case__	:      Union[str, Any]					,		snake_case__	:      Optional[Any]					,		snake_case__	:      List[Any]					,		snake_case__	:      Tuple					,		snake_case__	:      int					,		snake_case__	:      int				)	->			Tuple:


          '''simple docstring'''


          snake_case :     Any           =   TFMPNetModel(config=snake_case__				)
          snake_case :     List[Any]           =   {"input_ids": input_ids, "attention_mask": input_mask}
          snake_case :     Optional[Any]           =   model(snake_case__				)
          snake_case :     List[str]           =   [input_ids, input_mask]
          snake_case :     List[Any]           =   model(snake_case__				)
          self.parent.assertEqual(result.last_hidden_state.shape					,		(self.batch_size, self.seq_length, self.hidden_size)				)



   def        _SCREAMING_SNAKE_CASE     (self	:      List[str]					,		snake_case__	:      List[str]					,		snake_case__	:      Union[str, Any]					,		snake_case__	:      Optional[int]					,		snake_case__	:      List[Any]					,		snake_case__	:      Tuple					,		snake_case__	:      List[Any]				)	->			int:


          '''simple docstring'''


          snake_case :     Optional[Any]           =   TFMPNetForMaskedLM(config=snake_case__				)
          snake_case :     Optional[Any]           =   {"input_ids": input_ids, "attention_mask": input_mask}
          snake_case :     List[str]           =   model(snake_case__				)
          self.parent.assertEqual(result.logits.shape					,		(self.batch_size, self.seq_length, self.vocab_size)				)



   def        _SCREAMING_SNAKE_CASE     (self	:      str					,		snake_case__	:      Dict					,		snake_case__	:      str					,		snake_case__	:      List[str]					,		snake_case__	:      int					,		snake_case__	:      Dict					,		snake_case__	:      List[Any]				)	->			int:


          '''simple docstring'''


          snake_case :     Optional[Any]           =   TFMPNetForQuestionAnswering(config=snake_case__				)
          snake_case :     List[str]           =   {
              "input_ids": input_ids,
              "attention_mask": input_mask,
          }
          snake_case :     Optional[int]           =   model(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        _SCREAMING_SNAKE_CASE     (self	:      int					,		snake_case__	:      Union[str, Any]					,		snake_case__	:      Optional[int]					,		snake_case__	:      Optional[int]					,		snake_case__	:      Union[str, Any]					,		snake_case__	:      List[Any]					,		snake_case__	:      Any				)	->			Tuple:


          '''simple docstring'''


          snake_case :     Union[str, Any]           =   self.num_labels
          snake_case :     Optional[int]           =   TFMPNetForSequenceClassification(snake_case__				)
          snake_case :     Dict           =   {"input_ids": input_ids, "attention_mask": input_mask}
          snake_case :     str           =   model(snake_case__				)
          self.parent.assertEqual(result.logits.shape					,		(self.batch_size, self.num_labels)				)



   def        _SCREAMING_SNAKE_CASE     (self	:      Tuple					,		snake_case__	:      Union[str, Any]					,		snake_case__	:      List[str]					,		snake_case__	:      List[str]					,		snake_case__	:      Any					,		snake_case__	:      List[Any]					,		snake_case__	:      Optional[Any]				)	->			List[Any]:


          '''simple docstring'''


          snake_case :     List[Any]           =   self.num_choices
          snake_case :     List[Any]           =   TFMPNetForMultipleChoice(snake_case__				)
          snake_case :     Any           =   tf.tile(tf.expand_dims(snake_case__					,		1				)					,		(1, self.num_choices, 1)				)
          snake_case :     Union[str, Any]           =   tf.tile(tf.expand_dims(snake_case__					,		1				)					,		(1, self.num_choices, 1)				)
          snake_case :     Union[str, Any]           =   {
              "input_ids": multiple_choice_inputs_ids,
              "attention_mask": multiple_choice_input_mask,
          }
          snake_case :     str           =   model(snake_case__				)
          self.parent.assertEqual(result.logits.shape					,		(self.batch_size, self.num_choices)				)



   def        _SCREAMING_SNAKE_CASE     (self	:      List[Any]					,		snake_case__	:      Tuple					,		snake_case__	:      Optional[Any]					,		snake_case__	:      Optional[Any]					,		snake_case__	:      Any					,		snake_case__	:      Optional[Any]					,		snake_case__	:      List[Any]				)	->			Dict:


          '''simple docstring'''


          snake_case :     List[Any]           =   self.num_labels
          snake_case :     Dict           =   TFMPNetForTokenClassification(snake_case__				)
          snake_case :     Tuple           =   {"input_ids": input_ids, "attention_mask": input_mask}
          snake_case :     List[Any]           =   model(snake_case__				)
          self.parent.assertEqual(result.logits.shape					,		(self.batch_size, self.seq_length, self.num_labels)				)



   def        _SCREAMING_SNAKE_CASE     (self	:      str				)	->			Any:


          '''simple docstring'''


          snake_case :     List[str]           =   self.prepare_config_and_inputs()
          (snake_case) :     Tuple           =   config_and_inputs
          snake_case :     int           =   {"input_ids": input_ids, "attention_mask": input_mask}
          return config, inputs_dict






@require_tf
class 						UpperCAmelCase	(		A_ ,A_ ,unittest.TestCase				):
   A__      :	Dict		  =  (
       (
           TFMPNetForMaskedLM,
           TFMPNetForMultipleChoice,
           TFMPNetForQuestionAnswering,
           TFMPNetForSequenceClassification,
           TFMPNetForTokenClassification,
           TFMPNetModel,
       )
       if is_tf_available()
       else ()
   )
   A__      :	List[Any]		  =  (
       {
           "feature-extraction": TFMPNetModel,
           "fill-mask": TFMPNetForMaskedLM,
           "question-answering": TFMPNetForQuestionAnswering,
           "text-classification": TFMPNetForSequenceClassification,
           "token-classification": TFMPNetForTokenClassification,
           "zero-shot": TFMPNetForSequenceClassification,
       }
       if is_tf_available()
       else {}
   )
   A__      :	Optional[int]		  =  False
   A__      :	Optional[int]		  =  False



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


          '''simple docstring'''


          snake_case :     Optional[Any]           =   TFMPNetModelTester(self				)
          snake_case :     Union[str, Any]           =   ConfigTester(self					,		config_class=snake_case__					,		hidden_size=37				)



   def        _SCREAMING_SNAKE_CASE     (self	:      int				)	->			Tuple:


          '''simple docstring'''


          self.config_tester.run_common_tests()



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


          '''simple docstring'''


          snake_case :     Union[str, Any]           =   self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_mpnet_model(*snake_case__				)



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


          '''simple docstring'''


          snake_case :     List[Any]           =   self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_mpnet_for_masked_lm(*snake_case__				)



   def        _SCREAMING_SNAKE_CASE     (self	:      List[Any]				)	->			Any:


          '''simple docstring'''


          snake_case :     Optional[Any]           =   self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_mpnet_for_question_answering(*snake_case__				)



   def        _SCREAMING_SNAKE_CASE     (self	:      List[str]				)	->			Optional[Any]:


          '''simple docstring'''


          snake_case :     Tuple           =   self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_mpnet_for_sequence_classification(*snake_case__				)



   def        _SCREAMING_SNAKE_CASE     (self	:      List[Any]				)	->			Any:


          '''simple docstring'''


          snake_case :     Optional[int]           =   self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_mpnet_for_multiple_choice(*snake_case__				)



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


          '''simple docstring'''


          snake_case :     str           =   self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_mpnet_for_token_classification(*snake_case__				)



   @slow
   def        _SCREAMING_SNAKE_CASE     (self	:      List[str]				)	->			Any:


          '''simple docstring'''


          for model_name in ["microsoft/mpnet-base"]:
                 snake_case :     int           =   TFMPNetModel.from_pretrained(snake_case__				)
                 self.assertIsNotNone(snake_case__				)






@require_tf
class 						UpperCAmelCase	(		unittest.TestCase				):



   @slow
   def        _SCREAMING_SNAKE_CASE     (self	:      Any				)	->			Dict:


          '''simple docstring'''


          snake_case :     Optional[int]           =   TFMPNetModel.from_pretrained("microsoft/mpnet-base"				)
          snake_case :     Optional[int]           =   tf.constant([[0, 1, 2, 3, 4, 5]]				)
          snake_case :     Any           =   model(snake_case__				)[0]

          snake_case :     Optional[Any]           =   [1, 6, 7_68]
          self.assertEqual(output.shape					,		snake_case__				)

          snake_case :     Tuple           =   tf.constant(
              [
                  [
                      [-0.1067172, 0.08216473, 0.0024543],
                      [-0.03465879, 0.8354118, -0.03252288],
                      [-0.06569476, -0.12424111, -0.0494436],
                  ]
              ]				)
          tf.debugging.assert_near(output[:, :3, :3]					,		snake_case__					,		atol=1e-4				)







import platform
from argparse import ArgumentParser

import huggingface_hub
import pandas
import pyarrow

from datasets import __version__ as version
from datasets.commands import BaseDatasetsCLICommand


def     UpperCamelCase      (					__lowerCamelCase  :				int					):
       return EnvironmentCommand()






class 						UpperCAmelCase	(		A_				):



   @staticmethod
   def        _SCREAMING_SNAKE_CASE     (snake_case__	:      ArgumentParser				)	->			Any:


          '''simple docstring'''


          snake_case :     Optional[Any]           =   parser.add_parser("env"					,		help="Print relevant system environment info."				)
          download_parser.set_defaults(func=snake_case__				)



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


          '''simple docstring'''


          snake_case :     List[str]           =   {
              "`datasets` version": version,
              "Platform": platform.platform(),
              "Python version": platform.python_version(),
              "Huggingface_hub version": huggingface_hub.__version__,
              "PyArrow version": pyarrow.__version__,
              "Pandas version": pandas.__version__,
          }

          print("\nCopy-and-paste the text below in your GitHub issue.\n"				)
          print(self.format_dict(snake_case__				)				)

          return info



   @staticmethod
   def        _SCREAMING_SNAKE_CASE     (snake_case__	:      Tuple				)	->			Any:


          '''simple docstring'''


          return "\n".join([f"""- {prop}: {val}""" for prop, val in d.items()]				) + "\n"





