






"""simple docstring"""



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


_UpperCamelCase						:    Union[str, Any]		=						logging.get_logger(__name__)

_UpperCamelCase						:    str		=						{
    '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 			a	(  A__      ):
    UpperCAmelCase_					:	Optional[int]      	="layoutlmv2"







    def __init__(     self				,						_lowerCamelCase=3_0_5_2_2				,						_lowerCamelCase=7_6_8				,						_lowerCamelCase=1_2				,						_lowerCamelCase=1_2				,						_lowerCamelCase=3_0_7_2				,						_lowerCamelCase="gelu"				,						_lowerCamelCase=0.1				,						_lowerCamelCase=0.1				,						_lowerCamelCase=5_1_2				,						_lowerCamelCase=2				,						_lowerCamelCase=0.0_2				,						_lowerCamelCase=1e-12				,						_lowerCamelCase=0				,						_lowerCamelCase=1_0_2_4				,						_lowerCamelCase=1_2_8				,						_lowerCamelCase=3_2				,						_lowerCamelCase=True				,						_lowerCamelCase=2_5_6				,						_lowerCamelCase=6_4				,						_lowerCamelCase=True				,						_lowerCamelCase=[7, 7, 2_5_6]				,						_lowerCamelCase=1_2_8				,						_lowerCamelCase=1_2_8				,						_lowerCamelCase=True				,						_lowerCamelCase=True				,						_lowerCamelCase=False				,						_lowerCamelCase=None				,						**_lowerCamelCase				,						):
      super().__init__(
          vocab_size=__A				,						hidden_size=__A				,						num_hidden_layers=__A				,						num_attention_heads=__A				,						intermediate_size=__A				,						hidden_act=__A				,						hidden_dropout_prob=__A				,						attention_probs_dropout_prob=__A				,						max_position_embeddings=__A				,						type_vocab_size=__A				,						initializer_range=__A				,						layer_norm_eps=__A				,						pad_token_id=__A				,						**__A				,						)
      lowercase				       =			max_ad_position_embeddings
      lowercase				       =			max_rel_pos
      lowercase				       =			rel_pos_bins
      lowercase				       =			fast_qkv
      lowercase				       =			max_rel_ad_pos
      lowercase				       =			rel_ad_pos_bins
      lowercase				       =			convert_sync_batchnorm
      lowercase				       =			image_feature_pool_shape
      lowercase				       =			coordinate_size
      lowercase				       =			shape_size
      lowercase				       =			has_relative_attention_bias
      lowercase				       =			has_spatial_attention_bias
      lowercase				       =			has_visual_segment_embedding
      lowercase				       =			(
          detectrona_config_args if detectrona_config_args is not None else self.get_default_detectrona_config()
      )







    @classmethod
    def      UpperCamelCase_ (     self			):
      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": [[3_2], [6_4], [1_2_8], [2_5_6], [5_1_2]],
          "MODEL.RPN.IN_FEATURES": ["p2", "p3", "p4", "p5", "p6"],
          "MODEL.RPN.PRE_NMS_TOPK_TRAIN": 2_0_0_0,
          "MODEL.RPN.PRE_NMS_TOPK_TEST": 1_0_0_0,
          "MODEL.RPN.POST_NMS_TOPK_TRAIN": 1_0_0_0,
          "MODEL.POST_NMS_TOPK_TEST": 1_0_0_0,
          "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": 1_4,
          "MODEL.ROI_MASK_HEAD.NAME": "MaskRCNNConvUpsampleHead",
          "MODEL.ROI_MASK_HEAD.NUM_CONV": 4,
          "MODEL.ROI_MASK_HEAD.POOLER_RESOLUTION": 7,
          "MODEL.RESNETS.DEPTH": 1_0_1,
          "MODEL.RESNETS.SIZES": [[3_2], [6_4], [1_2_8], [2_5_6], [5_1_2]],
          "MODEL.RESNETS.ASPECT_RATIOS": [[0.5, 1.0, 2.0]],
          "MODEL.RESNETS.OUT_FEATURES": ["res2", "res3", "res4", "res5"],
          "MODEL.RESNETS.NUM_GROUPS": 3_2,
          "MODEL.RESNETS.WIDTH_PER_GROUP": 8,
          "MODEL.RESNETS.STRIDE_IN_1X1": False,
      }







    def      UpperCamelCase_ (     self			):
      lowercase				       =			detectrona.config.get_cfg()
      for k, v in self.detectrona_config_args.items():
        lowercase				       =			k.split('.'			)
        lowercase				       =			detectrona_config
        for attribute in attributes[:-1]:
          lowercase				       =			getattr(__A				,						__A			)
        setattr(__A				,						attributes[-1]				,						__A			)

      return detectrona_config




"""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      _SCREAMING_SNAKE_CASE   (     A__				):
			UpperCAmelCase_    :Union[str, Any]												=		"MarkupLMFeatureExtractor"
			UpperCAmelCase_    :Optional[Any]												=		("MarkupLMTokenizer", "MarkupLMTokenizerFast")
			UpperCAmelCase_    :List[Any]												=		True






			def __call__(   self			,  __A=None			,  __A=None			,  __A=None			,  __A=None			,  __A=None			,  __A = True			,  __A = False			,  __A = None			,  __A = None			,  __A = 0			,  __A = None			,  __A = None			,  __A = None			,  __A = False			,  __A = False			,  __A = False			,  __A = False			,  __A = True			,  __A = None			,  **__A			,  )     ->	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`"""			)

									lowerCAmelCase_       :Union[str, Any]     	=    self.feature_extractor(__A			)
									lowerCAmelCase_       :Any     	=    features["""nodes"""]
									lowerCAmelCase_       :Union[str, Any]     	=    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(__A			,  __A			):
												lowerCAmelCase_       :Dict     	=    [questions]  # add batch dimension (as the feature extractor always adds a batch dimension)

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

						return encoded_inputs






			def 					__lowerCAmelCase					(   self			,  *__A			,  **__A			)     ->	Tuple:
						return self.tokenizer.batch_decode(*__A			,  **__A			)






			def 					__lowerCAmelCase					(   self			,  *__A			,  **__A			)     ->	str:
						return self.tokenizer.decode(*__A			,  **__A			)






			@property
			def 					__lowerCAmelCase					(   self			)     ->	Any:
						lowerCAmelCase_       :Any     	=    self.tokenizer.model_input_names
						return tokenizer_input_names






