"""simple docstring"""




from __future__ import annotations

import unittest

from transformers import FunnelConfig, is_tf_available
from transformers.testing_utils import require_tf

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 import (
				    TFFunnelBaseModel,
				    TFFunnelForMaskedLM,
				    TFFunnelForMultipleChoice,
				    TFFunnelForPreTraining,
				    TFFunnelForQuestionAnswering,
				    TFFunnelForSequenceClassification,
				    TFFunnelForTokenClassification,
				    TFFunnelModel,
				)
class     UpperCamelCase__:





						def __init__(       self		,__UpperCAmelCase		,__UpperCAmelCase=13		,__UpperCAmelCase=7		,__UpperCAmelCase=True		,__UpperCAmelCase=True		,__UpperCAmelCase=True		,__UpperCAmelCase=True		,__UpperCAmelCase=99		,__UpperCAmelCase=[1, 1, 2]		,__UpperCAmelCase=1		,__UpperCAmelCase=32		,__UpperCAmelCase=4		,__UpperCAmelCase=8		,__UpperCAmelCase=37		,__UpperCAmelCase="gelu_new"		,__UpperCAmelCase=0.1		,__UpperCAmelCase=0.1		,__UpperCAmelCase=0.0		,__UpperCAmelCase=5_12		,__UpperCAmelCase=3		,__UpperCAmelCase=0.0_2		,__UpperCAmelCase=3		,__UpperCAmelCase=4		,__UpperCAmelCase=None		,__UpperCAmelCase=False		,)					->				Dict:
													A__	     =							parent
													A__	     =							batch_size
													A__	     =							seq_length
													A__	     =							is_training
													A__	     =							use_input_mask
													A__	     =							use_token_type_ids
													A__	     =							use_labels
													A__	     =							vocab_size
													A__	     =							block_sizes
													A__	     =							num_decoder_layers
													A__	     =							d_model
													A__	     =							n_head
													A__	     =							d_head
													A__	     =							d_inner
													A__	     =							hidden_act
													A__	     =							hidden_dropout
													A__	     =							attention_dropout
													A__	     =							activation_dropout
													A__	     =							max_position_embeddings
													A__	     =							type_vocab_size
													A__	     =							2
													A__	     =							num_labels
													A__	     =							num_choices
													A__	     =							scope
													A__	     =							initializer_std

													# Used in the tests to check the size of the first attention layer
													A__	     =							n_head
													# Used in the tests to check the size of the first hidden state
													A__	     =							self.d_model
													# Used in the tests to check the number of output hidden states/attentions
													A__	     =							sum(self.block_sizes     ) + (0 if base else self.num_decoder_layers)
													# FunnelModel adds two hidden layers: input embeddings and the sum of the upsampled encoder hidden state with
													# the last hidden state of the first block (which is the first hidden state of the decoder).
													if not base:
																				A__	     =							self.num_hidden_layers + 2





						def 				snake_case__	(       self     )					->				Tuple:
													A__	     =							ids_tensor([self.batch_size, self.seq_length]		,self.vocab_size     )

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

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

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

													A__	     =							FunnelConfig(
													    vocab_size=self.vocab_size		,block_sizes=self.block_sizes		,num_decoder_layers=self.num_decoder_layers		,d_model=self.d_model		,n_head=self.n_head		,d_head=self.d_head		,d_inner=self.d_inner		,hidden_act=self.hidden_act		,hidden_dropout=self.hidden_dropout		,attention_dropout=self.attention_dropout		,activation_dropout=self.activation_dropout		,max_position_embeddings=self.max_position_embeddings		,type_vocab_size=self.type_vocab_size		,initializer_std=self.initializer_std		,)

													return (
													    config,
													    input_ids,
													    token_type_ids,
													    input_mask,
													    sequence_labels,
													    token_labels,
													    choice_labels,
													)





						def 				snake_case__	(       self		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,)					->				Dict:
													A__	     =							TFFunnelModel(config=__UpperCAmelCase     )
													A__	     =							{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
													A__	     =							model(__UpperCAmelCase     )

													A__	     =							[input_ids, input_mask]
													A__	     =							model(__UpperCAmelCase     )

													A__	     =							model(__UpperCAmelCase     )
													self.parent.assertEqual(result.last_hidden_state.shape		,(self.batch_size, self.seq_length, self.d_model)     )

													A__	     =							False
													A__	     =							TFFunnelModel(config=__UpperCAmelCase     )
													A__	     =							model(__UpperCAmelCase     )
													self.parent.assertEqual(result.last_hidden_state.shape		,(self.batch_size, self.seq_length, self.d_model)     )

													A__	     =							False
													A__	     =							TFFunnelModel(config=__UpperCAmelCase     )
													A__	     =							model(__UpperCAmelCase     )
													self.parent.assertEqual(result.last_hidden_state.shape		,(self.batch_size, self.seq_length, self.d_model)     )





						def 				snake_case__	(       self		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,)					->				int:
													A__	     =							TFFunnelBaseModel(config=__UpperCAmelCase     )
													A__	     =							{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
													A__	     =							model(__UpperCAmelCase     )

													A__	     =							[input_ids, input_mask]
													A__	     =							model(__UpperCAmelCase     )

													A__	     =							model(__UpperCAmelCase     )
													self.parent.assertEqual(result.last_hidden_state.shape		,(self.batch_size, 2, self.d_model)     )

													A__	     =							False
													A__	     =							TFFunnelBaseModel(config=__UpperCAmelCase     )
													A__	     =							model(__UpperCAmelCase     )
													self.parent.assertEqual(result.last_hidden_state.shape		,(self.batch_size, 3, self.d_model)     )

													A__	     =							False
													A__	     =							TFFunnelBaseModel(config=__UpperCAmelCase     )
													A__	     =							model(__UpperCAmelCase     )
													self.parent.assertEqual(result.last_hidden_state.shape		,(self.batch_size, 2, self.d_model)     )





						def 				snake_case__	(       self		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,)					->				Union[str, Any]:
													A__	     =							TFFunnelForPreTraining(config=__UpperCAmelCase     )
													A__	     =							{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
													A__	     =							model(__UpperCAmelCase     )
													self.parent.assertEqual(result.logits.shape		,(self.batch_size, self.seq_length)     )





						def 				snake_case__	(       self		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,)					->				Dict:
													A__	     =							TFFunnelForMaskedLM(config=__UpperCAmelCase     )
													A__	     =							{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
													A__	     =							model(__UpperCAmelCase     )
													self.parent.assertEqual(result.logits.shape		,(self.batch_size, self.seq_length, self.vocab_size)     )





						def 				snake_case__	(       self		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,)					->				Any:
													A__	     =							self.num_labels
													A__	     =							TFFunnelForSequenceClassification(config=__UpperCAmelCase     )
													A__	     =							{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
													A__	     =							model(__UpperCAmelCase     )
													self.parent.assertEqual(result.logits.shape		,(self.batch_size, self.num_labels)     )





						def 				snake_case__	(       self		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,)					->				List[str]:
													A__	     =							self.num_choices
													A__	     =							TFFunnelForMultipleChoice(config=__UpperCAmelCase     )
													A__	     =							tf.tile(tf.expand_dims(__UpperCAmelCase		,1     )		,(1, self.num_choices, 1)     )
													A__	     =							tf.tile(tf.expand_dims(__UpperCAmelCase		,1     )		,(1, self.num_choices, 1)     )
													A__	     =							tf.tile(tf.expand_dims(__UpperCAmelCase		,1     )		,(1, self.num_choices, 1)     )
													A__	     =							{
													    'input_ids': multiple_choice_inputs_ids,
													    'attention_mask': multiple_choice_input_mask,
													    'token_type_ids': multiple_choice_token_type_ids,
													}
													A__	     =							model(__UpperCAmelCase     )
													self.parent.assertEqual(result.logits.shape		,(self.batch_size, self.num_choices)     )





						def 				snake_case__	(       self		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,)					->				List[str]:
													A__	     =							self.num_labels
													A__	     =							TFFunnelForTokenClassification(config=__UpperCAmelCase     )
													A__	     =							{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
													A__	     =							model(__UpperCAmelCase     )
													self.parent.assertEqual(result.logits.shape		,(self.batch_size, self.seq_length, self.num_labels)     )





						def 				snake_case__	(       self		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,__UpperCAmelCase		,)					->				Tuple:
													A__	     =							TFFunnelForQuestionAnswering(config=__UpperCAmelCase     )
													A__	     =							{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
													A__	     =							model(__UpperCAmelCase     )
													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 				snake_case__	(       self     )					->				List[str]:
													A__	     =							self.prepare_config_and_inputs()
													(
													    (
													    A__
													)     ,  (
													    A__
													)     ,  (
													    A__
													)     ,  (
													    A__
													)     ,  (
													    A__
													)     ,  (
													    A__
													)     ,  (
													    A__
													)     ,  
													)	     =							config_and_inputs
													A__	     =							{'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
													return config, inputs_dict






@require_tf
class     UpperCamelCase__(			__A		,						__A		,						unittest.TestCase ):
						lowerCAmelCase__  :						Optional[int]													=		(
						    (
						        TFFunnelModel,
						        TFFunnelForMaskedLM,
						        TFFunnelForPreTraining,
						        TFFunnelForQuestionAnswering,
						        TFFunnelForTokenClassification,
						    )
						    if is_tf_available()
						    else ()
						)
						lowerCAmelCase__  :						Tuple													=		(
						    {
						        'feature-extraction': (TFFunnelBaseModel, TFFunnelModel),
						        'fill-mask': TFFunnelForMaskedLM,
						        'question-answering': TFFunnelForQuestionAnswering,
						        'text-classification': TFFunnelForSequenceClassification,
						        'token-classification': TFFunnelForTokenClassification,
						        'zero-shot': TFFunnelForSequenceClassification,
						    }
						    if is_tf_available()
						    else {}
						)
						lowerCAmelCase__  :						Union[str, Any]													=		False
						lowerCAmelCase__  :						Tuple													=		False





						def 				snake_case__	(       self     )					->				Optional[int]:
													A__	     =							TFFunnelModelTester(self     )
													A__	     =							ConfigTester(self		,config_class=__UpperCAmelCase     )





						def 				snake_case__	(       self     )					->				Dict:
													self.config_tester.run_common_tests()





						def 				snake_case__	(       self     )					->				int:
													A__	     =							self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_model(*__UpperCAmelCase     )





						def 				snake_case__	(       self     )					->				Any:
													A__	     =							self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_pretraining(*__UpperCAmelCase     )





						def 				snake_case__	(       self     )					->				Dict:
													A__	     =							self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_masked_lm(*__UpperCAmelCase     )





						def 				snake_case__	(       self     )					->				Tuple:
													A__	     =							self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_token_classification(*__UpperCAmelCase     )





						def 				snake_case__	(       self     )					->				List[Any]:
													A__	     =							self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_question_answering(*__UpperCAmelCase     )






@require_tf
class     UpperCamelCase__(			__A		,						unittest.TestCase ):
						lowerCAmelCase__  :						int													=		(
						    (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
						)
						lowerCAmelCase__  :						str													=		False
						lowerCAmelCase__  :						Optional[int]													=		False





						def 				snake_case__	(       self     )					->				List[str]:
													A__	     =							TFFunnelModelTester(self		,base=__UpperCAmelCase     )
													A__	     =							ConfigTester(self		,config_class=__UpperCAmelCase     )





						def 				snake_case__	(       self     )					->				str:
													self.config_tester.run_common_tests()





						def 				snake_case__	(       self     )					->				Tuple:
													A__	     =							self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_base_model(*__UpperCAmelCase     )





						def 				snake_case__	(       self     )					->				Optional[int]:
													A__	     =							self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_sequence_classification(*__UpperCAmelCase     )





						def 				snake_case__	(       self     )					->				Union[str, Any]:
													A__	     =							self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_multiple_choice(*__UpperCAmelCase     )






"""simple docstring"""




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     UpperCamelCase__(			unittest.TestCase ):





						def __init__(       self		,__UpperCAmelCase     )					->				str:
													A__	     =							parent





						def 				snake_case__	(       self     )					->				int:
													return {}






def   UpperCAmelCase					(	):






							"""simple docstring"""





							A__	     =							'<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>'

							A__	     =							'\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     UpperCamelCase__(			__A		,						unittest.TestCase ):
						lowerCAmelCase__  :						Dict													=		MarkupLMFeatureExtractor if is_bsa_available() else None





						def 				snake_case__	(       self     )					->				Dict:
													A__	     =							MarkupLMFeatureExtractionTester(self     )





						@property
						def 				snake_case__	(       self     )					->				Optional[Any]:
													return self.feature_extract_tester.prepare_feat_extract_dict()





						def 				snake_case__	(       self     )					->				Any:
													# Initialize feature_extractor
													A__	     =							self.feature_extraction_class()

													# Test not batched input
													A__	     =							get_html_strings()[0]
													A__	     =							feature_extractor(__UpperCAmelCase     )

													# fmt: off
													A__	     =							[['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']]
													A__	     =							[['/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		,__UpperCAmelCase     )
													self.assertEqual(encoding.xpaths		,__UpperCAmelCase     )

													# Test batched
													A__	     =							get_html_strings()
													A__	     =							feature_extractor(__UpperCAmelCase     )

													# fmt: off
													A__	     =							expected_nodes + [['My First Heading', 'My first paragraph.']]
													A__	     =							expected_xpaths + [['/html/body/h1', '/html/body/p']]

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

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





