





import unittest

import numpy as np

from transformers import RoFormerConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask


if is_flax_available():
		import jax.numpy as jnp

		from transformers.models.roformer.modeling_flax_roformer import (
		    FlaxRoFormerForMaskedLM,
		    FlaxRoFormerForMultipleChoice,
		    FlaxRoFormerForQuestionAnswering,
		    FlaxRoFormerForSequenceClassification,
		    FlaxRoFormerForTokenClassification,
		    FlaxRoFormerModel,
		)

class 		snake_case_   (							unittest.TestCase						):







	'''simple docstring'''




	def __init__(						self							:     List[str]					,      __lowerCamelCase							:     Union[str, Any]					,      __lowerCamelCase							:     List[str]=13					,      __lowerCamelCase							:     Dict=7					,      __lowerCamelCase							:     Dict=True					,      __lowerCamelCase							:     str=True					,      __lowerCamelCase							:     str=True					,      __lowerCamelCase							:     Tuple=True					,      __lowerCamelCase							:     str=99					,      __lowerCamelCase							:     Optional[int]=32					,      __lowerCamelCase							:     Dict=5					,      __lowerCamelCase							:     Optional[Any]=4					,      __lowerCamelCase							:     Optional[Any]=37					,      __lowerCamelCase							:     int="gelu"					,      __lowerCamelCase							:     Optional[Any]=0.1					,      __lowerCamelCase							:     List[str]=0.1					,      __lowerCamelCase							:     List[Any]=512					,      __lowerCamelCase							:     Any=16					,      __lowerCamelCase							:     List[str]=2					,      __lowerCamelCase							:     Tuple=0.02					,      __lowerCamelCase							:     int=4					,      )       -> Optional[Any]:

			'''simple docstring'''




			__lowercase											=     parent
			__lowercase											=     batch_size
			__lowercase											=     seq_length
			__lowercase											=     is_training
			__lowercase											=     use_attention_mask
			__lowercase											=     use_token_type_ids
			__lowercase											=     use_labels
			__lowercase											=     vocab_size
			__lowercase											=     hidden_size
			__lowercase											=     num_hidden_layers
			__lowercase											=     num_attention_heads
			__lowercase											=     intermediate_size
			__lowercase											=     hidden_act
			__lowercase											=     hidden_dropout_prob
			__lowercase											=     attention_probs_dropout_prob
			__lowercase											=     max_position_embeddings
			__lowercase											=     type_vocab_size
			__lowercase											=     type_sequence_label_size
			__lowercase											=     initializer_range
			__lowercase											=     num_choices




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

			'''simple docstring'''




			__lowercase											=     ids_tensor([self.batch_size, self.seq_length]					,      self.vocab_size   )

			__lowercase											=     None
			if self.use_attention_mask:
					__lowercase											=     random_attention_mask([self.batch_size, self.seq_length]   )

			__lowercase											=     None
			if self.use_token_type_ids:
					__lowercase											=     ids_tensor([self.batch_size, self.seq_length]					,      self.type_vocab_size   )

			__lowercase											=     RoFormerConfig(
			    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					,      type_vocab_size=self.type_vocab_size					,      is_decoder=__lowerCamelCase					,      initializer_range=self.initializer_range					,      )

			return config, input_ids, token_type_ids, attention_mask






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

			'''simple docstring'''




			__lowercase											=     self.prepare_config_and_inputs()
			__lowercase											=     config_and_inputs
			__lowercase											=     {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": attention_mask}
			return config, inputs_dict





@require_flax
class 		snake_case_   (							__lowercase     ,     unittest.TestCase						):







	'''simple docstring'''
	__UpperCamelCase   =		True

	__UpperCamelCase   =		(
	    (
	        FlaxRoFormerModel,
	        FlaxRoFormerForMaskedLM,
	        FlaxRoFormerForSequenceClassification,
	        FlaxRoFormerForTokenClassification,
	        FlaxRoFormerForMultipleChoice,
	        FlaxRoFormerForQuestionAnswering,
	    )
	    if is_flax_available()
	    else ()
	)




	def    UpperCAmelCase			(						self							:     Any   )       -> str:

			'''simple docstring'''




			__lowercase											=     FlaxRoFormerModelTester(self   )






	@slow
	def    UpperCAmelCase			(						self							:     Any   )       -> str:

			'''simple docstring'''




			for model_class_name in self.all_model_classes:
					__lowercase											=     model_class_name.from_pretrained('junnyu/roformer_chinese_small'					,      from_pt=__lowerCamelCase   )
					__lowercase											=     model(np.ones((1, 1)   )   )
					self.assertIsNotNone(__lowerCamelCase   )





@require_flax
class 		snake_case_   (							unittest.TestCase						):







	'''simple docstring'''




	@slow
	def    UpperCAmelCase			(						self							:     Any   )       -> int:

			'''simple docstring'''




			__lowercase											=     FlaxRoFormerForMaskedLM.from_pretrained('junnyu/roformer_chinese_base'   )
			__lowercase											=     jnp.array([[0, 1, 2, 3, 4, 5]]   )
			__lowercase											=     model(__lowerCamelCase   )[0]

			__lowercase											=     50_000

			__lowercase											=     (1, 6, vocab_size)
			self.assertEqual(output.shape					,      __lowerCamelCase   )

			__lowercase											=     jnp.array(
			    [[[-0.1205, -1.0265, 0.2922], [-1.5134, 0.1974, 0.1519], [-5.0135, -3.9003, -0.8404]]]   )

			self.assertTrue(jnp.allclose(output[:, :3, :3]					,      __lowerCamelCase					,      atol=1E-4   )   )






import unittest

from transformers.testing_utils import require_bsa
from transformers.utils import is_bsa_available

from ...test_feature_extraction_common import FeatureExtractionSavingTestMixin


if is_bsa_available():
		from transformers import MarkupLMFeatureExtractor




class 					lowerCamelCase__				(							unittest.TestCase):




	'''simple docstring'''




	def __init__(   self						:Optional[int]	,  a						:List[str]		)						->					Union[str, Any]:
								__UpperCamelCase      :  Dict       =   parent







	def   _lowerCamelCase							(   self						:Dict		)						->					int:
								return {}




def       _SCREAMING_SNAKE_CASE   (						)   ->       Optional[Any]:






							'''simple docstring'''





							__UpperCamelCase      :  Union[str, Any]       =   "<HTML>\n\n    <HEAD>\n    <TITLE>sample document</TITLE>\n    </HEAD>\n\n    <BODY BGCOLOR=\"FFFFFF\">\n    <HR>\n    <a href=\"http://google.com\">Goog</a>\n    <H1>This is one header</H1>\n    <H2>This is a another Header</H2>\n    <P>Travel from\n        <P>\n        <B>SFO to JFK</B>\n        <BR>\n        <B><I>on May 2, 2015 at 2:00 pm. For details go to confirm.com </I></B>\n        <HR>\n        <div style=\"color:#0000FF\">\n            <h3>Traveler <b> name </b> is\n            <p> John Doe </p>\n        </div>"

							__UpperCamelCase      :  Optional[int]       =   "\n    <!DOCTYPE html>\n    <html>\n    <body>\n\n    <h1>My First Heading</h1>\n    <p>My first paragraph.</p>\n\n    </body>\n    </html>\n    "

							return [html_string_a, html_string_a]




@require_bsa
class 					lowerCamelCase__				(							__lowercase	,		unittest.TestCase):




	'''simple docstring'''




	_A								=	MarkupLMFeatureExtractor if is_bsa_available() else None







	def   _lowerCamelCase							(   self						:List[str]		)						->					str:
								__UpperCamelCase      :  List[str]       =   MarkupLMFeatureExtractionTester(self		)







	@property
	def   _lowerCamelCase							(   self						:List[Any]		)						->					List[str]:
								return self.feature_extract_tester.prepare_feat_extract_dict()







	def   _lowerCamelCase							(   self						:Dict		)						->					Dict:
								# Initialize feature_extractor
								__UpperCamelCase      :  Tuple       =   self.feature_extraction_class()

								# Test not batched input
								__UpperCamelCase      :  Union[str, Any]       =   get_html_strings()[0]
								__UpperCamelCase      :  Any       =   feature_extractor(a		)

								# fmt: off
								__UpperCamelCase      :  Union[str, Any]       =   [["sample document", "Goog", "This is one header", "This is a another Header", "Travel from", "SFO to JFK", "on May 2, 2015 at 2:00 pm. For details go to confirm.com", "Traveler", "name", "is", "John Doe"]]
								__UpperCamelCase      :  Tuple       =   [["/html/head/title", "/html/body/a", "/html/body/h1", "/html/body/h2", "/html/body/p", "/html/body/p/p/b[1]", "/html/body/p/p/b[2]/i", "/html/body/p/p/div/h3", "/html/body/p/p/div/h3/b", "/html/body/p/p/div/h3", "/html/body/p/p/div/h3/p"]]
								# fmt: on

								self.assertEqual(encoding.nodes	,  a		)
								self.assertEqual(encoding.xpaths	,  a		)

								# Test batched
								__UpperCamelCase      :  str       =   get_html_strings()
								__UpperCamelCase      :  List[Any]       =   feature_extractor(a		)

								# fmt: off
								__UpperCamelCase      :  Optional[int]       =   expected_nodes + [["My First Heading", "My first paragraph."]]
								__UpperCamelCase      :  Tuple       =   expected_xpaths + [["/html/body/h1", "/html/body/p"]]

								self.assertEqual(len(encoding.nodes		)	,  2		)
								self.assertEqual(len(encoding.xpaths		)	,  2		)

								self.assertEqual(encoding.nodes	,  a		)
								self.assertEqual(encoding.xpaths	,  a		)