



"""simple docstring"""






import os
import pickle
import tempfile
import unittest
from typing import Callable, Optional

import numpy as np

from transformers import (
    BatchEncoding,
    BertTokenizer,
    BertTokenizerFast,
    PreTrainedTokenizer,
    PreTrainedTokenizerFast,
    TensorType,
    TokenSpan,
    is_tokenizers_available,
)
from transformers.models.gpta.tokenization_gpta import GPTaTokenizer
from transformers.testing_utils import CaptureStderr, require_flax, require_tf, require_tokenizers, require_torch, slow


if is_tokenizers_available():
		from tokenizers import Tokenizer
		from tokenizers.models import WordPiece

class 			__SCREAMING_SNAKE_CASE      ( unittest.TestCase  ):


					'''simple docstring'''





					def 						snake_case			(			self				:    Optional[int],    lowerCamelCase				:    Optional[Any]	)->   str:
								lowerCamelCase__						:						int						      =list(tokenizer_class.max_model_input_sizes.keys()	)
								for model_name in sa_models[:1]:
											lowerCamelCase__						:						int						      =tokenizer_class.from_pretrained(lowerCamelCase	)
											self.assertIsNotNone(lowerCamelCase	)
											self.assertIsInstance(lowerCamelCase,    lowerCamelCase	)
											self.assertIsInstance(lowerCamelCase,    lowerCamelCase	)

											for special_tok in tokenizer.all_special_tokens:
														self.assertIsInstance(lowerCamelCase,    lowerCamelCase	)
														lowerCamelCase__						:						Optional[Any]						      =tokenizer.convert_tokens_to_ids(lowerCamelCase	)
														self.assertIsInstance(lowerCamelCase,    lowerCamelCase	)



					def 						snake_case			(			self				:    Dict,    lowerCamelCase				:    BatchEncoding,    lowerCamelCase				:    Optional[Callable] = None	)->   List[Any]:
								lowerCamelCase__						:						List[Any]						      =pickle.dumps(lowerCamelCase	)
								self.assertIsNotNone(lowerCamelCase	)

								lowerCamelCase__						:						Union[str, Any]						      =pickle.loads(lowerCamelCase	)

								# Ensure is_fast is correctly restored
								self.assertEqual(be_restored.is_fast,    be_original.is_fast	)

								# Ensure encodings are potentially correctly restored
								if be_original.is_fast:
											self.assertIsNotNone(be_restored.encodings	)
								else:
											self.assertIsNone(be_restored.encodings	)

								# Ensure the keys are the same
								for original_v, restored_v in zip(be_original.values(),    be_restored.values()	):
											if equal_op:
														self.assertTrue(equal_op(lowerCamelCase,    lowerCamelCase	)	)
											else:
														self.assertEqual(lowerCamelCase,    lowerCamelCase	)



					@slow
					def 						snake_case			(			self				:    Optional[Any]	)->   Tuple:
								self.check_tokenizer_from_pretrained(lowerCamelCase	)



					def 						snake_case			(			self				:    Union[str, Any]	)->   Tuple:
								self.assertEqual(TensorType('''tf'''	),    TensorType.TENSORFLOW	)
								self.assertEqual(TensorType('''pt'''	),    TensorType.PYTORCH	)
								self.assertEqual(TensorType('''np'''	),    TensorType.NUMPY	)



					@require_tokenizers
					def 						snake_case			(			self				:    Union[str, Any]	)->   Dict:
								import numpy as np

								lowerCamelCase__						:						Union[str, Any]						      =BertTokenizer.from_pretrained('''bert-base-cased'''	)
								lowerCamelCase__						:						str						      =BertTokenizerFast.from_pretrained('''bert-base-cased'''	)

								# Python no tensor
								with self.subTest('''BatchEncoding (Python, return_tensors=None)'''	):
											self.assert_dump_and_restore(tokenizer_p('''Small example to encode'''	)	)

								with self.subTest('''BatchEncoding (Python, return_tensors=NUMPY)'''	):
											self.assert_dump_and_restore(
											    tokenizer_p('''Small example to encode''',    return_tensors=TensorType.NUMPY	),    np.array_equal	)

								with self.subTest('''BatchEncoding (Rust, return_tensors=None)'''	):
											self.assert_dump_and_restore(tokenizer_r('''Small example to encode'''	)	)

								with self.subTest('''BatchEncoding (Rust, return_tensors=NUMPY)'''	):
											self.assert_dump_and_restore(
											    tokenizer_r('''Small example to encode''',    return_tensors=TensorType.NUMPY	),    np.array_equal	)



					@require_tf
					@require_tokenizers
					def 						snake_case			(			self				:    Tuple	)->   Tuple:
								import tensorflow as tf

								def tf_array_equals(lowerCamelCase				:    Optional[Any],    lowerCamelCase				:    Any	):
											return tf.reduce_all(tf.equal(lowerCamelCase,    lowerCamelCase	)	)

								lowerCamelCase__						:						List[str]						      =BertTokenizer.from_pretrained('''bert-base-cased'''	)
								lowerCamelCase__						:						List[Any]						      =BertTokenizerFast.from_pretrained('''bert-base-cased'''	)

								with self.subTest('''BatchEncoding (Python, return_tensors=TENSORFLOW)'''	):
											self.assert_dump_and_restore(
											    tokenizer_p('''Small example to encode''',    return_tensors=TensorType.TENSORFLOW	),    lowerCamelCase	)

								with self.subTest('''BatchEncoding (Rust, return_tensors=TENSORFLOW)'''	):
											self.assert_dump_and_restore(
											    tokenizer_r('''Small example to encode''',    return_tensors=TensorType.TENSORFLOW	),    lowerCamelCase	)



					@require_torch
					@require_tokenizers
					def 						snake_case			(			self				:    Union[str, Any]	)->   Union[str, Any]:
								import torch

								lowerCamelCase__						:						Union[str, Any]						      =BertTokenizer.from_pretrained('''bert-base-cased'''	)
								lowerCamelCase__						:						Dict						      =BertTokenizerFast.from_pretrained('''bert-base-cased'''	)

								with self.subTest('''BatchEncoding (Python, return_tensors=PYTORCH)'''	):
											self.assert_dump_and_restore(
											    tokenizer_p('''Small example to encode''',    return_tensors=TensorType.PYTORCH	),    torch.equal	)

								with self.subTest('''BatchEncoding (Rust, return_tensors=PYTORCH)'''	):
											self.assert_dump_and_restore(
											    tokenizer_r('''Small example to encode''',    return_tensors=TensorType.PYTORCH	),    torch.equal	)



					@require_tokenizers
					def 						snake_case			(			self				:    Dict	)->   List[str]:
								lowerCamelCase__						:						Tuple						      =BertTokenizer.from_pretrained('''bert-base-cased'''	)
								lowerCamelCase__						:						List[str]						      =BertTokenizerFast.from_pretrained('''bert-base-cased'''	)

								with self.subTest('''Python Tokenizer'''	):
											self.assertFalse(tokenizer_p('''Small example to_encode'''	).is_fast	)

								with self.subTest('''Rust Tokenizer'''	):
											self.assertTrue(tokenizer_r('''Small example to_encode'''	).is_fast	)



					@require_tokenizers
					def 						snake_case			(			self				:    Any	)->   int:
								lowerCamelCase__						:						List[Any]						      =BertTokenizerFast.from_pretrained('''bert-base-cased'''	)
								lowerCamelCase__						:						Optional[int]						      =tokenizer_r(['''Test''', '''\xad''', '''test'''],    is_split_into_words=lowerCamelCase	)

								self.assertEqual(encoded.word_to_tokens(0	),    TokenSpan(start=1,    end=2	)	)
								self.assertEqual(encoded.word_to_tokens(1	),    lowerCamelCase	)
								self.assertEqual(encoded.word_to_tokens(2	),    TokenSpan(start=2,    end=3	)	)



					def 						snake_case			(			self				:    Tuple	)->   Any:
								lowerCamelCase__						:						Optional[Any]						      =BatchEncoding({'''inputs''': [[1, 2, 3], [4, 5, 6]], '''labels''': [0, 1]}	)
								lowerCamelCase__						:						Union[str, Any]						      =batch.convert_to_tensors(tensor_type='''np'''	)
								self.assertEqual(tensor_batch['''inputs'''].shape,    (2, 3)	)
								self.assertEqual(tensor_batch['''labels'''].shape,    (2,)	)
								# test converting the converted
								with CaptureStderr() as cs:
											lowerCamelCase__						:						Any						      =batch.convert_to_tensors(tensor_type='''np'''	)
								self.assertFalse(len(cs.err	),    msg=F'''should have no warning, but got {cs.err}'''	)

								lowerCamelCase__						:						List[Any]						      =BatchEncoding({'''inputs''': [1, 2, 3], '''labels''': 0}	)
								lowerCamelCase__						:						Dict						      =batch.convert_to_tensors(tensor_type='''np''',    prepend_batch_axis=lowerCamelCase	)
								self.assertEqual(tensor_batch['''inputs'''].shape,    (1, 3)	)
								self.assertEqual(tensor_batch['''labels'''].shape,    (1,)	)



					@require_torch
					def 						snake_case			(			self				:    int	)->   Dict:
								lowerCamelCase__						:						Tuple						      =BatchEncoding({'''inputs''': [[1, 2, 3], [4, 5, 6]], '''labels''': [0, 1]}	)
								lowerCamelCase__						:						Tuple						      =batch.convert_to_tensors(tensor_type='''pt'''	)
								self.assertEqual(tensor_batch['''inputs'''].shape,    (2, 3)	)
								self.assertEqual(tensor_batch['''labels'''].shape,    (2,)	)
								# test converting the converted
								with CaptureStderr() as cs:
											lowerCamelCase__						:						Dict						      =batch.convert_to_tensors(tensor_type='''pt'''	)
								self.assertFalse(len(cs.err	),    msg=F'''should have no warning, but got {cs.err}'''	)

								lowerCamelCase__						:						Optional[Any]						      =BatchEncoding({'''inputs''': [1, 2, 3], '''labels''': 0}	)
								lowerCamelCase__						:						int						      =batch.convert_to_tensors(tensor_type='''pt''',    prepend_batch_axis=lowerCamelCase	)
								self.assertEqual(tensor_batch['''inputs'''].shape,    (1, 3)	)
								self.assertEqual(tensor_batch['''labels'''].shape,    (1,)	)



					@require_tf
					def 						snake_case			(			self				:    List[Any]	)->   Union[str, Any]:
								lowerCamelCase__						:						Dict						      =BatchEncoding({'''inputs''': [[1, 2, 3], [4, 5, 6]], '''labels''': [0, 1]}	)
								lowerCamelCase__						:						Optional[Any]						      =batch.convert_to_tensors(tensor_type='''tf'''	)
								self.assertEqual(tensor_batch['''inputs'''].shape,    (2, 3)	)
								self.assertEqual(tensor_batch['''labels'''].shape,    (2,)	)
								# test converting the converted
								with CaptureStderr() as cs:
											lowerCamelCase__						:						Union[str, Any]						      =batch.convert_to_tensors(tensor_type='''tf'''	)
								self.assertFalse(len(cs.err	),    msg=F'''should have no warning, but got {cs.err}'''	)

								lowerCamelCase__						:						int						      =BatchEncoding({'''inputs''': [1, 2, 3], '''labels''': 0}	)
								lowerCamelCase__						:						str						      =batch.convert_to_tensors(tensor_type='''tf''',    prepend_batch_axis=lowerCamelCase	)
								self.assertEqual(tensor_batch['''inputs'''].shape,    (1, 3)	)
								self.assertEqual(tensor_batch['''labels'''].shape,    (1,)	)



					@require_flax
					def 						snake_case			(			self				:    Optional[int]	)->   Optional[int]:
								lowerCamelCase__						:						Optional[int]						      =BatchEncoding({'''inputs''': [[1, 2, 3], [4, 5, 6]], '''labels''': [0, 1]}	)
								lowerCamelCase__						:						Tuple						      =batch.convert_to_tensors(tensor_type='''jax'''	)
								self.assertEqual(tensor_batch['''inputs'''].shape,    (2, 3)	)
								self.assertEqual(tensor_batch['''labels'''].shape,    (2,)	)
								# test converting the converted
								with CaptureStderr() as cs:
											lowerCamelCase__						:						Dict						      =batch.convert_to_tensors(tensor_type='''jax'''	)
								self.assertFalse(len(cs.err	),    msg=F'''should have no warning, but got {cs.err}'''	)

								lowerCamelCase__						:						Any						      =BatchEncoding({'''inputs''': [1, 2, 3], '''labels''': 0}	)
								lowerCamelCase__						:						str						      =batch.convert_to_tensors(tensor_type='''jax''',    prepend_batch_axis=lowerCamelCase	)
								self.assertEqual(tensor_batch['''inputs'''].shape,    (1, 3)	)
								self.assertEqual(tensor_batch['''labels'''].shape,    (1,)	)



					def 						snake_case			(			self				:    Optional[Any]	)->   int:
								lowerCamelCase__						:						str						      =[{'''input_ids''': np.array([0, 1, 2]	)}, {'''input_ids''': np.array([0, 1, 2, 3]	)}]
								lowerCamelCase__						:						Optional[Any]						      =BertTokenizer.from_pretrained('''bert-base-cased'''	)

								lowerCamelCase__						:						List[str]						      =tokenizer.pad(lowerCamelCase,    padding=lowerCamelCase	)
								self.assertTrue(isinstance(batch['''input_ids'''],    np.ndarray	)	)
								self.assertEqual(batch['''input_ids'''].tolist(),    [[0, 1, 2, tokenizer.pad_token_id], [0, 1, 2, 3]]	)
								lowerCamelCase__						:						Tuple						      =tokenizer.pad(lowerCamelCase,    padding=lowerCamelCase,    return_tensors='''np'''	)
								self.assertTrue(isinstance(batch['''input_ids'''],    np.ndarray	)	)
								self.assertEqual(batch['''input_ids'''].tolist(),    [[0, 1, 2, tokenizer.pad_token_id], [0, 1, 2, 3]]	)



					@require_torch
					def 						snake_case			(			self				:    List[Any]	)->   List[str]:
								import torch

								lowerCamelCase__						:						str						      =[{'''input_ids''': torch.tensor([0, 1, 2]	)}, {'''input_ids''': torch.tensor([0, 1, 2, 3]	)}]
								lowerCamelCase__						:						str						      =BertTokenizer.from_pretrained('''bert-base-cased'''	)

								lowerCamelCase__						:						Union[str, Any]						      =tokenizer.pad(lowerCamelCase,    padding=lowerCamelCase	)
								self.assertTrue(isinstance(batch['''input_ids'''],    torch.Tensor	)	)
								self.assertEqual(batch['''input_ids'''].tolist(),    [[0, 1, 2, tokenizer.pad_token_id], [0, 1, 2, 3]]	)
								lowerCamelCase__						:						Optional[Any]						      =tokenizer.pad(lowerCamelCase,    padding=lowerCamelCase,    return_tensors='''pt'''	)
								self.assertTrue(isinstance(batch['''input_ids'''],    torch.Tensor	)	)
								self.assertEqual(batch['''input_ids'''].tolist(),    [[0, 1, 2, tokenizer.pad_token_id], [0, 1, 2, 3]]	)



					@require_tf
					def 						snake_case			(			self				:    Optional[Any]	)->   Union[str, Any]:
								import tensorflow as tf

								lowerCamelCase__						:						str						      =[{'''input_ids''': tf.constant([0, 1, 2]	)}, {'''input_ids''': tf.constant([0, 1, 2, 3]	)}]
								lowerCamelCase__						:						Dict						      =BertTokenizer.from_pretrained('''bert-base-cased'''	)

								lowerCamelCase__						:						int						      =tokenizer.pad(lowerCamelCase,    padding=lowerCamelCase	)
								self.assertTrue(isinstance(batch['''input_ids'''],    tf.Tensor	)	)
								self.assertEqual(batch['''input_ids'''].numpy().tolist(),    [[0, 1, 2, tokenizer.pad_token_id], [0, 1, 2, 3]]	)
								lowerCamelCase__						:						Union[str, Any]						      =tokenizer.pad(lowerCamelCase,    padding=lowerCamelCase,    return_tensors='''tf'''	)
								self.assertTrue(isinstance(batch['''input_ids'''],    tf.Tensor	)	)
								self.assertEqual(batch['''input_ids'''].numpy().tolist(),    [[0, 1, 2, tokenizer.pad_token_id], [0, 1, 2, 3]]	)



					@require_tokenizers
					def 						snake_case			(			self				:    Tuple	)->   str:
								lowerCamelCase__						:						Any						      =Tokenizer(WordPiece(unk_token='''[UNK]'''	)	)
								PreTrainedTokenizerFast(tokenizer_object=lowerCamelCase	)




					@require_tokenizers
					def 						snake_case			(			self				:    Optional[Any]	)->   Union[str, Any]:
								lowerCamelCase__						:						str						      =Tokenizer(WordPiece(unk_token='''[UNK]'''	)	)
								with tempfile.TemporaryDirectory() as tmpdirname:
											bert_tokenizer.save(os.path.join(lowerCamelCase,    '''tokenizer.json'''	)	)
											PreTrainedTokenizerFast(tokenizer_file=os.path.join(lowerCamelCase,    '''tokenizer.json'''	)	)





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






   def __init__( self							:	Optional[Any]      ,		lowercase_							:	Tuple      ,		lowercase_							:	List[str]=13      ,		lowercase_							:	str=7      ,		lowercase_							:	str=True      ,		lowercase_							:	Dict=True      ,		lowercase_							:	List[str]=False      ,		lowercase_							:	Optional[Any]=True      ,		lowercase_							:	List[str]=99      ,		lowercase_							:	Optional[int]=64      ,		lowercase_							:	Optional[int]=2      ,		lowercase_							:	List[Any]=4      ,		lowercase_							:	Union[str, Any]=64      ,		lowercase_							:	Optional[Any]="gelu"      ,		lowercase_							:	str=0.1      ,		lowercase_							:	Union[str, Any]=0.1      ,		lowercase_							:	Optional[Any]=5_12      ,		lowercase_							:	Optional[Any]=16      ,		lowercase_							:	Optional[Any]=2      ,		lowercase_							:	Any=0.02      ,		lowercase_							:	List[Any]=3      ,		lowercase_							:	List[str]=4      ,		lowercase_							:	Union[str, Any]=None      ,		)   ->		Optional[int]:
       lowercase__					:  str          =							parent
       lowercase__					:  List[str]          =							batch_size
       lowercase__					:  Optional[int]          =							seq_length
       lowercase__					:  List[str]          =							is_training
       lowercase__					:  Union[str, Any]          =							use_input_mask
       lowercase__					:  Tuple          =							use_token_type_ids
       lowercase__					:  str          =							use_labels
       lowercase__					:  int          =							vocab_size
       lowercase__					:  Optional[Any]          =							hidden_size
       lowercase__					:  Dict          =							num_hidden_layers
       lowercase__					:  Any          =							num_attention_heads
       lowercase__					:  Dict          =							intermediate_size
       lowercase__					:  List[Any]          =							hidden_act
       lowercase__					:  int          =							hidden_dropout_prob
       lowercase__					:  Dict          =							attention_probs_dropout_prob
       lowercase__					:  Union[str, Any]          =							max_position_embeddings
       lowercase__					:  List[Any]          =							type_vocab_size
       lowercase__					:  str          =							type_sequence_label_size
       lowercase__					:  Union[str, Any]          =							initializer_range
       lowercase__					:  str          =							num_labels
       lowercase__					:  List[Any]          =							num_choices
       lowercase__					:  List[str]          =							scope






   def  __UpperCamelCase	( self							:	Dict    )   ->		Tuple:
       lowercase__					:  int          =							ids_tensor([self.batch_size, self.seq_length]      ,		self.vocab_size    )

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

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

       lowercase__					:  Any          =							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  __UpperCamelCase	( self							:	int      ,		lowercase_							:	Optional[Any]      ,		lowercase_							:	Union[str, Any]      ,		lowercase_							:	Any      ,		lowercase_							:	Optional[Any]      ,		lowercase_							:	Any      ,		lowercase_							:	List[Any]    )   ->		List[str]:
       lowercase__					:  int          =							TFMPNetModel(config=lowercase_    )
       lowercase__					:  Dict          =							{"input_ids": input_ids, "attention_mask": input_mask}
       lowercase__					:  Dict          =							model(lowercase_    )
       lowercase__					:  Tuple          =							[input_ids, input_mask]
       lowercase__					:  Any          =							model(lowercase_    )
       self.parent.assertEqual(result.last_hidden_state.shape      ,		(self.batch_size, self.seq_length, self.hidden_size)    )






   def  __UpperCamelCase	( self							:	List[Any]      ,		lowercase_							:	Optional[int]      ,		lowercase_							:	Tuple      ,		lowercase_							:	str      ,		lowercase_							:	Union[str, Any]      ,		lowercase_							:	Union[str, Any]      ,		lowercase_							:	List[Any]    )   ->		Union[str, Any]:
       lowercase__					:  List[str]          =							TFMPNetForMaskedLM(config=lowercase_    )
       lowercase__					:  Dict          =							{"input_ids": input_ids, "attention_mask": input_mask}
       lowercase__					:  Optional[int]          =							model(lowercase_    )
       self.parent.assertEqual(result.logits.shape      ,		(self.batch_size, self.seq_length, self.vocab_size)    )






   def  __UpperCamelCase	( self							:	Optional[Any]      ,		lowercase_							:	List[Any]      ,		lowercase_							:	Union[str, Any]      ,		lowercase_							:	Dict      ,		lowercase_							:	Tuple      ,		lowercase_							:	Tuple      ,		lowercase_							:	Optional[Any]    )   ->		List[Any]:
       lowercase__					:  List[Any]          =							TFMPNetForQuestionAnswering(config=lowercase_    )
       lowercase__					:  Optional[int]          =							{
           "input_ids": input_ids,
           "attention_mask": input_mask,
       }
       lowercase__					:  int          =							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  __UpperCamelCase	( self							:	Union[str, Any]      ,		lowercase_							:	List[str]      ,		lowercase_							:	List[Any]      ,		lowercase_							:	Tuple      ,		lowercase_							:	Optional[Any]      ,		lowercase_							:	Optional[int]      ,		lowercase_							:	Any    )   ->		int:
       lowercase__					:  Optional[Any]          =							self.num_labels
       lowercase__					:  int          =							TFMPNetForSequenceClassification(lowercase_    )
       lowercase__					:  Any          =							{"input_ids": input_ids, "attention_mask": input_mask}
       lowercase__					:  Optional[Any]          =							model(lowercase_    )
       self.parent.assertEqual(result.logits.shape      ,		(self.batch_size, self.num_labels)    )






   def  __UpperCamelCase	( self							:	List[str]      ,		lowercase_							:	int      ,		lowercase_							:	Optional[int]      ,		lowercase_							:	Union[str, Any]      ,		lowercase_							:	Optional[Any]      ,		lowercase_							:	List[str]      ,		lowercase_							:	List[str]    )   ->		Optional[int]:
       lowercase__					:  List[Any]          =							self.num_choices
       lowercase__					:  List[str]          =							TFMPNetForMultipleChoice(lowercase_    )
       lowercase__					:  Tuple          =							tf.tile(tf.expand_dims(lowercase_      ,		1    )      ,		(1, self.num_choices, 1)    )
       lowercase__					:  List[str]          =							tf.tile(tf.expand_dims(lowercase_      ,		1    )      ,		(1, self.num_choices, 1)    )
       lowercase__					:  Tuple          =							{
           "input_ids": multiple_choice_inputs_ids,
           "attention_mask": multiple_choice_input_mask,
       }
       lowercase__					:  List[str]          =							model(lowercase_    )
       self.parent.assertEqual(result.logits.shape      ,		(self.batch_size, self.num_choices)    )






   def  __UpperCamelCase	( self							:	Tuple      ,		lowercase_							:	Tuple      ,		lowercase_							:	str      ,		lowercase_							:	List[Any]      ,		lowercase_							:	str      ,		lowercase_							:	str      ,		lowercase_							:	Tuple    )   ->		int:
       lowercase__					:  Dict          =							self.num_labels
       lowercase__					:  int          =							TFMPNetForTokenClassification(lowercase_    )
       lowercase__					:  List[str]          =							{"input_ids": input_ids, "attention_mask": input_mask}
       lowercase__					:  Dict          =							model(lowercase_    )
       self.parent.assertEqual(result.logits.shape      ,		(self.batch_size, self.seq_length, self.num_labels)    )







   def  __UpperCamelCase	( self							:	List[Any]    )   ->		List[str]:
       lowercase__					:  int          =							self.prepare_config_and_inputs()
       ((lowercase__)   ,  (lowercase__)   ,  (lowercase__)   ,  (lowercase__)   ,  (lowercase__)   ,  (lowercase__))					:  str          =							config_and_inputs
       lowercase__					:  Union[str, Any]          =							{"input_ids": input_ids, "attention_mask": input_mask}
       return config, inputs_dict



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






   def  __UpperCamelCase	( self							:	List[Any]    )   ->		List[str]:
       lowercase__					:  Optional[int]          =							TFMPNetModelTester(self    )
       lowercase__					:  List[Any]          =							ConfigTester(self      ,		config_class=lowercase_      ,		hidden_size=37    )






   def  __UpperCamelCase	( self							:	int    )   ->		Dict:
       self.config_tester.run_common_tests()






   def  __UpperCamelCase	( self							:	Any    )   ->		Any:
       lowercase__					:  Tuple          =							self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mpnet_model(*lowercase_    )






   def  __UpperCamelCase	( self							:	Optional[Any]    )   ->		Dict:
       lowercase__					:  str          =							self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mpnet_for_masked_lm(*lowercase_    )






   def  __UpperCamelCase	( self							:	Optional[int]    )   ->		Any:
       lowercase__					:  Optional[Any]          =							self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mpnet_for_question_answering(*lowercase_    )






   def  __UpperCamelCase	( self							:	int    )   ->		List[Any]:
       lowercase__					:  Dict          =							self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mpnet_for_sequence_classification(*lowercase_    )






   def  __UpperCamelCase	( self							:	Dict    )   ->		Any:
       lowercase__					:  List[Any]          =							self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mpnet_for_multiple_choice(*lowercase_    )






   def  __UpperCamelCase	( self							:	List[Any]    )   ->		Dict:
       lowercase__					:  List[Any]          =							self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mpnet_for_token_classification(*lowercase_    )







   @slow
   def  __UpperCamelCase	( self							:	Dict    )   ->		int:
       for model_name in ["microsoft/mpnet-base"]:
           lowercase__					:  List[str]          =							TFMPNetModel.from_pretrained(lowercase_    )
           self.assertIsNotNone(lowercase_    )



@require_tf
class     snake_case_			(						unittest.TestCase			):






   @slow
   def  __UpperCamelCase	( self							:	int    )   ->		List[Any]:
       lowercase__					:  Optional[Any]          =							TFMPNetModel.from_pretrained("microsoft/mpnet-base"    )
       lowercase__					:  Tuple          =							tf.constant([[0, 1, 2, 3, 4, 5]]    )
       lowercase__					:  List[str]          =							model(lowercase_    )[0]

       lowercase__					:  List[Any]          =							[1, 6, 7_68]
       self.assertEqual(output.shape      ,		lowercase_    )

       lowercase__					:  Optional[int]          =							tf.constant(
           [
               [
                   [-0.1_06_71_72, 0.08_21_64_73, 0.0_02_45_43],
                   [-0.03_46_58_79, 0.8_35_41_18, -0.03_25_22_88],
                   [-0.06_56_94_76, -0.12_42_41_11, -0.0_49_44_36],
               ]
           ]    )
       tf.debugging.assert_near(output[:, :3, :3]      ,		lowercase_      ,		atol=1E-4    )



