





"""simple docstring"""
import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_layoutlm import LayoutLMTokenizer


__UpperCamelCase			:		Optional[int]		    =   logging.get_logger(__name__)

__UpperCamelCase			:		Any		    =   {'''vocab_file''': '''vocab.txt''', '''tokenizer_file''': '''tokenizer.json'''}

__UpperCamelCase			:		Any		    =   {
    '''vocab_file''': {
        '''microsoft/layoutlm-base-uncased''': (
            '''https://huggingface.co/microsoft/layoutlm-base-uncased/resolve/main/vocab.txt'''
        ),
        '''microsoft/layoutlm-large-uncased''': (
            '''https://huggingface.co/microsoft/layoutlm-large-uncased/resolve/main/vocab.txt'''
        ),
    },
    '''tokenizer_file''': {
        '''microsoft/layoutlm-base-uncased''': (
            '''https://huggingface.co/microsoft/layoutlm-base-uncased/resolve/main/tokenizer.json'''
        ),
        '''microsoft/layoutlm-large-uncased''': (
            '''https://huggingface.co/microsoft/layoutlm-large-uncased/resolve/main/tokenizer.json'''
        ),
    },
}

__UpperCamelCase			:		Optional[int]		    =   {
    '''microsoft/layoutlm-base-uncased''': 512,
    '''microsoft/layoutlm-large-uncased''': 512,
}

__UpperCamelCase			:		Tuple		    =   {
    '''microsoft/layoutlm-base-uncased''': {'''do_lower_case''': True},
    '''microsoft/layoutlm-large-uncased''': {'''do_lower_case''': True},
}







class 	a				(					a__   ):
 snake_case__    	=    VOCAB_FILES_NAMES
 snake_case__    	=    PRETRAINED_VOCAB_FILES_MAP
 snake_case__    	=    PRETRAINED_INIT_CONFIGURATION
 snake_case__    	=    PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
 snake_case__    	=    LayoutLMTokenizer



 def __init__(			self							,    _snake_case=None							,    _snake_case=None							,    _snake_case=True							,    _snake_case="[UNK]"							,    _snake_case="[SEP]"							,    _snake_case="[PAD]"							,    _snake_case="[CLS]"							,    _snake_case="[MASK]"							,    _snake_case=True							,    _snake_case=None							,    **_snake_case							,    ):







  """simple docstring"""






  super().__init__(
      _snake_case							,    tokenizer_file=_snake_case							,    do_lower_case=_snake_case							,    unk_token=_snake_case							,    sep_token=_snake_case							,    pad_token=_snake_case							,    cls_token=_snake_case							,    mask_token=_snake_case							,    tokenize_chinese_chars=_snake_case							,    strip_accents=_snake_case							,    **_snake_case							,    )

  lowerCAmelCase  							=      json.loads(self.backend_tokenizer.normalizer.__getstate__()			)
  if (
      normalizer_state.get('lowercase'							,    _snake_case			) != do_lower_case
      or normalizer_state.get('strip_accents'							,    _snake_case			) != strip_accents
      or normalizer_state.get('handle_chinese_chars'							,    _snake_case			) != tokenize_chinese_chars
  ):
   lowerCAmelCase  							=      getattr(_snake_case							,    normalizer_state.pop('type'			)			)
   lowerCAmelCase  							=      do_lower_case
   lowerCAmelCase  							=      strip_accents
   lowerCAmelCase  							=      tokenize_chinese_chars
   lowerCAmelCase  							=      normalizer_class(**_snake_case			)

  lowerCAmelCase  							=      do_lower_case



 def 					UpperCamelCase__   (			self							,    _snake_case							,    _snake_case=None			):







  """simple docstring"""






  lowerCAmelCase  							=      [self.cls_token_id] + token_ids_a + [self.sep_token_id]

  if token_ids_a:
   output += token_ids_a + [self.sep_token_id]

  return output



 def 					UpperCamelCase__   (			self							,    _snake_case							,    _snake_case = None			):







  """simple docstring"""






  lowerCAmelCase  							=      [self.sep_token_id]
  lowerCAmelCase  							=      [self.cls_token_id]
  if token_ids_a is None:
   return len(cls + token_ids_a + sep			) * [0]
  return len(cls + token_ids_a + sep			) * [0] + len(token_ids_a + sep			) * [1]



 def 					UpperCamelCase__   (			self							,    _snake_case							,    _snake_case = None			):







  """simple docstring"""






  lowerCAmelCase  							=      self._tokenizer.model.save(_snake_case							,    name=_snake_case			)
  return tuple(_snake_case			)












