




'''simple docstring'''







import unittest

from transformers import MarkupLMConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device
from transformers.utils import cached_property

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
					import torch

					from transformers import (
					    MarkupLMForQuestionAnswering,
					    MarkupLMForSequenceClassification,
					    MarkupLMForTokenClassification,
					    MarkupLMModel,
					)

# TODO check dependencies
from transformers import MarkupLMFeatureExtractor, MarkupLMProcessor, MarkupLMTokenizer


class    __a :

							def __init__(							self							:       List[Any]    ,       __magic_name__							:       List[Any]    ,       __magic_name__							:       Any=13    ,       __magic_name__							:       Union[str, Any]=7    ,       __magic_name__							:       Union[str, Any]=True    ,       __magic_name__							:       List[Any]=True    ,       __magic_name__							:       int=True    ,       __magic_name__							:       int=True    ,       __magic_name__							:       int=99    ,       __magic_name__							:       Optional[Any]=32    ,       __magic_name__							:       Union[str, Any]=5    ,       __magic_name__							:       int=4    ,       __magic_name__							:       Dict=37    ,       __magic_name__							:       Tuple="gelu"    ,       __magic_name__							:       str=0.1    ,       __magic_name__							:       int=0.1    ,       __magic_name__							:       Any=5_12    ,       __magic_name__							:       Dict=16    ,       __magic_name__							:       Dict=2    ,       __magic_name__							:       Union[str, Any]=0.0_2    ,       __magic_name__							:       Optional[int]=3    ,       __magic_name__							:       Tuple=None    ,       __magic_name__							:       Optional[int]=20    ,       __magic_name__							:       int=30    ,       __magic_name__							:       Tuple=2    ,       __magic_name__							:       str=2    ,       __magic_name__							:       str=10    ,       )   ->    int:







													"""simple docstring"""
													UpperCAmelCase_     : str         =					parent
													UpperCAmelCase_     : Union[str, Any]         =					batch_size
													UpperCAmelCase_     : str         =					seq_length
													UpperCAmelCase_     : int         =					is_training
													UpperCAmelCase_     : Tuple         =					use_input_mask
													UpperCAmelCase_     : int         =					use_token_type_ids
													UpperCAmelCase_     : Union[str, Any]         =					use_labels
													UpperCAmelCase_     : Union[str, Any]         =					vocab_size
													UpperCAmelCase_     : str         =					hidden_size
													UpperCAmelCase_     : Tuple         =					num_hidden_layers
													UpperCAmelCase_     : Optional[Any]         =					num_attention_heads
													UpperCAmelCase_     : int         =					intermediate_size
													UpperCAmelCase_     : List[Any]         =					hidden_act
													UpperCAmelCase_     : List[Any]         =					hidden_dropout_prob
													UpperCAmelCase_     : Optional[Any]         =					attention_probs_dropout_prob
													UpperCAmelCase_     : Union[str, Any]         =					max_position_embeddings
													UpperCAmelCase_     : Optional[int]         =					type_vocab_size
													UpperCAmelCase_     : List[Any]         =					type_sequence_label_size
													UpperCAmelCase_     : Tuple         =					initializer_range
													UpperCAmelCase_     : int         =					num_labels
													UpperCAmelCase_     : str         =					scope
													UpperCAmelCase_     : Optional[Any]         =					max_xpath_tag_unit_embeddings
													UpperCAmelCase_     : Optional[Any]         =					max_xpath_subs_unit_embeddings
													UpperCAmelCase_     : int         =					tag_pad_id
													UpperCAmelCase_     : List[str]         =					subs_pad_id
													UpperCAmelCase_     : Union[str, Any]         =					max_depth

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







													"""simple docstring"""
													UpperCAmelCase_     : Optional[Any]         =					ids_tensor([self.batch_size, self.seq_length]    ,       self.vocab_size				)

													UpperCAmelCase_     : Any         =					ids_tensor(
													    [self.batch_size, self.seq_length, self.max_depth]    ,       self.max_xpath_tag_unit_embeddings				)

													UpperCAmelCase_     : Optional[Any]         =					ids_tensor(
													    [self.batch_size, self.seq_length, self.max_depth]    ,       self.max_xpath_subs_unit_embeddings				)

													UpperCAmelCase_     : Union[str, Any]         =					None
													if self.use_input_mask:
																			UpperCAmelCase_     : Optional[Any]         =					ids_tensor([self.batch_size, self.seq_length]    ,       vocab_size=2				)

													UpperCAmelCase_     : Union[str, Any]         =					None
													if self.use_token_type_ids:
																			UpperCAmelCase_     : str         =					ids_tensor([self.batch_size, self.seq_length]    ,       self.type_vocab_size				)

													UpperCAmelCase_     : List[Any]         =					None
													UpperCAmelCase_     : List[str]         =					None
													if self.use_labels:
																			UpperCAmelCase_     : int         =					ids_tensor([self.batch_size]    ,       self.type_sequence_label_size				)
																			UpperCAmelCase_     : Dict         =					ids_tensor([self.batch_size, self.seq_length]    ,       self.num_labels				)

													UpperCAmelCase_     : int         =					self.get_config()

													return (
													    config,
													    input_ids,
													    xpath_tags_seq,
													    xpath_subs_seq,
													    token_type_ids,
													    input_mask,
													    sequence_labels,
													    token_labels,
													)

							def       UpperCAmelCase__		(							self							:       Any				)   ->    int:







													"""simple docstring"""
													return MarkupLMConfig(
													    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    ,       initializer_range=self.initializer_range    ,       max_xpath_tag_unit_embeddings=self.max_xpath_tag_unit_embeddings    ,       max_xpath_subs_unit_embeddings=self.max_xpath_subs_unit_embeddings    ,       tag_pad_id=self.tag_pad_id    ,       subs_pad_id=self.subs_pad_id    ,       max_depth=self.max_depth    ,       )

							def       UpperCAmelCase__		(							self							:       Tuple    ,       __magic_name__							:       Optional[int]    ,       __magic_name__							:       Union[str, Any]    ,       __magic_name__							:       int    ,       __magic_name__							:       Tuple    ,       __magic_name__							:       Union[str, Any]    ,       __magic_name__							:       Any    ,       __magic_name__							:       Optional[int]    ,       __magic_name__							:       List[str]    ,       )   ->    int:







													"""simple docstring"""
													UpperCAmelCase_     : Tuple         =					MarkupLMModel(config=__lowerCAmelCase				)
													model.to(__lowerCAmelCase				)
													model.eval()
													print('''Configs:'''    ,       model.config.tag_pad_id    ,       model.config.subs_pad_id				)
													UpperCAmelCase_     : Any         =					model(__lowerCAmelCase    ,       attention_mask=__lowerCAmelCase    ,       token_type_ids=__lowerCAmelCase				)
													UpperCAmelCase_     : List[str]         =					model(__lowerCAmelCase    ,       token_type_ids=__lowerCAmelCase				)
													UpperCAmelCase_     : Tuple         =					model(__lowerCAmelCase				)
													self.parent.assertEqual(result.last_hidden_state.shape    ,       (self.batch_size, self.seq_length, self.hidden_size)				)
													self.parent.assertEqual(result.pooler_output.shape    ,       (self.batch_size, self.hidden_size)				)

							def       UpperCAmelCase__		(							self							:       int    ,       __magic_name__							:       Optional[Any]    ,       __magic_name__							:       int    ,       __magic_name__							:       List[Any]    ,       __magic_name__							:       int    ,       __magic_name__							:       Any    ,       __magic_name__							:       Dict    ,       __magic_name__							:       List[str]    ,       __magic_name__							:       Any    ,       )   ->    Optional[Any]:







													"""simple docstring"""
													UpperCAmelCase_     : List[str]         =					self.num_labels
													UpperCAmelCase_     : str         =					MarkupLMForSequenceClassification(__lowerCAmelCase				)
													model.to(__lowerCAmelCase				)
													model.eval()
													UpperCAmelCase_     : List[str]         =					model(
													    __lowerCAmelCase    ,       xpath_tags_seq=__lowerCAmelCase    ,       xpath_subs_seq=__lowerCAmelCase    ,       attention_mask=__lowerCAmelCase    ,       token_type_ids=__lowerCAmelCase    ,       labels=__lowerCAmelCase    ,       )
													self.parent.assertEqual(result.logits.shape    ,       (self.batch_size, self.num_labels)				)

							def       UpperCAmelCase__		(							self							:       Any    ,       __magic_name__							:       List[Any]    ,       __magic_name__							:       int    ,       __magic_name__							:       Optional[int]    ,       __magic_name__							:       Union[str, Any]    ,       __magic_name__							:       Dict    ,       __magic_name__							:       Optional[int]    ,       __magic_name__							:       Optional[int]    ,       __magic_name__							:       str    ,       )   ->    Union[str, Any]:







													"""simple docstring"""
													UpperCAmelCase_     : Tuple         =					self.num_labels
													UpperCAmelCase_     : Tuple         =					MarkupLMForTokenClassification(config=__lowerCAmelCase				)
													model.to(__lowerCAmelCase				)
													model.eval()
													UpperCAmelCase_     : str         =					model(
													    __lowerCAmelCase    ,       xpath_tags_seq=__lowerCAmelCase    ,       xpath_subs_seq=__lowerCAmelCase    ,       attention_mask=__lowerCAmelCase    ,       token_type_ids=__lowerCAmelCase    ,       labels=__lowerCAmelCase    ,       )
													self.parent.assertEqual(result.logits.shape    ,       (self.batch_size, self.seq_length, self.num_labels)				)

							def       UpperCAmelCase__		(							self							:       Union[str, Any]    ,       __magic_name__							:       int    ,       __magic_name__							:       List[str]    ,       __magic_name__							:       Union[str, Any]    ,       __magic_name__							:       Tuple    ,       __magic_name__							:       Dict    ,       __magic_name__							:       str    ,       __magic_name__							:       List[str]    ,       __magic_name__							:       Any    ,       )   ->    Optional[Any]:







													"""simple docstring"""
													UpperCAmelCase_     : Union[str, Any]         =					MarkupLMForQuestionAnswering(config=__lowerCAmelCase				)
													model.to(__lowerCAmelCase				)
													model.eval()
													UpperCAmelCase_     : int         =					model(
													    __lowerCAmelCase    ,       xpath_tags_seq=__lowerCAmelCase    ,       xpath_subs_seq=__lowerCAmelCase    ,       attention_mask=__lowerCAmelCase    ,       token_type_ids=__lowerCAmelCase    ,       start_positions=__lowerCAmelCase    ,       end_positions=__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							:       Dict				)   ->    Tuple:







													"""simple docstring"""
													UpperCAmelCase_     : Union[str, Any]         =					self.prepare_config_and_inputs()
													(
													    (
													    UpperCAmelCase_					
													)  ,    (
													    UpperCAmelCase_					
													)  ,    (
													    UpperCAmelCase_					
													)  ,    (
													    UpperCAmelCase_					
													)  ,    (
													    UpperCAmelCase_					
													)  ,    (
													    UpperCAmelCase_					
													)  ,    (
													    UpperCAmelCase_					
													)  ,    (
													    UpperCAmelCase_					
													)  ,    					
													)     : Tuple         =					config_and_inputs
													UpperCAmelCase_     : List[Any]         =					{
													    '''input_ids''': input_ids,
													    '''xpath_tags_seq''': xpath_tags_seq,
													    '''xpath_subs_seq''': xpath_subs_seq,
													    '''token_type_ids''': token_type_ids,
													    '''attention_mask''': input_mask,
													}
													return config, inputs_dict





