code: 
  
  
  
  
  
  '''simple docstring'''
  
  
  from ...configuration_utils import PretrainedConfig
  from ...utils import is_detectrona_available, logging
  
  
  _lowerCamelCase				:	Optional[int]				    =       logging.get_logger(__name__)
  
  _lowerCamelCase				:	Tuple				    =       {
      '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 							__UpperCAmelCase  (       __SCREAMING_SNAKE_CASE						):
  
  
  
  
  
  
  
  		'''simple docstring'''
  
  
  
  
  
  
  
  		__lowerCAmelCase 				=    '''layoutlmv2'''
  
  
  
  
  
  
  
  		def __init__(self						:      List[str]      ,      _lowerCAmelCase						:      str=3_0522      ,      _lowerCAmelCase						:      Any=768      ,      _lowerCAmelCase						:      Dict=12      ,      _lowerCAmelCase						:      List[str]=12      ,      _lowerCAmelCase						:      Optional[int]=3072      ,      _lowerCAmelCase						:      List[Any]="gelu"      ,      _lowerCAmelCase						:      Optional[int]=0.1      ,      _lowerCAmelCase						:      str=0.1      ,      _lowerCAmelCase						:      Optional[Any]=512      ,      _lowerCAmelCase						:      int=2      ,      _lowerCAmelCase						:      List[Any]=0.02      ,      _lowerCAmelCase						:      Optional[int]=1e-12      ,      _lowerCAmelCase						:      Union[str, Any]=0      ,      _lowerCAmelCase						:      int=1024      ,      _lowerCAmelCase						:      List[Any]=128      ,      _lowerCAmelCase						:      List[str]=32      ,      _lowerCAmelCase						:      Optional[int]=True      ,      _lowerCAmelCase						:      List[str]=256      ,      _lowerCAmelCase						:      List[str]=64      ,      _lowerCAmelCase						:      Dict=True      ,      _lowerCAmelCase						:      Tuple=[7, 7, 256]      ,      _lowerCAmelCase						:      Optional[Any]=128      ,      _lowerCAmelCase						:      int=128      ,      _lowerCAmelCase						:      Union[str, Any]=True      ,      _lowerCAmelCase						:      Any=True      ,      _lowerCAmelCase						:      Optional[int]=False      ,      _lowerCAmelCase						:      List[str]=None      ,      **_lowerCAmelCase						:      str      ,      ):
  			super().__init__(
  			    vocab_size=UpperCamelCase__      ,      hidden_size=UpperCamelCase__      ,      num_hidden_layers=UpperCamelCase__      ,      num_attention_heads=UpperCamelCase__      ,      intermediate_size=UpperCamelCase__      ,      hidden_act=UpperCamelCase__      ,      hidden_dropout_prob=UpperCamelCase__      ,      attention_probs_dropout_prob=UpperCamelCase__      ,      max_position_embeddings=UpperCamelCase__      ,      type_vocab_size=UpperCamelCase__      ,      initializer_range=UpperCamelCase__      ,      layer_norm_eps=UpperCamelCase__      ,      pad_token_id=UpperCamelCase__      ,      **UpperCamelCase__      ,      )
  			A							  =      max_ad_position_embeddings
  			A							  =      max_rel_pos
  			A							  =      rel_pos_bins
  			A							  =      fast_qkv
  			A							  =      max_rel_ad_pos
  			A							  =      rel_ad_pos_bins
  			A							  =      convert_sync_batchnorm
  			A							  =      image_feature_pool_shape
  			A							  =      coordinate_size
  			A							  =      shape_size
  			A							  =      has_relative_attention_bias
  			A							  =      has_spatial_attention_bias
  			A							  =      has_visual_segment_embedding
  			A							  =      (
  			    detectrona_config_args if detectrona_config_args is not None else self.get_default_detectrona_config()
  			)
  
  
  
  
  
  
  
  		@classmethod
  		def        A     (self						:      Optional[int]      ):
  			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], [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						:      Any      ):
  			A							  =      detectrona.config.get_cfg()
  			for k, v in self.detectrona_config_args.items():
  				A							  =      k.split("""."""      )
  				A							  =      detectrona_config
  				for attribute in attributes[:-1]:
  					A							  =      getattr(UpperCamelCase__      ,      UpperCamelCase__      )
  				setattr(UpperCamelCase__      ,      attributes[-1]      ,      UpperCamelCase__      )
  
  			return detectrona_config
  
  