"""simple docstring"""
from ...configuration_utils import PretrainedConfig
from ...utils import is_detectrona_available, logging


__UpperCamelCase			:		List[Any]		    =   logging.get_logger(__name__)

__UpperCamelCase			:		Union[str, Any]		    =   {
    '''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__   ):
 snake_case__    	=    '''layoutlmv2'''



 def __init__(			self							,    _snake_case=3_05_22							,    _snake_case=7_68							,    _snake_case=12							,    _snake_case=12							,    _snake_case=30_72							,    _snake_case="gelu"							,    _snake_case=0.1							,    _snake_case=0.1							,    _snake_case=5_12							,    _snake_case=2							,    _snake_case=0.02							,    _snake_case=1E-12							,    _snake_case=0							,    _snake_case=10_24							,    _snake_case=1_28							,    _snake_case=32							,    _snake_case=True							,    _snake_case=2_56							,    _snake_case=64							,    _snake_case=True							,    _snake_case=[7, 7, 2_56]							,    _snake_case=1_28							,    _snake_case=1_28							,    _snake_case=True							,    _snake_case=True							,    _snake_case=False							,    _snake_case=None							,    **_snake_case							,    ):







  """simple docstring"""






  super().__init__(
      vocab_size=_snake_case							,    hidden_size=_snake_case							,    num_hidden_layers=_snake_case							,    num_attention_heads=_snake_case							,    intermediate_size=_snake_case							,    hidden_act=_snake_case							,    hidden_dropout_prob=_snake_case							,    attention_probs_dropout_prob=_snake_case							,    max_position_embeddings=_snake_case							,    type_vocab_size=_snake_case							,    initializer_range=_snake_case							,    layer_norm_eps=_snake_case							,    pad_token_id=_snake_case							,    **_snake_case							,    )
  lowerCAmelCase  							=      max_ad_position_embeddings
  lowerCAmelCase  							=      max_rel_pos
  lowerCAmelCase  							=      rel_pos_bins
  lowerCAmelCase  							=      fast_qkv
  lowerCAmelCase  							=      max_rel_ad_pos
  lowerCAmelCase  							=      rel_ad_pos_bins
  lowerCAmelCase  							=      convert_sync_batchnorm
  lowerCAmelCase  							=      image_feature_pool_shape
  lowerCAmelCase  							=      coordinate_size
  lowerCAmelCase  							=      shape_size
  lowerCAmelCase  							=      has_relative_attention_bias
  lowerCAmelCase  							=      has_spatial_attention_bias
  lowerCAmelCase  							=      has_visual_segment_embedding
  lowerCAmelCase  							=      (
      detectrona_config_args if detectrona_config_args is not None else self.get_default_detectrona_config()
  )



 @classmethod
 def 					UpperCamelCase__   (			self			):







  """simple docstring"""






  return {
      "MODEL.MASK_ON": True,
      "MODEL.PIXEL_STD": [57.375, 57.120, 58.395],
      "MODEL.BACKBONE.NAME": "build_resnet_fpn_backbone",
      "MODEL.FPN.IN_FEATURES": ["res2", "res3", "res4", "res5"],
      "MODEL.ANCHOR_GENERATOR.SIZES": [[32], [64], [1_28], [2_56], [5_12]],
      "MODEL.RPN.IN_FEATURES": ["p2", "p3", "p4", "p5", "p6"],
      "MODEL.RPN.PRE_NMS_TOPK_TRAIN": 20_00,
      "MODEL.RPN.PRE_NMS_TOPK_TEST": 10_00,
      "MODEL.RPN.POST_NMS_TOPK_TRAIN": 10_00,
      "MODEL.POST_NMS_TOPK_TEST": 10_00,
      "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": 1_01,
      "MODEL.RESNETS.SIZES": [[32], [64], [1_28], [2_56], [5_12]],
      "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 					UpperCamelCase__   (			self			):







  """simple docstring"""






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

  return detectrona_config





