





'''simple docstring'''







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


snake_case_  :							List[str]            =	logging.get_logger(__name__)

snake_case_  :							List[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   (lowerCAmelCase__  ):
							__a       : Dict          =							'layoutlmv2'

							def __init__(				self				:  Tuple							,  __magic_name__				:  Dict=3_05_22							,  __magic_name__				:  Any=7_68							,  __magic_name__				:  int=12							,  __magic_name__				:  Tuple=12							,  __magic_name__				:  Dict=30_72							,  __magic_name__				:  int="gelu"							,  __magic_name__				:  List[Any]=0.1							,  __magic_name__				:  int=0.1							,  __magic_name__				:  Union[str, Any]=5_12							,  __magic_name__				:  str=2							,  __magic_name__				:  Optional[Any]=0.0_2							,  __magic_name__				:  str=1E-12							,  __magic_name__				:  str=0							,  __magic_name__				:  Tuple=10_24							,  __magic_name__				:  str=1_28							,  __magic_name__				:  str=32							,  __magic_name__				:  List[str]=True							,  __magic_name__				:  Tuple=2_56							,  __magic_name__				:  str=64							,  __magic_name__				:  str=True							,  __magic_name__				:  List[str]=[7, 7, 2_56]							,  __magic_name__				:  str=1_28							,  __magic_name__				:  List[Any]=1_28							,  __magic_name__				:  Optional[int]=True							,  __magic_name__				:  Any=True							,  __magic_name__				:  Any=False							,  __magic_name__				:  List[str]=None							,  **__magic_name__				:  str							,  )       ->							Tuple:







													"""simple docstring"""
													super().__init__(
													    vocab_size=lowercase__							,  hidden_size=lowercase__							,  num_hidden_layers=lowercase__							,  num_attention_heads=lowercase__							,  intermediate_size=lowercase__							,  hidden_act=lowercase__							,  hidden_dropout_prob=lowercase__							,  attention_probs_dropout_prob=lowercase__							,  max_position_embeddings=lowercase__							,  type_vocab_size=lowercase__							,  initializer_range=lowercase__							,  layer_norm_eps=lowercase__							,  pad_token_id=lowercase__							,  **lowercase__							,  )
													UpperCAmelCase_      :   Optional[int]      =	max_ad_position_embeddings
													UpperCAmelCase_      :   str      =	max_rel_pos
													UpperCAmelCase_      :   Any      =	rel_pos_bins
													UpperCAmelCase_      :   int      =	fast_qkv
													UpperCAmelCase_      :   Union[str, Any]      =	max_rel_ad_pos
													UpperCAmelCase_      :   List[Any]      =	rel_ad_pos_bins
													UpperCAmelCase_      :   Tuple      =	convert_sync_batchnorm
													UpperCAmelCase_      :   int      =	image_feature_pool_shape
													UpperCAmelCase_      :   List[Any]      =	coordinate_size
													UpperCAmelCase_      :   Union[str, Any]      =	shape_size
													UpperCAmelCase_      :   Any      =	has_relative_attention_bias
													UpperCAmelCase_      :   Any      =	has_spatial_attention_bias
													UpperCAmelCase_      :   Any      =	has_visual_segment_embedding
													UpperCAmelCase_      :   Tuple      =	(
													    detectrona_config_args if detectrona_config_args is not None else self.get_default_detectrona_config()
													)

							@classmethod
							def      UpperCAmelCase__						(				self				:  Optional[Any] )       ->							str:







													"""simple docstring"""
													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], [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				:  int )       ->							List[str]:







													"""simple docstring"""
													UpperCAmelCase_      :   Dict      =	detectrona.config.get_cfg()
													for k, v in self.detectrona_config_args.items():
																			UpperCAmelCase_      :   int      =	k.split('''.''' )
																			UpperCAmelCase_      :   str      =	detectrona_config
																			for attribute in attributes[:-1]:
																									UpperCAmelCase_      :   int      =	getattr(lowercase__							,  lowercase__ )
																			setattr(lowercase__							,  attributes[-1]							,  lowercase__ )

													return detectrona_config













import os
from shutil import copyfile
from typing import List, Optional, Tuple

from ...tokenization_utils import AddedToken
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import is_sentencepiece_available, logging


if is_sentencepiece_available():
					from .tokenization_xlm_roberta import XLMRobertaTokenizer
else:
					snake_case_   :	Optional[int]							      =None


snake_case_   :	List[str]							      =logging.get_logger(__name__)

snake_case_   :	Optional[int]							      ={'''vocab_file''': '''sentencepiece.bpe.model''', '''tokenizer_file''': '''tokenizer.json'''}

