





'''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 lowerCamelCase    :







  def __init__(		self  ,  lowercase__  ,  lowercase__=13  ,  lowercase__=7  ,  lowercase__=True  ,  lowercase__=True  ,  lowercase__=True  ,  lowercase__=True  ,  lowercase__=99  ,  lowercase__=32  ,  lowercase__=5  ,  lowercase__=4  ,  lowercase__=37  ,  lowercase__="gelu"  ,  lowercase__=0.1  ,  lowercase__=0.1  ,  lowercase__=512  ,  lowercase__=16  ,  lowercase__=2  ,  lowercase__=0.02  ,  lowercase__=3  ,  lowercase__=None  ,  lowercase__=20  ,  lowercase__=30  ,  lowercase__=2  ,  lowercase__=2  ,  lowercase__=10  ,  )		->    Dict:






        """simple docstring"""





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







  def 					UpperCAmelCase_					(		self		)		->    str:






        """simple docstring"""





        _snake_case		:						Any         =  ids_tensor([self.batch_size, self.seq_length]  ,  self.vocab_size		)

        _snake_case		:						Dict         =  ids_tensor(
            [self.batch_size, self.seq_length, self.max_depth]  ,  self.max_xpath_tag_unit_embeddings		)

        _snake_case		:						Dict         =  ids_tensor(
            [self.batch_size, self.seq_length, self.max_depth]  ,  self.max_xpath_subs_unit_embeddings		)

        _snake_case		:						Any         =  None
        if self.use_input_mask:
              _snake_case		:						List[str]         =  ids_tensor([self.batch_size, self.seq_length]  ,  vocab_size=2		)

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

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

        _snake_case		:						str         =  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		)		->    str:






        """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  ,  lowercase__  ,  lowercase__  ,  lowercase__  ,  lowercase__  ,  lowercase__  ,  lowercase__  ,  lowercase__  ,  lowercase__  ,  )		->    List[Any]:






        """simple docstring"""





        _snake_case		:						int         =  MarkupLMModel(config=__UpperCamelCase		)
        model.to(__UpperCamelCase		)
        model.eval()
        print('''Configs:'''  ,  model.config.tag_pad_id  ,  model.config.subs_pad_id		)
        _snake_case		:						Tuple         =  model(__UpperCamelCase  ,  attention_mask=__UpperCamelCase  ,  token_type_ids=__UpperCamelCase		)
        _snake_case		:						int         =  model(__UpperCamelCase  ,  token_type_ids=__UpperCamelCase		)
        _snake_case		:						Any         =  model(__UpperCamelCase		)
        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  ,  lowercase__  ,  lowercase__  ,  lowercase__  ,  lowercase__  ,  lowercase__  ,  lowercase__  ,  lowercase__  ,  lowercase__  ,  )		->    List[Any]:






        """simple docstring"""





        _snake_case		:						Optional[int]         =  self.num_labels
        _snake_case		:						Tuple         =  MarkupLMForSequenceClassification(__UpperCamelCase		)
        model.to(__UpperCamelCase		)
        model.eval()
        _snake_case		:						str         =  model(
            __UpperCamelCase  ,  xpath_tags_seq=__UpperCamelCase  ,  xpath_subs_seq=__UpperCamelCase  ,  attention_mask=__UpperCamelCase  ,  token_type_ids=__UpperCamelCase  ,  labels=__UpperCamelCase  ,  )
        self.parent.assertEqual(result.logits.shape  ,  (self.batch_size, self.num_labels)		)







  def 					UpperCAmelCase_					(		self  ,  lowercase__  ,  lowercase__  ,  lowercase__  ,  lowercase__  ,  lowercase__  ,  lowercase__  ,  lowercase__  ,  lowercase__  ,  )		->    Any:






        """simple docstring"""





        _snake_case		:						Union[str, Any]         =  self.num_labels
        _snake_case		:						str         =  MarkupLMForTokenClassification(config=__UpperCamelCase		)
        model.to(__UpperCamelCase		)
        model.eval()
        _snake_case		:						Dict         =  model(
            __UpperCamelCase  ,  xpath_tags_seq=__UpperCamelCase  ,  xpath_subs_seq=__UpperCamelCase  ,  attention_mask=__UpperCamelCase  ,  token_type_ids=__UpperCamelCase  ,  labels=__UpperCamelCase  ,  )
        self.parent.assertEqual(result.logits.shape  ,  (self.batch_size, self.seq_length, self.num_labels)		)







  def 					UpperCAmelCase_					(		self  ,  lowercase__  ,  lowercase__  ,  lowercase__  ,  lowercase__  ,  lowercase__  ,  lowercase__  ,  lowercase__  ,  lowercase__  ,  )		->    Dict:






        """simple docstring"""





        _snake_case		:						Dict         =  MarkupLMForQuestionAnswering(config=__UpperCamelCase		)
        model.to(__UpperCamelCase		)
        model.eval()
        _snake_case		:						Tuple         =  model(
            __UpperCamelCase  ,  xpath_tags_seq=__UpperCamelCase  ,  xpath_subs_seq=__UpperCamelCase  ,  attention_mask=__UpperCamelCase  ,  token_type_ids=__UpperCamelCase  ,  start_positions=__UpperCamelCase  ,  end_positions=__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 					UpperCAmelCase_					(		self		)		->    Optional[int]:






        """simple docstring"""





        _snake_case		:						Optional[int]         =  self.prepare_config_and_inputs()
        (
            _snake_case						
        )		:						List[str]         =  config_and_inputs
        _snake_case		:						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 lowerCamelCase    (lowerCAmelCase_    ,   lowerCAmelCase_    ,   unittest.TestCase       ):
  _lowercase	:						Union[str, Any]							       =					(
      (
          MarkupLMModel,
          MarkupLMForSequenceClassification,
          MarkupLMForTokenClassification,
          MarkupLMForQuestionAnswering,
      )
      if is_torch_available()
      else None
  )
  _lowercase	:						int							       =					(
      {
          """feature-extraction""": MarkupLMModel,
          """question-answering""": MarkupLMForQuestionAnswering,
          """text-classification""": MarkupLMForSequenceClassification,
          """token-classification""": MarkupLMForTokenClassification,
          """zero-shot""": MarkupLMForSequenceClassification,
      }
      if is_torch_available()
      else {}
  )







  def 					UpperCAmelCase_					(		self  ,  lowercase__  ,  lowercase__  ,  lowercase__  ,  lowercase__  ,  lowercase__		)		->    Union[str, Any]:






        """simple docstring"""





        return True







  def 					UpperCAmelCase_					(		self		)		->    Tuple:






        """simple docstring"""





        _snake_case		:						str         =  MarkupLMModelTester(self		)
        _snake_case		:						str         =  ConfigTester(self  ,  config_class=__UpperCamelCase  ,  hidden_size=37		)







  def 					UpperCAmelCase_					(		self		)		->    int:






        """simple docstring"""





        self.config_tester.run_common_tests()







  def 					UpperCAmelCase_					(		self		)		->    int:






        """simple docstring"""





        _snake_case		:						List[Any]         =  self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*__UpperCamelCase		)







  def 					UpperCAmelCase_					(		self		)		->    Optional[Any]:






        """simple docstring"""





        _snake_case		:						Union[str, Any]         =  self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_sequence_classification(*__UpperCamelCase		)







  def 					UpperCAmelCase_					(		self		)		->    str:






        """simple docstring"""





        _snake_case		:						List[Any]         =  self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_token_classification(*__UpperCamelCase		)







  def 					UpperCAmelCase_					(		self		)		->    Tuple:






        """simple docstring"""





        _snake_case		:						Dict         =  self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_question_answering(*__UpperCamelCase		)




def  _a     (				):





      """simple docstring"""



      _snake_case		:						Optional[Any]         =  "\n    <!DOCTYPE html>\n    <html>\n    <head>\n    <title>Page Title</title>\n    </head>\n    <body>\n\n    <h1>This is a Heading</h1>\n    <p>This is a paragraph.</p>\n\n    </body>\n    </html>\n    "

      return html_string





@require_torch
class lowerCamelCase    (unittest.TestCase       ):







  @cached_property
  def 					UpperCAmelCase_					(		self		)		->    int:






        """simple docstring"""





        _snake_case		:						Dict         =  MarkupLMFeatureExtractor()
        _snake_case		:						List[str]         =  MarkupLMTokenizer.from_pretrained('''microsoft/markuplm-base'''		)

        return MarkupLMProcessor(__UpperCamelCase  ,  __UpperCamelCase		)







  @slow
  def 					UpperCAmelCase_					(		self		)		->    Tuple:






        """simple docstring"""





        _snake_case		:						str         =  MarkupLMModel.from_pretrained('''microsoft/markuplm-base'''		).to(__UpperCamelCase		)

        _snake_case		:						Union[str, Any]         =  self.default_processor

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

        # forward pass
        with torch.no_grad():
              _snake_case		:						Union[str, Any]         =  model(**__UpperCamelCase		)

        # verify the last hidden states
        _snake_case		:						List[str]         =  torch.Size([1, 14, 768]		)
        self.assertEqual(outputs.last_hidden_state.shape  ,  __UpperCamelCase		)

        _snake_case		:						str         =  torch.tensor(
            [[0.0_675, -0.0_052, 0.5_001], [-0.2_281, 0.0_802, 0.2_192], [-0.0_583, -0.3_311, 0.1_185]]		).to(__UpperCamelCase		)

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




"""simple docstring"""




def 				a__			(					lowerCAmelCase						:							int		):






     '''simple docstring'''
     if number != int(lowerCAmelCase		):
          raise ValueError("factorial() only accepts integral values"		)
     if number < 0:
          raise ValueError("factorial() not defined for negative values"		)
     UpperCAmelCase__				:			int							=    1
     for i in range(1							,     number + 1		):
          value *= i
     return value



def 				a__			(					lowerCAmelCase						:							int		):






     '''simple docstring'''
     if not isinstance(lowerCAmelCase							,     lowerCAmelCase		):
          raise ValueError("factorial() only accepts integral values"		)
     if n < 0:
          raise ValueError("factorial() not defined for negative values"		)
     return 1 if n == 0 or n == 1 else n * factorial(n - 1		)


if __name__ == "__main__":
    import doctest

    doctest.testmod()

    A__   :						Any 							=     int(input("""Enter a positive integer: """).strip() or 0)
    print(f"""factorial{n} is {factorial(n)}""")