style_context: 
  
  
  
  
  
  '''simple docstring'''
  
  
  class 							__UpperCAmelCase  :
  
  
  
  
  
  
  
  		'''simple docstring'''
  
  
  
  
  
  
  
  		def __init__(self						:      List[str]      ):
  			# numbermap keys are the number and its values are lists of indexes sorted
  			# in ascending order
  			A							  =      {}
  			# indexmap keys are an index and it's values are the number at that index
  			A							  =      {}
  
  
  
  
  
  
  
  		def        A     (self						:      Union[str, Any]      ,      _lowerCAmelCase						:      list | str | range      ,      _lowerCAmelCase						:      int      ):
  			if isinstance(_lowerCAmelCase      ,      (range, str)      ):
  				A							  =      list(_lowerCAmelCase      )
  			elif not isinstance(_lowerCAmelCase      ,      _lowerCAmelCase      ):
  				raise TypeError(
  				    """binary_search_delete() only accepts either a list, range or str"""      )
  
  			A							  =      0
  			A							  =      len(_lowerCAmelCase      ) - 1
  
  			while low <= high:
  				A							  =      (low + high) // 2
  				if array[mid] == item:
  					array.pop(_lowerCAmelCase      )
  					return array
  				elif array[mid] < item:
  					A							  =      mid + 1
  				else:
  					A							  =      mid - 1
  			raise ValueError(
  			    """Either the item is not in the array or the array was unsorted"""      )
  
  
  
  
  
  
  
  		def        A     (self						:      Dict      ,      _lowerCAmelCase						:      list | str | range      ,      _lowerCAmelCase						:      int      ):
  			if isinstance(_lowerCAmelCase      ,      (range, str)      ):
  				A							  =      list(_lowerCAmelCase      )
  			elif not isinstance(_lowerCAmelCase      ,      _lowerCAmelCase      ):
  				raise TypeError(
  				    """binary_search_insert() only accepts either a list, range or str"""      )
  
  			A							  =      0
  			A							  =      len(_lowerCAmelCase      ) - 1
  
  			while low <= high:
  				A							  =      (low + high) // 2
  				if array[mid] == index:
  					# If the item already exists in the array,
  					# insert it after the existing item
  					array.insert(mid + 1      ,      _lowerCAmelCase      )
  					return array
  				elif array[mid] < index:
  					A							  =      mid + 1
  				else:
  					A							  =      mid - 1
  
          # If the item doesn't exist in the array, insert it at the appropriate position
  			array.insert(_lowerCAmelCase      ,      _lowerCAmelCase      )
  			return array
  
  
  
  
  
  
  
  		def        A     (self						:      List[str]      ,      _lowerCAmelCase						:      int      ,      _lowerCAmelCase						:      int      ):
  			# Remove previous index
  			if index in self.indexmap:
  				A							  =      self.indexmap[index]
  				if len(self.numbermap[n]      ) == 1:
  					del self.numbermap[n]
  				else:
  					A							  =      self.binary_search_delete(self.numbermap[n]      ,      _lowerCAmelCase      )
  
          # Set new index
  			A							  =      number
  
  			# Number not seen before or empty so insert number value
  			if number not in self.numbermap:
  				A							  =      [index]
  
  			# Here we need to perform a binary search insertion in order to insert
  			# The item in the correct place
  			else:
  				A							  =      self.binary_search_insert(
  				    self.numbermap[number]      ,      _lowerCAmelCase      )
  
  
  
  
  
  
  
  		def        A     (self						:      int      ,      _lowerCAmelCase						:      int      ):
  			return self.numbermap.get(_lowerCAmelCase      ,      [-1]      )[0]
  
  
  if __name__ == "__main__":
  				import doctest
  
  				doctest.testmod()
  
  