code: 
  
  
  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 						snake_case			:
  			'''simple docstring'''
  
  			def __init__(	self     :     Optional[Any]							,							lowerCAmelCase_     :     Any							,							lowerCAmelCase_     :     Dict=13							,							lowerCAmelCase_     :     str=7							,							lowerCAmelCase_     :     Any=True							,							lowerCAmelCase_     :     Any=True							,							lowerCAmelCase_     :     Dict=False							,							lowerCAmelCase_     :     Any=True							,							lowerCAmelCase_     :     Tuple=99							,							lowerCAmelCase_     :     Optional[Any]=64							,							lowerCAmelCase_     :     List[Any]=2							,							lowerCAmelCase_     :     Dict=4							,							lowerCAmelCase_     :     Optional[int]=64							,							lowerCAmelCase_     :     List[Any]="gelu"							,							lowerCAmelCase_     :     Optional[Any]=0.1							,							lowerCAmelCase_     :     Tuple=0.1							,							lowerCAmelCase_     :     Optional[int]=512							,							lowerCAmelCase_     :     int=16							,							lowerCAmelCase_     :     List[Any]=2							,							lowerCAmelCase_     :     Dict=0.02							,							lowerCAmelCase_     :     List[Any]=3							,							lowerCAmelCase_     :     Optional[int]=4							,							lowerCAmelCase_     :     str=None							,							)					->					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 _lowercase (	self     :     int					)					->					Dict:
  
  
  
  
  								"""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_	      =       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 _lowercase (	self     :     Any							,							lowerCAmelCase_     :     Optional[int]							,							lowerCAmelCase_     :     str							,							lowerCAmelCase_     :     Any							,							lowerCAmelCase_     :     Any							,							lowerCAmelCase_     :     Union[str, Any]							,							lowerCAmelCase_     :     Any					)					->					Union[str, Any]:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       TFMPNetModel(config=lowerCAmelCase_					)
  								SCREAMING_SNAKE_CASE_	      =       {'''input_ids''': input_ids, '''attention_mask''': input_mask}
  								SCREAMING_SNAKE_CASE_	      =       model(lowerCAmelCase_					)
  								SCREAMING_SNAKE_CASE_	      =       [input_ids, input_mask]
  								SCREAMING_SNAKE_CASE_	      =       model(lowerCAmelCase_					)
  								self.parent.assertEqual(result.last_hidden_state.shape							,							(self.batch_size, self.seq_length, self.hidden_size)					)
  
  			def _lowercase (	self     :     List[Any]							,							lowerCAmelCase_     :     List[str]							,							lowerCAmelCase_     :     Union[str, Any]							,							lowerCAmelCase_     :     List[Any]							,							lowerCAmelCase_     :     int							,							lowerCAmelCase_     :     Dict							,							lowerCAmelCase_     :     Optional[int]					)					->					List[str]:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       TFMPNetForMaskedLM(config=lowerCAmelCase_					)
  								SCREAMING_SNAKE_CASE_	      =       {'''input_ids''': input_ids, '''attention_mask''': input_mask}
  								SCREAMING_SNAKE_CASE_	      =       model(lowerCAmelCase_					)
  								self.parent.assertEqual(result.logits.shape							,							(self.batch_size, self.seq_length, self.vocab_size)					)
  
  			def _lowercase (	self     :     Optional[int]							,							lowerCAmelCase_     :     Optional[int]							,							lowerCAmelCase_     :     List[str]							,							lowerCAmelCase_     :     Optional[int]							,							lowerCAmelCase_     :     Any							,							lowerCAmelCase_     :     str							,							lowerCAmelCase_     :     Any					)					->					List[Any]:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       TFMPNetForQuestionAnswering(config=lowerCAmelCase_					)
  								SCREAMING_SNAKE_CASE_	      =       {
  								    '''input_ids''': input_ids,
  								    '''attention_mask''': input_mask,
  								}
  								SCREAMING_SNAKE_CASE_	      =       model(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 _lowercase (	self     :     str							,							lowerCAmelCase_     :     str							,							lowerCAmelCase_     :     int							,							lowerCAmelCase_     :     Dict							,							lowerCAmelCase_     :     List[Any]							,							lowerCAmelCase_     :     Union[str, Any]							,							lowerCAmelCase_     :     Tuple					)					->					int:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       self.num_labels
  								SCREAMING_SNAKE_CASE_	      =       TFMPNetForSequenceClassification(lowerCAmelCase_					)
  								SCREAMING_SNAKE_CASE_	      =       {'''input_ids''': input_ids, '''attention_mask''': input_mask}
  								SCREAMING_SNAKE_CASE_	      =       model(lowerCAmelCase_					)
  								self.parent.assertEqual(result.logits.shape							,							(self.batch_size, self.num_labels)					)
  
  			def _lowercase (	self     :     Optional[Any]							,							lowerCAmelCase_     :     Optional[int]							,							lowerCAmelCase_     :     Dict							,							lowerCAmelCase_     :     Optional[Any]							,							lowerCAmelCase_     :     Any							,							lowerCAmelCase_     :     Tuple							,							lowerCAmelCase_     :     Dict					)					->					int:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       self.num_choices
  								SCREAMING_SNAKE_CASE_	      =       TFMPNetForMultipleChoice(lowerCAmelCase_					)
  								SCREAMING_SNAKE_CASE_	      =       tf.tile(tf.expand_dims(lowerCAmelCase_							,							1					)							,							(1, self.num_choices, 1)					)
  								SCREAMING_SNAKE_CASE_	      =       tf.tile(tf.expand_dims(lowerCAmelCase_							,							1					)							,							(1, self.num_choices, 1)					)
  								SCREAMING_SNAKE_CASE_	      =       {
  								    '''input_ids''': multiple_choice_inputs_ids,
  								    '''attention_mask''': multiple_choice_input_mask,
  								}
  								SCREAMING_SNAKE_CASE_	      =       model(lowerCAmelCase_					)
  								self.parent.assertEqual(result.logits.shape							,							(self.batch_size, self.num_choices)					)
  
  			def _lowercase (	self     :     Dict							,							lowerCAmelCase_     :     Union[str, Any]							,							lowerCAmelCase_     :     Union[str, Any]							,							lowerCAmelCase_     :     str							,							lowerCAmelCase_     :     Tuple							,							lowerCAmelCase_     :     int							,							lowerCAmelCase_     :     str					)					->					List[Any]:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       self.num_labels
  								SCREAMING_SNAKE_CASE_	      =       TFMPNetForTokenClassification(lowerCAmelCase_					)
  								SCREAMING_SNAKE_CASE_	      =       {'''input_ids''': input_ids, '''attention_mask''': input_mask}
  								SCREAMING_SNAKE_CASE_	      =       model(lowerCAmelCase_					)
  								self.parent.assertEqual(result.logits.shape							,							(self.batch_size, self.seq_length, self.num_labels)					)
  
  
  
  
  			def _lowercase (	self     :     int					)					->					Tuple:
  
  
  
  
  								"""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_tf
  class 						snake_case			(       lowerCAmelCase__	, lowerCAmelCase__	, unittest.TestCase	):
  			'''simple docstring'''
  
  			UpperCAmelCase       :       Dict       = (
  			    (
  			        TFMPNetForMaskedLM,
  			        TFMPNetForMultipleChoice,
  			        TFMPNetForQuestionAnswering,
  			        TFMPNetForSequenceClassification,
  			        TFMPNetForTokenClassification,
  			        TFMPNetModel,
  			    )
  			    if is_tf_available()
  			    else ()
  			)
  			UpperCAmelCase       :       str       = (
  			    {
  			        """feature-extraction""": TFMPNetModel,
  			        """fill-mask""": TFMPNetForMaskedLM,
  			        """question-answering""": TFMPNetForQuestionAnswering,
  			        """text-classification""": TFMPNetForSequenceClassification,
  			        """token-classification""": TFMPNetForTokenClassification,
  			        """zero-shot""": TFMPNetForSequenceClassification,
  			    }
  			    if is_tf_available()
  			    else {}
  			)
  			UpperCAmelCase       :       str       = False
  			UpperCAmelCase       :       Dict       = False
  
  			def _lowercase (	self     :     int					)					->					str:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       TFMPNetModelTester(self					)
  								SCREAMING_SNAKE_CASE_	      =       ConfigTester(self							,							config_class=lowerCAmelCase_							,							hidden_size=37					)
  
  			def _lowercase (	self     :     str					)					->					int:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								self.config_tester.run_common_tests()
  
  			def _lowercase (	self     :     Optional[Any]					)					->					int:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       self.model_tester.prepare_config_and_inputs()
  								self.model_tester.create_and_check_mpnet_model(*lowerCAmelCase_					)
  
  			def _lowercase (	self     :     int					)					->					Tuple:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       self.model_tester.prepare_config_and_inputs()
  								self.model_tester.create_and_check_mpnet_for_masked_lm(*lowerCAmelCase_					)
  
  			def _lowercase (	self     :     Union[str, Any]					)					->					Any:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       self.model_tester.prepare_config_and_inputs()
  								self.model_tester.create_and_check_mpnet_for_question_answering(*lowerCAmelCase_					)
  
  			def _lowercase (	self     :     int					)					->					List[Any]:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       self.model_tester.prepare_config_and_inputs()
  								self.model_tester.create_and_check_mpnet_for_sequence_classification(*lowerCAmelCase_					)
  
  			def _lowercase (	self     :     Dict					)					->					List[str]:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       self.model_tester.prepare_config_and_inputs()
  								self.model_tester.create_and_check_mpnet_for_multiple_choice(*lowerCAmelCase_					)
  
  			def _lowercase (	self     :     int					)					->					Any:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       self.model_tester.prepare_config_and_inputs()
  								self.model_tester.create_and_check_mpnet_for_token_classification(*lowerCAmelCase_					)
  
  
  
  
  			@slow
  			def _lowercase (	self     :     List[str]					)					->					Optional[Any]:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								for model_name in ["microsoft/mpnet-base"]:
  													SCREAMING_SNAKE_CASE_	      =       TFMPNetModel.from_pretrained(lowerCAmelCase_					)
  													self.assertIsNotNone(lowerCAmelCase_					)
  
  @require_tf
  class 						snake_case			(       unittest.TestCase	):
  			'''simple docstring'''
  
  			@slow
  			def _lowercase (	self     :     Optional[Any]					)					->					Optional[int]:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       TFMPNetModel.from_pretrained('''microsoft/mpnet-base'''					)
  								SCREAMING_SNAKE_CASE_	      =       tf.constant([[0, 1, 2, 3, 4, 5]]					)
  								SCREAMING_SNAKE_CASE_	      =       model(lowerCAmelCase_					)[0]
  
  								SCREAMING_SNAKE_CASE_	      =       [1, 6, 768]
  								self.assertEqual(output.shape							,							lowerCAmelCase_					)
  
  								SCREAMING_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]							,							lowerCAmelCase_							,							atol=1e-4					)
  
  
  
style_context: 
  
  
  def 							UpperCAmelCase				(     UpperCAmelCase      )->		bool:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  					if not isinstance(UpperCAmelCase				,UpperCAmelCase      ):
  										SCREAMING_SNAKE_CASE_	      =       f'''Input value of [number={number}] must be an integer'''
  										raise TypeError(UpperCAmelCase      )
  					if number < 0 or number % 2 == 1:
  										return False
  					SCREAMING_SNAKE_CASE_	      =       int(number**0.5      )
  					return number == number_sqrt * (number_sqrt + 1)
  
  
  if __name__ == "__main__":
  		import doctest
  
  		doctest.testmod()
  
  
  