



"""simple docstring"""




from typing import Optional, Union

from ...file_utils import TensorType
from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding, PaddingStrategy, TruncationStrategy


class 	a__		(    __snake_case  ):
   _lowerCamelCase       				=					"MarkupLMFeatureExtractor"
   _lowerCamelCase       				=					("MarkupLMTokenizer", "MarkupLMTokenizerFast")
   _lowerCamelCase       				=					True


   def __call__(				self   :				str,  lowerCAmelCase   :				Tuple=None,  lowerCAmelCase   :				int=None,  lowerCAmelCase   :				List[Any]=None,  lowerCAmelCase   :				List[Any]=None,  lowerCAmelCase   :				Any=None,  lowerCAmelCase   :				bool = True,  lowerCAmelCase   :				Union[bool, str, PaddingStrategy] = False,  lowerCAmelCase   :				Union[bool, str, TruncationStrategy] = None,  lowerCAmelCase   :				Optional[int] = None,  lowerCAmelCase   :				int = 0,  lowerCAmelCase   :				Optional[int] = None,  lowerCAmelCase   :				Optional[bool] = None,  lowerCAmelCase   :				Optional[bool] = None,  lowerCAmelCase   :				bool = False,  lowerCAmelCase   :				bool = False,  lowerCAmelCase   :				bool = False,  lowerCAmelCase   :				bool = False,  lowerCAmelCase   :				bool = True,  lowerCAmelCase   :				Optional[Union[str, TensorType]] = None,  **lowerCAmelCase   :				Optional[int],  )     ->							BatchEncoding:
         # first, create nodes and xpaths
         if self.parse_html:
               if html_strings is None:
                     raise ValueError('Make sure to pass HTML strings in case `parse_html` is set to `True`'      )

               if nodes is not None or xpaths is not None or node_labels is not None:
                     raise ValueError(
                         'Please don\'t pass nodes, xpaths nor node labels in case `parse_html` is set to `True`'      )

               lowercase	:   Any											= self.feature_extractor(lowerCamelCase_      )
               lowercase	:   List[str]											= features["""nodes"""]
               lowercase	:   int											= features["""xpaths"""]
         else:
               if html_strings is not None:
                     raise ValueError('You have passed HTML strings but `parse_html` is set to `False`.'      )
               if nodes is None or xpaths is None:
                     raise ValueError('Make sure to pass nodes and xpaths in case `parse_html` is set to `False`'      )

        # # second, apply the tokenizer
         if questions is not None and self.parse_html:
               if isinstance(lowerCamelCase_,  lowerCamelCase_      ):
                     lowercase	:   Optional[Any]											= [questions]  # add batch dimension (as the feature extractor always adds a batch dimension)

         lowercase	:   Any											= self.tokenizer(
             text=questions if questions is not None else nodes,  text_pair=nodes if questions is not None else None,  xpaths=lowerCamelCase_,  node_labels=lowerCamelCase_,  add_special_tokens=lowerCamelCase_,  padding=lowerCamelCase_,  truncation=lowerCamelCase_,  max_length=lowerCamelCase_,  stride=lowerCamelCase_,  pad_to_multiple_of=lowerCamelCase_,  return_token_type_ids=lowerCamelCase_,  return_attention_mask=lowerCamelCase_,  return_overflowing_tokens=lowerCamelCase_,  return_special_tokens_mask=lowerCamelCase_,  return_offsets_mapping=lowerCamelCase_,  return_length=lowerCamelCase_,  verbose=lowerCamelCase_,  return_tensors=lowerCamelCase_,  **lowerCamelCase_,  )

         return encoded_inputs


   def 							lowercase					(				self   :				Any,  *lowerCAmelCase   :				Dict,  **lowerCAmelCase   :				Union[str, Any]      )     ->							Any:
         return self.tokenizer.batch_decode(*lowerCamelCase_,  **lowerCamelCase_      )


   def 							lowercase					(				self   :				Tuple,  *lowerCAmelCase   :				Dict,  **lowerCAmelCase   :				str      )     ->							Tuple:
         return self.tokenizer.decode(*lowerCamelCase_,  **lowerCamelCase_      )






   @property
   def 							lowercase					(				self   :				List[Any]      )     ->							List[Any]:
         lowercase	:   List[str]											= self.tokenizer.model_input_names
         return tokenizer_input_names





from ...configuration_utils import PretrainedConfig
from ...utils import is_detectrona_available, logging


UpperCamelCase_									=   logging.get_logger(__name__)

UpperCamelCase_									=   {
    '''layoutlmv2-base-uncased''': '''https://huggingface.co/microsoft/layoutlmv2-base-uncased/resolve/main/config.json''',
    '''layoutlmv2-large-uncased''': '''https://huggingface.co/microsoft/layoutlmv2-large-uncased/resolve/main/config.json''',
    # See all LayoutLMv2 models at https://huggingface.co/models?filter=layoutlmv2
}

# soft dependency
if is_detectrona_available():
      import detectrona