snake_case_   :	Union[str, Any]							      ={
    '''vocab_file''': {
        '''xlm-roberta-base''': '''https://huggingface.co/xlm-roberta-base/resolve/main/sentencepiece.bpe.model''',
        '''xlm-roberta-large''': '''https://huggingface.co/xlm-roberta-large/resolve/main/sentencepiece.bpe.model''',
        '''xlm-roberta-large-finetuned-conll02-dutch''': (
            '''https://huggingface.co/xlm-roberta-large-finetuned-conll02-dutch/resolve/main/sentencepiece.bpe.model'''
        ),
        '''xlm-roberta-large-finetuned-conll02-spanish''': (
            '''https://huggingface.co/xlm-roberta-large-finetuned-conll02-spanish/resolve/main/sentencepiece.bpe.model'''
        ),
        '''xlm-roberta-large-finetuned-conll03-english''': (
            '''https://huggingface.co/xlm-roberta-large-finetuned-conll03-english/resolve/main/sentencepiece.bpe.model'''
        ),
        '''xlm-roberta-large-finetuned-conll03-german''': (
            '''https://huggingface.co/xlm-roberta-large-finetuned-conll03-german/resolve/main/sentencepiece.bpe.model'''
        ),
    },
    '''tokenizer_file''': {
        '''xlm-roberta-base''': '''https://huggingface.co/xlm-roberta-base/resolve/main/tokenizer.json''',
        '''xlm-roberta-large''': '''https://huggingface.co/xlm-roberta-large/resolve/main/tokenizer.json''',
        '''xlm-roberta-large-finetuned-conll02-dutch''': (
            '''https://huggingface.co/xlm-roberta-large-finetuned-conll02-dutch/resolve/main/tokenizer.json'''
        ),
        '''xlm-roberta-large-finetuned-conll02-spanish''': (
            '''https://huggingface.co/xlm-roberta-large-finetuned-conll02-spanish/resolve/main/tokenizer.json'''
        ),
        '''xlm-roberta-large-finetuned-conll03-english''': (
            '''https://huggingface.co/xlm-roberta-large-finetuned-conll03-english/resolve/main/tokenizer.json'''
        ),
        '''xlm-roberta-large-finetuned-conll03-german''': (
            '''https://huggingface.co/xlm-roberta-large-finetuned-conll03-german/resolve/main/tokenizer.json'''
        ),
    },
}

snake_case_   :	int							      ={
    '''xlm-roberta-base''': 512,
    '''xlm-roberta-large''': 512,
    '''xlm-roberta-large-finetuned-conll02-dutch''': 512,
    '''xlm-roberta-large-finetuned-conll02-spanish''': 512,
    '''xlm-roberta-large-finetuned-conll03-english''': 512,
    '''xlm-roberta-large-finetuned-conll03-german''': 512,
}





class        a__      (	lowerCAmelCase__		):
		UpperCAmelCase_							:       int 					= VOCAB_FILES_NAMES
		UpperCAmelCase_							:       str 					= PRETRAINED_VOCAB_FILES_MAP
		UpperCAmelCase_							:       Union[str, Any] 					= PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
		UpperCAmelCase_							:       int 					= ['input_ids', 'attention_mask']
		UpperCAmelCase_							:       Optional[int] 					= XLMRobertaTokenizer






		def __init__(      self							, lowercase__=None							, lowercase__=None							, lowercase__="<s>"							, lowercase__="</s>"							, lowercase__="</s>"							, lowercase__="<s>"							, lowercase__="<unk>"							, lowercase__="<pad>"							, lowercase__="<mask>"							, **lowercase__							, )				->				List[str]:
				# Mask token behave like a normal word, i.e. include the space before it
				__A    =							AddedToken(lowercase__							, lstrip=lowercase__							, rstrip=lowercase__						) if isinstance(lowercase__							, lowercase__						) else mask_token

				super().__init__(
				    lowercase__							, tokenizer_file=lowercase__							, bos_token=lowercase__							, eos_token=lowercase__							, sep_token=lowercase__							, cls_token=lowercase__							, unk_token=lowercase__							, pad_token=lowercase__							, mask_token=lowercase__							, **lowercase__							, )

				__A    =							vocab_file
				__A    =							False if not self.vocab_file else True






		def 					_lowerCamelCase					(      self							, lowercase__							, lowercase__ = None						)				->				List[int]:

				if token_ids_a is None:
						return [self.cls_token_id] + token_ids_a + [self.sep_token_id]
				__A    =							[self.cls_token_id]
				__A    =							[self.sep_token_id]
				return cls + token_ids_a + sep + sep + token_ids_a + sep






		def 					_lowerCamelCase					(      self							, lowercase__							, lowercase__ = None						)				->				List[int]:
				__A    =							[self.sep_token_id]
				__A    =							[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 + sep + token_ids_a + sep						) * [0]






		def 					_lowerCamelCase					(      self							, lowercase__							, lowercase__ = None						)				->				Tuple[str]:
				if not self.can_save_slow_tokenizer:
						raise ValueError(
						    "Your fast tokenizer does not have the necessary information to save the vocabulary for a slow "
						    "tokenizer."						)

				if not os.path.isdir(lowercase__						):
						logger.error(F"""Vocabulary path ({save_directory}) should be a directory."""						)
						return
				__A    =							os.path.join(
				    lowercase__							, (filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"]						)

				if os.path.abspath(self.vocab_file						) != os.path.abspath(lowercase__						):
						copyfile(self.vocab_file							, lowercase__						)

				return (out_vocab_file,)