@require_torch
class    __a (lowerCAmelCase__    ,						lowerCAmelCase__    ,						unittest.TestCase       ):
							__a   :				Optional[Any]       =    (
							    (
							        MarkupLMModel,
							        MarkupLMForSequenceClassification,
							        MarkupLMForTokenClassification,
							        MarkupLMForQuestionAnswering,
							    )
							    if is_torch_available()
							    else None
							)
							__a   :				Union[str, Any]       =    (
							    {
							        '''feature-extraction''': MarkupLMModel,
							        '''question-answering''': MarkupLMForQuestionAnswering,
							        '''text-classification''': MarkupLMForSequenceClassification,
							        '''token-classification''': MarkupLMForTokenClassification,
							        '''zero-shot''': MarkupLMForSequenceClassification,
							    }
							    if is_torch_available()
							    else {}
							)

							def       UpperCAmelCase__		(							self							:       Optional[Any]    ,       __magic_name__							:       Union[str, Any]    ,       __magic_name__							:       Optional[int]    ,       __magic_name__							:       Union[str, Any]    ,       __magic_name__							:       Any    ,       __magic_name__							:       List[str]				)   ->    List[Any]:







													"""simple docstring"""
													return True

							def       UpperCAmelCase__		(							self							:       Tuple				)   ->    Union[str, Any]:







													"""simple docstring"""
													UpperCAmelCase_     : Any         =					MarkupLMModelTester(self				)
													UpperCAmelCase_     : Union[str, Any]         =					ConfigTester(self    ,       config_class=__lowerCAmelCase    ,       hidden_size=37				)

							def       UpperCAmelCase__		(							self							:       Optional[int]				)   ->    Union[str, Any]:







													"""simple docstring"""
													self.config_tester.run_common_tests()

							def       UpperCAmelCase__		(							self							:       int				)   ->    List[Any]:







													"""simple docstring"""
													UpperCAmelCase_     : Dict         =					self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_model(*__lowerCAmelCase				)

							def       UpperCAmelCase__		(							self							:       Dict				)   ->    Union[str, Any]:







													"""simple docstring"""
													UpperCAmelCase_     : Any         =					self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_sequence_classification(*__lowerCAmelCase				)

							def       UpperCAmelCase__		(							self							:       str				)   ->    Optional[Any]:







													"""simple docstring"""
													UpperCAmelCase_     : int         =					self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_token_classification(*__lowerCAmelCase				)



							def       UpperCAmelCase__		(							self							:       List[Any]				)   ->    int:







													"""simple docstring"""
													UpperCAmelCase_     : Union[str, Any]         =					self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_question_answering(*__lowerCAmelCase				)





