


'''simple docstring'''





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     __lowerCAmelCase     :






  """simple docstring"""





  def __init__(     self       :       List[str]    ,				_lowerCAmelCase       :       Optional[int]    ,				_lowerCAmelCase       :       List[str]=1_3    ,				_lowerCAmelCase       :       int=7    ,				_lowerCAmelCase       :       Any=True    ,				_lowerCAmelCase       :       Optional[Any]=True    ,				_lowerCAmelCase       :       int=False    ,				_lowerCAmelCase       :       int=True    ,				_lowerCAmelCase       :       int=9_9    ,				_lowerCAmelCase       :       Optional[int]=6_4    ,				_lowerCAmelCase       :       Any=2    ,				_lowerCAmelCase       :       Union[str, Any]=4    ,				_lowerCAmelCase       :       List[str]=6_4    ,				_lowerCAmelCase       :       List[str]="gelu"    ,				_lowerCAmelCase       :       List[Any]=0.1    ,				_lowerCAmelCase       :       str=0.1    ,				_lowerCAmelCase       :       Union[str, Any]=5_1_2    ,				_lowerCAmelCase       :       int=1_6    ,				_lowerCAmelCase       :       List[Any]=2    ,				_lowerCAmelCase       :       Union[str, Any]=0.02    ,				_lowerCAmelCase       :       Union[str, Any]=3    ,				_lowerCAmelCase       :       List[Any]=4    ,				_lowerCAmelCase       :       Tuple=None    ,				)   -> Dict:




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



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




     """simple docstring"""
     snake_case_					    =					ids_tensor([self.batch_size, self.seq_length]    ,				self.vocab_size  )

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

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

     snake_case_					    =					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 					lowerCAmelCase__  (     self       :       Optional[int]    ,				_lowerCAmelCase       :       Tuple    ,				_lowerCAmelCase       :       Union[str, Any]    ,				_lowerCAmelCase       :       List[Any]    ,				_lowerCAmelCase       :       Tuple    ,				_lowerCAmelCase       :       int    ,				_lowerCAmelCase       :       Tuple  )   -> Dict:




     """simple docstring"""
     snake_case_					    =					TFMPNetModel(config=lowercase_  )
     snake_case_					    =					{"input_ids": input_ids, "attention_mask": input_mask}
     snake_case_					    =					model(lowercase_  )
     snake_case_					    =					[input_ids, input_mask]
     snake_case_					    =					model(lowercase_  )
     self.parent.assertEqual(result.last_hidden_state.shape    ,				(self.batch_size, self.seq_length, self.hidden_size)  )



  def 					lowerCAmelCase__  (     self       :       Dict    ,				_lowerCAmelCase       :       Dict    ,				_lowerCAmelCase       :       Dict    ,				_lowerCAmelCase       :       Any    ,				_lowerCAmelCase       :       Tuple    ,				_lowerCAmelCase       :       Union[str, Any]    ,				_lowerCAmelCase       :       Dict  )   -> Optional[Any]:




     """simple docstring"""
     snake_case_					    =					TFMPNetForMaskedLM(config=lowercase_  )
     snake_case_					    =					{"input_ids": input_ids, "attention_mask": input_mask}
     snake_case_					    =					model(lowercase_  )
     self.parent.assertEqual(result.logits.shape    ,				(self.batch_size, self.seq_length, self.vocab_size)  )



  def 					lowerCAmelCase__  (     self       :       List[Any]    ,				_lowerCAmelCase       :       List[str]    ,				_lowerCAmelCase       :       Any    ,				_lowerCAmelCase       :       List[Any]    ,				_lowerCAmelCase       :       Optional[int]    ,				_lowerCAmelCase       :       Any    ,				_lowerCAmelCase       :       str  )   -> List[Any]:




     """simple docstring"""
     snake_case_					    =					TFMPNetForQuestionAnswering(config=lowercase_  )
     snake_case_					    =					{
         "input_ids": input_ids,
         "attention_mask": input_mask,
     }
     snake_case_					    =					model(lowercase_  )
     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 					lowerCAmelCase__  (     self       :       Optional[Any]    ,				_lowerCAmelCase       :       str    ,				_lowerCAmelCase       :       Dict    ,				_lowerCAmelCase       :       Optional[Any]    ,				_lowerCAmelCase       :       List[Any]    ,				_lowerCAmelCase       :       str    ,				_lowerCAmelCase       :       Dict  )   -> str:




     """simple docstring"""
     snake_case_					    =					self.num_labels
     snake_case_					    =					TFMPNetForSequenceClassification(lowercase_  )
     snake_case_					    =					{"input_ids": input_ids, "attention_mask": input_mask}
     snake_case_					    =					model(lowercase_  )
     self.parent.assertEqual(result.logits.shape    ,				(self.batch_size, self.num_labels)  )



  def 					lowerCAmelCase__  (     self       :       Optional[int]    ,				_lowerCAmelCase       :       List[str]    ,				_lowerCAmelCase       :       List[str]    ,				_lowerCAmelCase       :       List[str]    ,				_lowerCAmelCase       :       int    ,				_lowerCAmelCase       :       List[Any]    ,				_lowerCAmelCase       :       List[Any]  )   -> Optional[Any]:




     """simple docstring"""
     snake_case_					    =					self.num_choices
     snake_case_					    =					TFMPNetForMultipleChoice(lowercase_  )
     snake_case_					    =					tf.tile(tf.expand_dims(lowercase_    ,				1  )    ,				(1, self.num_choices, 1)  )
     snake_case_					    =					tf.tile(tf.expand_dims(lowercase_    ,				1  )    ,				(1, self.num_choices, 1)  )
     snake_case_					    =					{
         "input_ids": multiple_choice_inputs_ids,
         "attention_mask": multiple_choice_input_mask,
     }
     snake_case_					    =					model(lowercase_  )
     self.parent.assertEqual(result.logits.shape    ,				(self.batch_size, self.num_choices)  )



  def 					lowerCAmelCase__  (     self       :       int    ,				_lowerCAmelCase       :       List[Any]    ,				_lowerCAmelCase       :       Any    ,				_lowerCAmelCase       :       Dict    ,				_lowerCAmelCase       :       Any    ,				_lowerCAmelCase       :       Optional[int]    ,				_lowerCAmelCase       :       str  )   -> List[Any]:




     """simple docstring"""
     snake_case_					    =					self.num_labels
     snake_case_					    =					TFMPNetForTokenClassification(lowercase_  )
     snake_case_					    =					{"input_ids": input_ids, "attention_mask": input_mask}
     snake_case_					    =					model(lowercase_  )
     self.parent.assertEqual(result.logits.shape    ,				(self.batch_size, self.seq_length, self.num_labels)  )



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




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






