
"""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 	__snake_case      :





 """simple docstring"""


 def __init__(					self      ,		__lowerCamelCase      ,		__lowerCamelCase=13      ,		__lowerCamelCase=7      ,		__lowerCamelCase=True      ,		__lowerCamelCase=True      ,		__lowerCamelCase=False      ,		__lowerCamelCase=True      ,		__lowerCamelCase=99      ,		__lowerCamelCase=64      ,		__lowerCamelCase=2      ,		__lowerCamelCase=4      ,		__lowerCamelCase=64      ,		__lowerCamelCase="gelu"      ,		__lowerCamelCase=0.1      ,		__lowerCamelCase=0.1      ,		__lowerCamelCase=512      ,		__lowerCamelCase=16      ,		__lowerCamelCase=2      ,		__lowerCamelCase=0.0_2      ,		__lowerCamelCase=3      ,		__lowerCamelCase=4      ,		__lowerCamelCase=None      ,		):



     '''simple docstring'''




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

 def       UpperCamelCase__(					self						):



     '''simple docstring'''




     __A					:		Optional[int]						=  ids_tensor([self.batch_size, self.seq_length]      ,		self.vocab_size						)

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

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

     __A					:		Tuple						=  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      ,		__lowerCamelCase      ,		__lowerCamelCase      ,		__lowerCamelCase      ,		__lowerCamelCase      ,		__lowerCamelCase      ,		__lowerCamelCase						):



     '''simple docstring'''




     __A					:		Any						=  TFMPNetModel(config=lowerCAmelCase_						)
     __A					:		str						=  {'''input_ids''': input_ids, '''attention_mask''': input_mask}
     __A					:		List[Any]						=  model(lowerCAmelCase_						)
     __A					:		List[Any]						=  [input_ids, input_mask]
     __A					:		Optional[int]						=  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						):



     '''simple docstring'''




     __A					:		List[str]						=  TFMPNetForMaskedLM(config=lowerCAmelCase_						)
     __A					:		Optional[Any]						=  {'''input_ids''': input_ids, '''attention_mask''': input_mask}
     __A					:		List[Any]						=  model(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						):



     '''simple docstring'''




     __A					:		Any						=  TFMPNetForQuestionAnswering(config=lowerCAmelCase_						)
     __A					:		int						=  {
         '''input_ids''': input_ids,
         '''attention_mask''': input_mask,
     }
     __A					:		Union[str, Any]						=  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       UpperCamelCase__(					self      ,		__lowerCamelCase      ,		__lowerCamelCase      ,		__lowerCamelCase      ,		__lowerCamelCase      ,		__lowerCamelCase      ,		__lowerCamelCase						):



     '''simple docstring'''




     __A					:		Optional[int]						=  self.num_labels
     __A					:		List[Any]						=  TFMPNetForSequenceClassification(lowerCAmelCase_						)
     __A					:		Dict						=  {'''input_ids''': input_ids, '''attention_mask''': input_mask}
     __A					:		List[Any]						=  model(lowerCAmelCase_						)
     self.parent.assertEqual(result.logits.shape      ,		(self.batch_size, self.num_labels)						)

 def       UpperCamelCase__(					self      ,		__lowerCamelCase      ,		__lowerCamelCase      ,		__lowerCamelCase      ,		__lowerCamelCase      ,		__lowerCamelCase      ,		__lowerCamelCase						):



     '''simple docstring'''




     __A					:		Optional[Any]						=  self.num_choices
     __A					:		Dict						=  TFMPNetForMultipleChoice(lowerCAmelCase_						)
     __A					:		str						=  tf.tile(tf.expand_dims(lowerCAmelCase_      ,		1						)      ,		(1, self.num_choices, 1)						)
     __A					:		Any						=  tf.tile(tf.expand_dims(lowerCAmelCase_      ,		1						)      ,		(1, self.num_choices, 1)						)
     __A					:		Optional[Any]						=  {
         '''input_ids''': multiple_choice_inputs_ids,
         '''attention_mask''': multiple_choice_input_mask,
     }
     __A					:		Union[str, Any]						=  model(lowerCAmelCase_						)
     self.parent.assertEqual(result.logits.shape      ,		(self.batch_size, self.num_choices)						)

 def       UpperCamelCase__(					self      ,		__lowerCamelCase      ,		__lowerCamelCase      ,		__lowerCamelCase      ,		__lowerCamelCase      ,		__lowerCamelCase      ,		__lowerCamelCase						):



     '''simple docstring'''




     __A					:		Optional[Any]						=  self.num_labels
     __A					:		Union[str, Any]						=  TFMPNetForTokenClassification(lowerCAmelCase_						)
     __A					:		Optional[Any]						=  {'''input_ids''': input_ids, '''attention_mask''': input_mask}
     __A					:		int						=  model(lowerCAmelCase_						)
     self.parent.assertEqual(result.logits.shape      ,		(self.batch_size, self.seq_length, self.num_labels)						)







 def       UpperCamelCase__(					self						):



     '''simple docstring'''




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






@require_tf
class 	__snake_case      (	lowerCAmelCase__							,							lowerCAmelCase__							,							unittest.TestCase  ):





 """simple docstring"""


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

 def       UpperCamelCase__(					self						):



     '''simple docstring'''




     __A					:		str						=  TFMPNetModelTester(self						)
     __A					:		Any						=  ConfigTester(self      ,		config_class=lowerCAmelCase_      ,		hidden_size=37						)

 def       UpperCamelCase__(					self						):



     '''simple docstring'''




     self.config_tester.run_common_tests()

 def       UpperCamelCase__(					self						):



     '''simple docstring'''




     __A					:		Optional[Any]						=  self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_mpnet_model(*lowerCAmelCase_						)

 def       UpperCamelCase__(					self						):



     '''simple docstring'''




     __A					:		Dict						=  self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_mpnet_for_masked_lm(*lowerCAmelCase_						)

 def       UpperCamelCase__(					self						):



     '''simple docstring'''




     __A					:		str						=  self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_mpnet_for_question_answering(*lowerCAmelCase_						)

 def       UpperCamelCase__(					self						):



     '''simple docstring'''




     __A					:		Dict						=  self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_mpnet_for_sequence_classification(*lowerCAmelCase_						)

 def       UpperCamelCase__(					self						):



     '''simple docstring'''




     __A					:		List[str]						=  self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_mpnet_for_multiple_choice(*lowerCAmelCase_						)

 def       UpperCamelCase__(					self						):



     '''simple docstring'''




     __A					:		List[str]						=  self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_mpnet_for_token_classification(*lowerCAmelCase_						)







 @slow
 def       UpperCamelCase__(					self						):



     '''simple docstring'''




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






@require_tf
class 	__snake_case      (	unittest.TestCase  ):





 """simple docstring"""


 @slow
 def       UpperCamelCase__(					self						):



     '''simple docstring'''




     __A					:		Optional[int]						=  TFMPNetModel.from_pretrained('''microsoft/mpnet-base'''						)
     __A					:		int						=  tf.constant([[0, 1, 2, 3, 4, 5]]						)
     __A					:		str						=  model(lowerCAmelCase_						)[0]

     __A					:		Any						=  [1, 6, 768]
     self.assertEqual(output.shape      ,		lowerCAmelCase_						)

     __A					:		str						=  tf.constant(
         [
             [
                 [-0.1_0_6_7_1_7_2, 0.0_8_2_1_6_4_7_3, 0.0_0_2_4_5_4_3],
                 [-0.0_3_4_6_5_8_7_9, 0.8_3_5_4_1_1_8, -0.0_3_2_5_2_2_8_8],
                 [-0.0_6_5_6_9_4_7_6, -0.1_2_4_2_4_1_1_1, -0.0_4_9_4_4_3_6],
             ]
         ]						)
     tf.debugging.assert_near(output[:, :3, :3]      ,		lowerCAmelCase_      ,		atol=1e-4						)











"""simple docstring"""



import unittest

from transformers import load_tool

from .test_tools_common import ToolTesterMixin


a_				=    """
Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf originally as a company that developed a chatbot app targeted at teenagers.[2] After open-sourcing the model behind the chatbot, the company pivoted to focus on being a platform for machine learning.