def     lowerCamelCase_ (					)	->		Tuple:
						UpperCAmelCase_     : Union[str, Any]         =					'''
    <!DOCTYPE html>
    <html>
    <head>
    <title>Page Title</title>
    </head>
    <body>

    <h1>This is a Heading</h1>
    <p>This is a paragraph.</p>

    </body>
    </html>
    '''

						return html_string


@require_torch
class    __a (unittest.TestCase       ):

							@cached_property
							def       UpperCAmelCase__		(							self							:       Optional[int]				)   ->    str:







													"""simple docstring"""
													UpperCAmelCase_     : Any         =					MarkupLMFeatureExtractor()
													UpperCAmelCase_     : str         =					MarkupLMTokenizer.from_pretrained('''microsoft/markuplm-base'''				)

													return MarkupLMProcessor(__lowerCAmelCase    ,       __lowerCAmelCase				)



							@slow
							def       UpperCAmelCase__		(							self							:       Tuple				)   ->    Tuple:







													"""simple docstring"""
													UpperCAmelCase_     : Optional[int]         =					MarkupLMModel.from_pretrained('''microsoft/markuplm-base'''				).to(__lowerCAmelCase				)

													UpperCAmelCase_     : Optional[int]         =					self.default_processor

													UpperCAmelCase_     : Any         =					processor(prepare_html_string()    ,       return_tensors='''pt'''				)
													UpperCAmelCase_     : Optional[Any]         =					inputs.to(__lowerCAmelCase				)

													# forward pass
													with torch.no_grad():
																			UpperCAmelCase_     : Optional[Any]         =					model(**__lowerCAmelCase				)

													# verify the last hidden states
													UpperCAmelCase_     : Union[str, Any]         =					torch.Size([1, 14, 7_68]				)
													self.assertEqual(outputs.last_hidden_state.shape    ,       __lowerCAmelCase				)

													UpperCAmelCase_     : List[str]         =					torch.tensor(
													    [[0.0_6_7_5, -0.0_0_5_2, 0.5_0_0_1], [-0.2_2_8_1, 0.0_8_0_2, 0.2_1_9_2], [-0.0_5_8_3, -0.3_3_1_1, 0.1_1_8_5]]				).to(__lowerCAmelCase				)

													self.assertTrue(torch.allclose(outputs.last_hidden_state[0, :3, :3]    ,       __lowerCAmelCase    ,       atol=1E-4				)				)