@require_tf
class     __lowerCAmelCase     ( lowerCamelCase__ ,  lowerCamelCase__ ,  unittest.TestCase					):






  """simple docstring"""





  _SCREAMING_SNAKE_CASE		    =       (
      (
          TFMPNetForMaskedLM,
          TFMPNetForMultipleChoice,
          TFMPNetForQuestionAnswering,
          TFMPNetForSequenceClassification,
          TFMPNetForTokenClassification,
          TFMPNetModel,
      )
      if is_tf_available()
      else ()
  )
  _SCREAMING_SNAKE_CASE		    =       (
      {
          'feature-extraction': TFMPNetModel,
          'fill-mask': TFMPNetForMaskedLM,
          'question-answering': TFMPNetForQuestionAnswering,
          'text-classification': TFMPNetForSequenceClassification,
          'token-classification': TFMPNetForTokenClassification,
          'zero-shot': TFMPNetForSequenceClassification,
      }
      if is_tf_available()
      else {}
  )
  _SCREAMING_SNAKE_CASE		    =       False
  _SCREAMING_SNAKE_CASE		    =       False



  def 					lowerCAmelCase__  (     self       :       Dict  )   -> Any:




     """simple docstring"""
     snake_case_					    =					TFMPNetModelTester(self  )
     snake_case_					    =					ConfigTester(self    ,				config_class=lowercase_    ,				hidden_size=3_7  )



  def 					lowerCAmelCase__  (     self       :       Any  )   -> int:




     """simple docstring"""
     self.config_tester.run_common_tests()



  def 					lowerCAmelCase__  (     self       :       Optional[int]  )   -> Tuple:




     """simple docstring"""
     snake_case_					    =					self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_mpnet_model(*lowercase_  )



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




     """simple docstring"""
     snake_case_					    =					self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_mpnet_for_masked_lm(*lowercase_  )



  def 					lowerCAmelCase__  (     self       :       Optional[int]  )   -> Tuple:




     """simple docstring"""
     snake_case_					    =					self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_mpnet_for_question_answering(*lowercase_  )



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




     """simple docstring"""
     snake_case_					    =					self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_mpnet_for_sequence_classification(*lowercase_  )



  def 					lowerCAmelCase__  (     self       :       Tuple  )   -> List[str]:




     """simple docstring"""
     snake_case_					    =					self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_mpnet_for_multiple_choice(*lowercase_  )



  def 					lowerCAmelCase__  (     self       :       int  )   -> List[Any]:




     """simple docstring"""
     snake_case_					    =					self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_mpnet_for_token_classification(*lowercase_  )



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




     """simple docstring"""






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