class       _snake_case				(     __snake_case ):






   '''simple docstring'''






   A__      : List[Any]       =						"layoutlmv2"


   def __init__(    self:     Tuple  ,lowerCamelCase_:     Dict=30522  ,lowerCamelCase_:     str=768  ,lowerCamelCase_:     Any=12  ,lowerCamelCase_:     Tuple=12  ,lowerCamelCase_:     int=3072  ,lowerCamelCase_:     int="gelu"  ,lowerCamelCase_:     Dict=0.1  ,lowerCamelCase_:     List[Any]=0.1  ,lowerCamelCase_:     List[Any]=512  ,lowerCamelCase_:     Tuple=2  ,lowerCamelCase_:     Dict=0.0_2  ,lowerCamelCase_:     Dict=1e-12  ,lowerCamelCase_:     Dict=0  ,lowerCamelCase_:     List[str]=1024  ,lowerCamelCase_:     Optional[Any]=128  ,lowerCamelCase_:     List[Any]=32  ,lowerCamelCase_:     List[Any]=True  ,lowerCamelCase_:     Dict=256  ,lowerCamelCase_:     int=64  ,lowerCamelCase_:     str=True  ,lowerCamelCase_:     Tuple=[7, 7, 256]  ,lowerCamelCase_:     Union[str, Any]=128  ,lowerCamelCase_:     Any=128  ,lowerCamelCase_:     int=True  ,lowerCamelCase_:     Union[str, Any]=True  ,lowerCamelCase_:     Optional[int]=False  ,lowerCamelCase_:     List[str]=None  ,**lowerCamelCase_:     str  ,)	->      Any:
       super().__init__(
           vocab_size=lowerCamelCase_  ,hidden_size=lowerCamelCase_  ,num_hidden_layers=lowerCamelCase_  ,num_attention_heads=lowerCamelCase_  ,intermediate_size=lowerCamelCase_  ,hidden_act=lowerCamelCase_  ,hidden_dropout_prob=lowerCamelCase_  ,attention_probs_dropout_prob=lowerCamelCase_  ,max_position_embeddings=lowerCamelCase_  ,type_vocab_size=lowerCamelCase_  ,initializer_range=lowerCamelCase_  ,layer_norm_eps=lowerCamelCase_  ,pad_token_id=lowerCamelCase_  ,**lowerCamelCase_  ,)
       UpperCAmelCase_     :       Optional[int]  		=					max_ad_position_embeddings
       UpperCAmelCase_     :       Optional[int]  		=					max_rel_pos
       UpperCAmelCase_     :       Optional[int]  		=					rel_pos_bins
       UpperCAmelCase_     :       List[str]  		=					fast_qkv
       UpperCAmelCase_     :       int  		=					max_rel_ad_pos
       UpperCAmelCase_     :       int  		=					rel_ad_pos_bins
       UpperCAmelCase_     :       Optional[Any]  		=					convert_sync_batchnorm
       UpperCAmelCase_     :       str  		=					image_feature_pool_shape
       UpperCAmelCase_     :       List[Any]  		=					coordinate_size
       UpperCAmelCase_     :       int  		=					shape_size
       UpperCAmelCase_     :       Optional[Any]  		=					has_relative_attention_bias
       UpperCAmelCase_     :       str  		=					has_spatial_attention_bias
       UpperCAmelCase_     :       Tuple  		=					has_visual_segment_embedding
       UpperCAmelCase_     :       Optional[Any]  		=					(
           detectrona_config_args if detectrona_config_args is not None else self.get_default_detectrona_config()
       )


   @classmethod
   def       A__    (    self:     Any							)	->      Dict:
       return {
           "MODEL.MASK_ON": True,
           "MODEL.PIXEL_STD": [5_7.3_7_5, 5_7.1_2_0, 5_8.3_9_5],
           "MODEL.BACKBONE.NAME": "build_resnet_fpn_backbone",
           "MODEL.FPN.IN_FEATURES": ["res2", "res3", "res4", "res5"],
           "MODEL.ANCHOR_GENERATOR.SIZES": [[32], [64], [128], [256], [512]],
           "MODEL.RPN.IN_FEATURES": ["p2", "p3", "p4", "p5", "p6"],
           "MODEL.RPN.PRE_NMS_TOPK_TRAIN": 2000,
           "MODEL.RPN.PRE_NMS_TOPK_TEST": 1000,
           "MODEL.RPN.POST_NMS_TOPK_TRAIN": 1000,
           "MODEL.POST_NMS_TOPK_TEST": 1000,
           "MODEL.ROI_HEADS.NAME": "StandardROIHeads",
           "MODEL.ROI_HEADS.NUM_CLASSES": 5,
           "MODEL.ROI_HEADS.IN_FEATURES": ["p2", "p3", "p4", "p5"],
           "MODEL.ROI_BOX_HEAD.NAME": "FastRCNNConvFCHead",
           "MODEL.ROI_BOX_HEAD.NUM_FC": 2,
           "MODEL.ROI_BOX_HEAD.POOLER_RESOLUTION": 14,
           "MODEL.ROI_MASK_HEAD.NAME": "MaskRCNNConvUpsampleHead",
           "MODEL.ROI_MASK_HEAD.NUM_CONV": 4,
           "MODEL.ROI_MASK_HEAD.POOLER_RESOLUTION": 7,
           "MODEL.RESNETS.DEPTH": 101,
           "MODEL.RESNETS.SIZES": [[32], [64], [128], [256], [512]],
           "MODEL.RESNETS.ASPECT_RATIOS": [[0.5, 1.0, 2.0]],
           "MODEL.RESNETS.OUT_FEATURES": ["res2", "res3", "res4", "res5"],
           "MODEL.RESNETS.NUM_GROUPS": 32,
           "MODEL.RESNETS.WIDTH_PER_GROUP": 8,
           "MODEL.RESNETS.STRIDE_IN_1X1": False,
       }






   def       A__    (    self:     Tuple							)	->      int:
       UpperCAmelCase_     :       Any  		=					detectrona.config.get_cfg()
       for k, v in self.detectrona_config_args.items():
           UpperCAmelCase_     :       Optional[int]  		=					k.split("""."""							)
           UpperCAmelCase_     :       List[str]  		=					detectrona_config
           for attribute in attributes[:-1]:
               UpperCAmelCase_     :       Optional[Any]  		=					getattr(lowerCamelCase_  ,lowerCamelCase_							)
           setattr(lowerCamelCase_  ,attributes[-1]  ,lowerCamelCase_							)

       return detectrona_config