'''simple docstring'''







from transformers import SqueezeBertTokenizer, SqueezeBertTokenizerFast
from transformers.testing_utils import require_tokenizers, slow

from ..bert.test_tokenization_bert import BertTokenizationTest


@require_tokenizers
class    __a (lowerCamelCase       ):
							__a   :				Any       =    SqueezeBertTokenizer
							__a   :				Dict       =    SqueezeBertTokenizerFast
							__a   :				Any       =    True

							def       UpperCAmelCase__		(							self							:       Union[str, Any]    ,       **__magic_name__							:       Dict				)   ->    int:







													"""simple docstring"""
													return SqueezeBertTokenizerFast.from_pretrained(self.tmpdirname    ,       **__magic_name__				)



							@slow
							def       UpperCAmelCase__		(							self							:       Union[str, Any]				)   ->    int:







													"""simple docstring"""
													UpperCAmelCase_     : List[str]         =					SqueezeBertTokenizer.from_pretrained('''squeezebert/squeezebert-mnli-headless'''				)

													UpperCAmelCase_     : Any         =					tokenizer.encode('''sequence builders'''    ,       add_special_tokens=__magic_name__				)
													UpperCAmelCase_     : Optional[Any]         =					tokenizer.encode('''multi-sequence build'''    ,       add_special_tokens=__magic_name__				)

													UpperCAmelCase_     : List[Any]         =					tokenizer.build_inputs_with_special_tokens(__magic_name__				)
													UpperCAmelCase_     : Any         =					tokenizer.build_inputs_with_special_tokens(__magic_name__    ,       __magic_name__				)

													assert encoded_sentence == [tokenizer.cls_token_id] + text + [tokenizer.sep_token_id]
													assert encoded_pair == [tokenizer.cls_token_id] + text + [tokenizer.sep_token_id] + text_a + [
													    tokenizer.sep_token_id
													]