@require_tf
class     __lowerCAmelCase     ( unittest.TestCase					):






  """simple docstring"""





  @slow
  def 					lowerCAmelCase__  (     self       :       Dict  )   -> str:




     """simple docstring"""
     snake_case_					    =					TFMPNetModel.from_pretrained("microsoft/mpnet-base"  )
     snake_case_					    =					tf.constant([[0, 1, 2, 3, 4, 5]]  )
     snake_case_					    =					model(lowercase_  )[0]

     snake_case_					    =					[1, 6, 7_6_8]
     self.assertEqual(output.shape    ,				lowercase_  )

     snake_case_					    =					tf.constant(
         [
             [
                 [-0.1_067_172, 0.08_216_473, 0.0_024_543],
                 [-0.03_465_879, 0.8_354_118, -0.03_252_288],
                 [-0.06_569_476, -0.12_424_111, -0.0_494_436],
             ]
         ]  )
     tf.debugging.assert_near(output[:, :3, :3]    ,				lowercase_    ,				atol=1e-4  )








from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


SCREAMING_SNAKE_CASE	:List[str]  		=     {
    '''configuration_prophetnet''': ['''PROPHETNET_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''ProphetNetConfig'''],
    '''tokenization_prophetnet''': ['''ProphetNetTokenizer'''],
}

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   SCREAMING_SNAKE_CASE	:List[str]  		=     [
       '''PROPHETNET_PRETRAINED_MODEL_ARCHIVE_LIST''',
       '''ProphetNetDecoder''',
       '''ProphetNetEncoder''',
       '''ProphetNetForCausalLM''',
       '''ProphetNetForConditionalGeneration''',
       '''ProphetNetModel''',
       '''ProphetNetPreTrainedModel''',
   ]


if TYPE_CHECKING:
   from .configuration_prophetnet import PROPHETNET_PRETRAINED_CONFIG_ARCHIVE_MAP, ProphetNetConfig
   from .tokenization_prophetnet import ProphetNetTokenizer

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_prophetnet import (
          PROPHETNET_PRETRAINED_MODEL_ARCHIVE_LIST,
          ProphetNetDecoder,
          ProphetNetEncoder,
          ProphetNetForCausalLM,
          ProphetNetForConditionalGeneration,
          ProphetNetModel,
          ProphetNetPreTrainedModel,
      )

else:
   import sys

   SCREAMING_SNAKE_CASE	:int  		=     _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)




