code: 
  
  
  from typing import TYPE_CHECKING
  
  from ..utils import OptionalDependencyNotAvailable, _LazyModule, is_flax_available, is_tf_available, is_torch_available
  
  
  SCREAMING_SNAKE_CASE__				:    Any         =    {
      'configuration_utils': ['GenerationConfig'],
      'streamers': ['TextIteratorStreamer', 'TextStreamer'],
  }
  
  try:
   if not is_torch_available():
    raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
   pass
  else:
   SCREAMING_SNAKE_CASE__				:    Optional[int]         =    [
       'Constraint',
       'ConstraintListState',
       'DisjunctiveConstraint',
       'PhrasalConstraint',
   ]
   SCREAMING_SNAKE_CASE__				:    Optional[Any]         =    [
       'BeamHypotheses',
       'BeamScorer',
       'BeamSearchScorer',
       'ConstrainedBeamSearchScorer',
   ]
   SCREAMING_SNAKE_CASE__				:    Dict         =    [
       'EpsilonLogitsWarper',
       'EtaLogitsWarper',
       'ForcedBOSTokenLogitsProcessor',
       'ForcedEOSTokenLogitsProcessor',
       'HammingDiversityLogitsProcessor',
       'InfNanRemoveLogitsProcessor',
       'LogitsProcessor',
       'LogitsProcessorList',
       'LogitsWarper',
       'MinLengthLogitsProcessor',
       'MinNewTokensLengthLogitsProcessor',
       'NoBadWordsLogitsProcessor',
       'NoRepeatNGramLogitsProcessor',
       'PrefixConstrainedLogitsProcessor',
       'RepetitionPenaltyLogitsProcessor',
       'SequenceBiasLogitsProcessor',
       'EncoderRepetitionPenaltyLogitsProcessor',
       'TemperatureLogitsWarper',
       'TopKLogitsWarper',
       'TopPLogitsWarper',
       'TypicalLogitsWarper',
       'EncoderNoRepeatNGramLogitsProcessor',
       'ExponentialDecayLengthPenalty',
       'LogitNormalization',
   ]
   SCREAMING_SNAKE_CASE__				:    Any         =    [
       'MaxNewTokensCriteria',
       'MaxLengthCriteria',
       'MaxTimeCriteria',
       'StoppingCriteria',
       'StoppingCriteriaList',
       'validate_stopping_criteria',
   ]
   SCREAMING_SNAKE_CASE__				:    Optional[int]         =    [
       'GenerationMixin',
       'top_k_top_p_filtering',
       'GreedySearchEncoderDecoderOutput',
       'GreedySearchDecoderOnlyOutput',
       'SampleEncoderDecoderOutput',
       'SampleDecoderOnlyOutput',
       'BeamSearchEncoderDecoderOutput',
       'BeamSearchDecoderOnlyOutput',
       'BeamSampleEncoderDecoderOutput',
       'BeamSampleDecoderOnlyOutput',
       'ContrastiveSearchEncoderDecoderOutput',
       'ContrastiveSearchDecoderOnlyOutput',
   ]
  
  try:
   if not is_tf_available():
    raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
   pass
  else:
   SCREAMING_SNAKE_CASE__				:    List[Any]         =    [
       'TFForcedBOSTokenLogitsProcessor',
       'TFForcedEOSTokenLogitsProcessor',
       'TFLogitsProcessor',
       'TFLogitsProcessorList',
       'TFLogitsWarper',
       'TFMinLengthLogitsProcessor',
       'TFNoBadWordsLogitsProcessor',
       'TFNoRepeatNGramLogitsProcessor',
       'TFRepetitionPenaltyLogitsProcessor',
       'TFTemperatureLogitsWarper',
       'TFTopKLogitsWarper',
       'TFTopPLogitsWarper',
       'TFForceTokensLogitsProcessor',
       'TFSuppressTokensAtBeginLogitsProcessor',
       'TFSuppressTokensLogitsProcessor',
   ]
   SCREAMING_SNAKE_CASE__				:    int         =    [
       'TFGenerationMixin',
       'tf_top_k_top_p_filtering',
       'TFGreedySearchDecoderOnlyOutput',
       'TFGreedySearchEncoderDecoderOutput',
       'TFSampleEncoderDecoderOutput',
       'TFSampleDecoderOnlyOutput',
       'TFBeamSearchEncoderDecoderOutput',
       'TFBeamSearchDecoderOnlyOutput',
       'TFBeamSampleEncoderDecoderOutput',
       'TFBeamSampleDecoderOnlyOutput',
       'TFContrastiveSearchEncoderDecoderOutput',
       'TFContrastiveSearchDecoderOnlyOutput',
   ]
  
  try:
   if not is_flax_available():
    raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
   pass
  else:
   SCREAMING_SNAKE_CASE__				:    Union[str, Any]         =    [
       'FlaxForcedBOSTokenLogitsProcessor',
       'FlaxForcedEOSTokenLogitsProcessor',
       'FlaxLogitsProcessor',
       'FlaxLogitsProcessorList',
       'FlaxLogitsWarper',
       'FlaxMinLengthLogitsProcessor',
       'FlaxTemperatureLogitsWarper',
       'FlaxTopKLogitsWarper',
       'FlaxTopPLogitsWarper',
   ]
   SCREAMING_SNAKE_CASE__				:    List[Any]         =    [
       'FlaxGenerationMixin',
       'FlaxGreedySearchOutput',
       'FlaxSampleOutput',
       'FlaxBeamSearchOutput',
   ]
  
  if TYPE_CHECKING:
   from .configuration_utils import GenerationConfig
   from .streamers import TextIteratorStreamer, TextStreamer
  
   try:
    if not is_torch_available():
     raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
    pass
   else:
    from .beam_constraints import Constraint, ConstraintListState, DisjunctiveConstraint, PhrasalConstraint
    from .beam_search import BeamHypotheses, BeamScorer, BeamSearchScorer, ConstrainedBeamSearchScorer
    from .logits_process import (
        EncoderNoRepeatNGramLogitsProcessor,
        EncoderRepetitionPenaltyLogitsProcessor,
        EpsilonLogitsWarper,
        EtaLogitsWarper,
        ExponentialDecayLengthPenalty,
        ForcedBOSTokenLogitsProcessor,
        ForcedEOSTokenLogitsProcessor,
        HammingDiversityLogitsProcessor,
        InfNanRemoveLogitsProcessor,
        LogitNormalization,
        LogitsProcessor,
        LogitsProcessorList,
        LogitsWarper,
        MinLengthLogitsProcessor,
        MinNewTokensLengthLogitsProcessor,
        NoBadWordsLogitsProcessor,
        NoRepeatNGramLogitsProcessor,
        PrefixConstrainedLogitsProcessor,
        RepetitionPenaltyLogitsProcessor,
        SequenceBiasLogitsProcessor,
        TemperatureLogitsWarper,
        TopKLogitsWarper,
        TopPLogitsWarper,
        TypicalLogitsWarper,
    )
    from .stopping_criteria import (
        MaxLengthCriteria,
        MaxNewTokensCriteria,
        MaxTimeCriteria,
        StoppingCriteria,
        StoppingCriteriaList,
        validate_stopping_criteria,
    )
    from .utils import (
        BeamSampleDecoderOnlyOutput,
        BeamSampleEncoderDecoderOutput,
        BeamSearchDecoderOnlyOutput,
        BeamSearchEncoderDecoderOutput,
        ContrastiveSearchDecoderOnlyOutput,
        ContrastiveSearchEncoderDecoderOutput,
        GenerationMixin,
        GreedySearchDecoderOnlyOutput,
        GreedySearchEncoderDecoderOutput,
        SampleDecoderOnlyOutput,
        SampleEncoderDecoderOutput,
        top_k_top_p_filtering,
    )
  
   try:
    if not is_tf_available():
     raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
    pass
   else:
    from .tf_logits_process import (
        TFForcedBOSTokenLogitsProcessor,
        TFForcedEOSTokenLogitsProcessor,
        TFForceTokensLogitsProcessor,
        TFLogitsProcessor,
        TFLogitsProcessorList,
        TFLogitsWarper,
        TFMinLengthLogitsProcessor,
        TFNoBadWordsLogitsProcessor,
        TFNoRepeatNGramLogitsProcessor,
        TFRepetitionPenaltyLogitsProcessor,
        TFSuppressTokensAtBeginLogitsProcessor,
        TFSuppressTokensLogitsProcessor,
        TFTemperatureLogitsWarper,
        TFTopKLogitsWarper,
        TFTopPLogitsWarper,
    )
    from .tf_utils import (
        TFBeamSampleDecoderOnlyOutput,
        TFBeamSampleEncoderDecoderOutput,
        TFBeamSearchDecoderOnlyOutput,
        TFBeamSearchEncoderDecoderOutput,
        TFContrastiveSearchDecoderOnlyOutput,
        TFContrastiveSearchEncoderDecoderOutput,
        TFGenerationMixin,
        TFGreedySearchDecoderOnlyOutput,
        TFGreedySearchEncoderDecoderOutput,
        TFSampleDecoderOnlyOutput,
        TFSampleEncoderDecoderOutput,
        tf_top_k_top_p_filtering,
    )
  
   try:
    if not is_flax_available():
     raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
    pass
   else:
    from .flax_logits_process import (
        FlaxForcedBOSTokenLogitsProcessor,
        FlaxForcedEOSTokenLogitsProcessor,
        FlaxLogitsProcessor,
        FlaxLogitsProcessorList,
        FlaxLogitsWarper,
        FlaxMinLengthLogitsProcessor,
        FlaxTemperatureLogitsWarper,
        FlaxTopKLogitsWarper,
        FlaxTopPLogitsWarper,
    )
    from .flax_utils import FlaxBeamSearchOutput, FlaxGenerationMixin, FlaxGreedySearchOutput, FlaxSampleOutput
  else:
   import sys
  
   SCREAMING_SNAKE_CASE__				:    Optional[Any]         =    _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)
  
  
  
  
  
  