In March 2021, Hugging Face raised $40 million in a Series B funding round.[3]

On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model.[4] In 2022, the workshop concluded with the announcement of BLOOM, a multilingual large language model with 176 billion parameters.[5]
"""






class 	__snake_case      (	unittest.TestCase							,							SCREAMING_SNAKE_CASE__  ):





 """simple docstring"""


 def       UpperCamelCase__(					self						):



     '''simple docstring'''




     __A					:		Optional[Any]						=  load_tool('''summarization'''						)
     self.tool.setup()
     __A					:		Tuple						=  load_tool('''summarization'''      ,		remote=__lowerCamelCase						)

 def       UpperCamelCase__(					self						):



     '''simple docstring'''




     __A					:		List[str]						=  self.tool(__lowerCamelCase						)
     self.assertEqual(
         __lowerCamelCase      ,		'''Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM.'''      ,		)

 def       UpperCamelCase__(					self						):



     '''simple docstring'''




     __A					:		int						=  self.remote_tool(__lowerCamelCase						)
     self.assertEqual(
         __lowerCamelCase      ,		'''Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM.'''      ,		)

 def       UpperCamelCase__(					self						):



     '''simple docstring'''




     __A					:		List[Any]						=  self.tool(text=__lowerCamelCase						)
     self.assertEqual(
         __lowerCamelCase      ,		'''Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM.'''      ,		)







 def       UpperCamelCase__(					self						):



     '''simple docstring'''




     __A					:		Optional[int]						=  self.remote_tool(text=__lowerCamelCase						)
     self.assertEqual(
         __lowerCamelCase      ,		'''Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM.'''      ,		)