style_context: 
  
  
  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 		_SCREAMING_SNAKE_CASE    :
  
  
       def __init__(     self       ,				A_       ,				A_=13       ,				A_=7       ,				A_=True       ,				A_=True       ,				A_=True       ,				A_=True       ,				A_=99       ,				A_=32       ,				A_=5       ,				A_=4       ,				A_=37       ,				A_="gelu"       ,				A_=0.1       ,				A_=0.1       ,				A_=5_12       ,				A_=16       ,				A_=2       ,				A_=0.0_2       ,				A_=3       ,				A_=None       ,				A_=20       ,				A_=30       ,				A_=2       ,				A_=2       ,				A_=10       ,				):
         _UpperCAmelCase		:       str       =    parent
         _UpperCAmelCase		:       Dict       =    batch_size
         _UpperCAmelCase		:       Optional[int]       =    seq_length
         _UpperCAmelCase		:       Union[str, Any]       =    is_training
         _UpperCAmelCase		:       Tuple       =    use_input_mask
         _UpperCAmelCase		:       Dict       =    use_token_type_ids
         _UpperCAmelCase		:       Dict       =    use_labels
         _UpperCAmelCase		:       Optional[int]       =    vocab_size
         _UpperCAmelCase		:       List[str]       =    hidden_size
         _UpperCAmelCase		:       Tuple       =    num_hidden_layers
         _UpperCAmelCase		:       Tuple       =    num_attention_heads
         _UpperCAmelCase		:       Optional[int]       =    intermediate_size
         _UpperCAmelCase		:       str       =    hidden_act
         _UpperCAmelCase		:       Optional[Any]       =    hidden_dropout_prob
         _UpperCAmelCase		:       List[str]       =    attention_probs_dropout_prob
         _UpperCAmelCase		:       Union[str, Any]       =    max_position_embeddings
         _UpperCAmelCase		:       List[Any]       =    type_vocab_size
         _UpperCAmelCase		:       Union[str, Any]       =    type_sequence_label_size
         _UpperCAmelCase		:       List[Any]       =    initializer_range
         _UpperCAmelCase		:       Union[str, Any]       =    num_labels
         _UpperCAmelCase		:       Any       =    scope
         _UpperCAmelCase		:       List[str]       =    max_xpath_tag_unit_embeddings
         _UpperCAmelCase		:       Tuple       =    max_xpath_subs_unit_embeddings
         _UpperCAmelCase		:       Optional[Any]       =    tag_pad_id
         _UpperCAmelCase		:       Union[str, Any]       =    subs_pad_id
         _UpperCAmelCase		:       Optional[int]       =    max_depth
  
  
       def 					__snake_case(     self						):
         _UpperCAmelCase		:       Dict       =    ids_tensor([self.batch_size, self.seq_length]       ,				self.vocab_size						)
  
         _UpperCAmelCase		:       List[str]       =    ids_tensor(
             [self.batch_size, self.seq_length, self.max_depth]       ,				self.max_xpath_tag_unit_embeddings						)
  
         _UpperCAmelCase		:       Tuple       =    ids_tensor(
             [self.batch_size, self.seq_length, self.max_depth]       ,				self.max_xpath_subs_unit_embeddings						)
  
         _UpperCAmelCase		:       int       =    None
         if self.use_input_mask:
           _UpperCAmelCase		:       Any       =    ids_tensor([self.batch_size, self.seq_length]       ,				vocab_size=2						)
  
         _UpperCAmelCase		:       Tuple       =    None
         if self.use_token_type_ids:
           _UpperCAmelCase		:       Dict       =    ids_tensor([self.batch_size, self.seq_length]       ,				self.type_vocab_size						)
  
         _UpperCAmelCase		:       str       =    None
         _UpperCAmelCase		:       Union[str, Any]       =    None
         if self.use_labels:
           _UpperCAmelCase		:       int       =    ids_tensor([self.batch_size]       ,				self.type_sequence_label_size						)
           _UpperCAmelCase		:       int       =    ids_tensor([self.batch_size, self.seq_length]       ,				self.num_labels						)
  
         _UpperCAmelCase		:       List[Any]       =    self.get_config()
  
         return (
             config,
             input_ids,
             xpath_tags_seq,
             xpath_subs_seq,
             token_type_ids,
             input_mask,
             sequence_labels,
             token_labels,
         )
  
  
       def 					__snake_case(     self						):
         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 					__snake_case(     self       ,				A_       ,				A_       ,				A_       ,				A_       ,				A_       ,				A_       ,				A_       ,				A_       ,				):
         _UpperCAmelCase		:       Tuple       =    MarkupLMModel(config=A_						)
         model.to(A_						)
         model.eval()
         print("""Configs:"""       ,				model.config.tag_pad_id       ,				model.config.subs_pad_id						)
         _UpperCAmelCase		:       List[Any]       =    model(A_       ,				attention_mask=A_       ,				token_type_ids=A_						)
         _UpperCAmelCase		:       Tuple       =    model(A_       ,				token_type_ids=A_						)
         _UpperCAmelCase		:       Union[str, Any]       =    model(A_						)
         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 					__snake_case(     self       ,				A_       ,				A_       ,				A_       ,				A_       ,				A_       ,				A_       ,				A_       ,				A_       ,				):
         _UpperCAmelCase		:       Optional[int]       =    self.num_labels
         _UpperCAmelCase		:       List[Any]       =    MarkupLMForSequenceClassification(A_						)
         model.to(A_						)
         model.eval()
         _UpperCAmelCase		:       Any       =    model(
             A_       ,				xpath_tags_seq=A_       ,				xpath_subs_seq=A_       ,				attention_mask=A_       ,				token_type_ids=A_       ,				labels=A_       ,				)
         self.parent.assertEqual(result.logits.shape       ,				(self.batch_size, self.num_labels)						)
  
  
       def 					__snake_case(     self       ,				A_       ,				A_       ,				A_       ,				A_       ,				A_       ,				A_       ,				A_       ,				A_       ,				):
         _UpperCAmelCase		:       List[Any]       =    self.num_labels
         _UpperCAmelCase		:       Any       =    MarkupLMForTokenClassification(config=A_						)
         model.to(A_						)
         model.eval()
         _UpperCAmelCase		:       Tuple       =    model(
             A_       ,				xpath_tags_seq=A_       ,				xpath_subs_seq=A_       ,				attention_mask=A_       ,				token_type_ids=A_       ,				labels=A_       ,				)
         self.parent.assertEqual(result.logits.shape       ,				(self.batch_size, self.seq_length, self.num_labels)						)
  
  
       def 					__snake_case(     self       ,				A_       ,				A_       ,				A_       ,				A_       ,				A_       ,				A_       ,				A_       ,				A_       ,				):
         _UpperCAmelCase		:       List[Any]       =    MarkupLMForQuestionAnswering(config=A_						)
         model.to(A_						)
         model.eval()
         _UpperCAmelCase		:       List[Any]       =    model(
             A_       ,				xpath_tags_seq=A_       ,				xpath_subs_seq=A_       ,				attention_mask=A_       ,				token_type_ids=A_       ,				start_positions=A_       ,				end_positions=A_       ,				)
         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						):
         _UpperCAmelCase		:       Union[str, Any]       =    self.prepare_config_and_inputs()
         (
             (
             _UpperCAmelCase
         ),(
             _UpperCAmelCase
         ),(
             _UpperCAmelCase
         ),(
             _UpperCAmelCase
         ),(
             _UpperCAmelCase
         ),(
             _UpperCAmelCase
         ),(
             _UpperCAmelCase
         ),(
             _UpperCAmelCase
         ),
         )		:       List[str]       =    config_and_inputs
         _UpperCAmelCase		:       Optional[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 		_SCREAMING_SNAKE_CASE    (	A       ,  A       ,  unittest.TestCase    ):
       __SCREAMING_SNAKE_CASE    				=						(
           (
               MarkupLMModel,
               MarkupLMForSequenceClassification,
               MarkupLMForTokenClassification,
               MarkupLMForQuestionAnswering,
           )
           if is_torch_available()
           else None
       )
       __SCREAMING_SNAKE_CASE    				=						(
           {
               '''feature-extraction''': MarkupLMModel,
               '''question-answering''': MarkupLMForQuestionAnswering,
               '''text-classification''': MarkupLMForSequenceClassification,
               '''token-classification''': MarkupLMForTokenClassification,
               '''zero-shot''': MarkupLMForSequenceClassification,
           }
           if is_torch_available()
           else {}
       )
  
  
       def 					__snake_case(     self       ,				A_       ,				A_       ,				A_       ,				A_       ,				A_						):
         # ValueError: Nodes must be of type `List[str]` (single pretokenized example), or `List[List[str]]`
         # (batch of pretokenized examples).
         return True
  
  
       def 					__snake_case(     self						):
         _UpperCAmelCase		:       Union[str, Any]       =    MarkupLMModelTester(self						)
         _UpperCAmelCase		:       str       =    ConfigTester(self       ,				config_class=A_       ,				hidden_size=37						)
  
  
       def 					__snake_case(     self						):
         self.config_tester.run_common_tests()
  
  
       def 					__snake_case(     self						):
         _UpperCAmelCase		:       List[Any]       =    self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*A_						)
  
  
       def 					__snake_case(     self						):
         _UpperCAmelCase		:       Optional[int]       =    self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_sequence_classification(*A_						)
  
  
       def 					__snake_case(     self						):
         _UpperCAmelCase		:       Union[str, Any]       =    self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_token_classification(*A_						)
  
  
  
  
       def 					__snake_case(     self						):
         _UpperCAmelCase		:       Any       =    self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_question_answering(*A_						)
  
  
  
  
  def       a__						(		):
    _UpperCAmelCase		:       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 		_SCREAMING_SNAKE_CASE    (	unittest.TestCase    ):
  
  
       @cached_property
       def 					__snake_case(     self						):
         # TODO use from_pretrained here
         _UpperCAmelCase		:       int       =    MarkupLMFeatureExtractor()
         _UpperCAmelCase		:       int       =    MarkupLMTokenizer.from_pretrained("""microsoft/markuplm-base"""						)
  
         return MarkupLMProcessor(A_       ,				A_						)
  
  
  
  
       @slow
       def 					__snake_case(     self						):
         _UpperCAmelCase		:       List[Any]       =    MarkupLMModel.from_pretrained("""microsoft/markuplm-base"""						).to(A_						)
  
         _UpperCAmelCase		:       Optional[Any]       =    self.default_processor
  
         _UpperCAmelCase		:       str       =    processor(prepare_html_string()       ,				return_tensors="""pt"""						)
         _UpperCAmelCase		:       List[str]       =    inputs.to(A_						)
  
         # forward pass
         with torch.no_grad():
           _UpperCAmelCase		:       Optional[Any]       =    model(**A_						)
  
         # verify the last hidden states
         _UpperCAmelCase		:       Tuple       =    torch.Size([1, 14, 7_68]						)
         self.assertEqual(outputs.last_hidden_state.shape       ,				A_						)
  
         _UpperCAmelCase		:       List[Any]       =    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(A_						)
  
         self.assertTrue(torch.allclose(outputs.last_hidden_state[0, :3, :3]       ,				A_       ,				atol=1e-4						)						)
  
  
  
  
  
  