






from collections import OrderedDict
from typing import TYPE_CHECKING, Any, Mapping, Optional

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...onnx.utils import compute_effective_axis_dimension
from ...utils import logging


if TYPE_CHECKING:
	from ...processing_utils import ProcessorMixin
	from ...utils import TensorType


a_							=			logging.get_logger(__name__)

a_							=			{
    '''microsoft/layoutlmv3-base''': '''https://huggingface.co/microsoft/layoutlmv3-base/resolve/main/config.json''',
}


class    lowercase__   (	_UpperCAmelCase		):
	a_   			='''layoutlmv3'''

	def __init__(							self						,			__UpperCAmelCase=50265						,			__UpperCAmelCase=768						,			__UpperCAmelCase=12						,			__UpperCAmelCase=12						,			__UpperCAmelCase=3072						,			__UpperCAmelCase="gelu"						,			__UpperCAmelCase=0.1						,			__UpperCAmelCase=0.1						,			__UpperCAmelCase=512						,			__UpperCAmelCase=2						,			__UpperCAmelCase=0.02						,			__UpperCAmelCase=1E-5						,			__UpperCAmelCase=1						,			__UpperCAmelCase=0						,			__UpperCAmelCase=2						,			__UpperCAmelCase=1024						,			__UpperCAmelCase=128						,			__UpperCAmelCase=128						,			__UpperCAmelCase=True						,			__UpperCAmelCase=32						,			__UpperCAmelCase=128						,			__UpperCAmelCase=64						,			__UpperCAmelCase=256						,			__UpperCAmelCase=True						,			__UpperCAmelCase=True						,			__UpperCAmelCase=True						,			__UpperCAmelCase=224						,			__UpperCAmelCase=3						,			__UpperCAmelCase=16						,			__UpperCAmelCase=None						,			**__UpperCAmelCase						,			)->    Dict:







							'''simple docstring'''





							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						,			bos_token_id=__lowerCAmelCase						,			eos_token_id=__lowerCAmelCase						,			**__lowerCAmelCase						,			)
							lowerCAmelCase__       					=  max_ad_position_embeddings
							lowerCAmelCase__       					=  coordinate_size
							lowerCAmelCase__       					=  shape_size
							lowerCAmelCase__       					=  has_relative_attention_bias
							lowerCAmelCase__       					=  rel_pos_bins
							lowerCAmelCase__       					=  max_rel_pos
							lowerCAmelCase__       					=  has_spatial_attention_bias
							lowerCAmelCase__       					=  rel_ad_pos_bins
							lowerCAmelCase__       					=  max_rel_ad_pos
							lowerCAmelCase__       					=  text_embed
							lowerCAmelCase__       					=  visual_embed
							lowerCAmelCase__       					=  input_size
							lowerCAmelCase__       					=  num_channels
							lowerCAmelCase__       					=  patch_size
							lowerCAmelCase__       					=  classifier_dropout





class    lowercase__   (	_UpperCAmelCase		):
	a_   			=version.parse("""1.12"""		)

	@property
	def 						UpperCAmelCase     (							self				)->    Mapping[str, Mapping[int, str]]:







							'''simple docstring'''





							if self.task in ["question-answering", "sequence-classification"]:
													return OrderedDict(
													    [
													        ("input_ids", {0: "batch", 1: "sequence"}),
													        ("attention_mask", {0: "batch", 1: "sequence"}),
													        ("bbox", {0: "batch", 1: "sequence"}),
													        ("pixel_values", {0: "batch", 1: "num_channels", 2: "height", 3: "width"}),
													    ]				)
							else:
													return OrderedDict(
													    [
													        ("input_ids", {0: "batch", 1: "sequence"}),
													        ("bbox", {0: "batch", 1: "sequence"}),
													        ("attention_mask", {0: "batch", 1: "sequence"}),
													        ("pixel_values", {0: "batch", 1: "num_channels"}),
													    ]				)

	@property
	def 						UpperCAmelCase     (							self				)->    float:







							'''simple docstring'''





							return 1E-5

	@property
	def 						UpperCAmelCase     (							self				)->    int:







							'''simple docstring'''





							return 12


	def 						UpperCAmelCase     (							self						,			__UpperCAmelCase						,			__UpperCAmelCase = -1						,			__UpperCAmelCase = -1						,			__UpperCAmelCase = False						,			__UpperCAmelCase = None						,			__UpperCAmelCase = 3						,			__UpperCAmelCase = 40						,			__UpperCAmelCase = 40						,			)->    Mapping[str, Any]:







							'''simple docstring'''





							setattr(processor.image_processor						,			"apply_ocr"						,			__lowerCAmelCase				)

							# If dynamic axis (-1) we forward with a fixed dimension of 2 samples to avoid optimizations made by ONNX
							lowerCAmelCase__       					=  compute_effective_axis_dimension(
							    __lowerCAmelCase						,			fixed_dimension=OnnxConfig.default_fixed_batch						,			num_token_to_add=0				)
							# If dynamic axis (-1) we forward with a fixed dimension of 8 tokens to avoid optimizations made by ONNX
							lowerCAmelCase__       					=  processor.tokenizer.num_special_tokens_to_add(__lowerCAmelCase				)
							lowerCAmelCase__       					=  compute_effective_axis_dimension(
							    __lowerCAmelCase						,			fixed_dimension=OnnxConfig.default_fixed_sequence						,			num_token_to_add=__lowerCAmelCase				)
							# Generate dummy inputs according to compute batch and sequence
							lowerCAmelCase__       					=  [[" ".join([processor.tokenizer.unk_token]				) * seq_length]] * batch_size

							# Generate dummy bounding boxes
							lowerCAmelCase__       					=  [[[48, 84, 73, 128]]] * batch_size

							# If dynamic axis (-1) we forward with a fixed dimension of 2 samples to avoid optimizations made by ONNX
							# batch_size = compute_effective_axis_dimension(batch_size, fixed_dimension=OnnxConfig.default_fixed_batch)
							lowerCAmelCase__       					=  self._generate_dummy_images(__lowerCAmelCase						,			__lowerCAmelCase						,			__lowerCAmelCase						,			__lowerCAmelCase				)

							lowerCAmelCase__       					=  dict(
							    processor(
							        __lowerCAmelCase						,			text=__lowerCAmelCase						,			boxes=__lowerCAmelCase						,			return_tensors=__lowerCAmelCase						,			)				)

							return inputs













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_albert import AlbertTokenizer
else:
					A    :					Tuple =      None

A    :					Optional[Any] =      logging.get_logger(__name__)
A    :					Tuple =      {'''vocab_file''': '''spiece.model''', '''tokenizer_file''': '''tokenizer.json'''}

A    :					List[str] =      {
    '''vocab_file''': {
        '''albert-base-v1''': '''https://huggingface.co/albert-base-v1/resolve/main/spiece.model''',
        '''albert-large-v1''': '''https://huggingface.co/albert-large-v1/resolve/main/spiece.model''',
        '''albert-xlarge-v1''': '''https://huggingface.co/albert-xlarge-v1/resolve/main/spiece.model''',
        '''albert-xxlarge-v1''': '''https://huggingface.co/albert-xxlarge-v1/resolve/main/spiece.model''',
        '''albert-base-v2''': '''https://huggingface.co/albert-base-v2/resolve/main/spiece.model''',
        '''albert-large-v2''': '''https://huggingface.co/albert-large-v2/resolve/main/spiece.model''',
        '''albert-xlarge-v2''': '''https://huggingface.co/albert-xlarge-v2/resolve/main/spiece.model''',
        '''albert-xxlarge-v2''': '''https://huggingface.co/albert-xxlarge-v2/resolve/main/spiece.model''',
    },
    '''tokenizer_file''': {
        '''albert-base-v1''': '''https://huggingface.co/albert-base-v1/resolve/main/tokenizer.json''',
        '''albert-large-v1''': '''https://huggingface.co/albert-large-v1/resolve/main/tokenizer.json''',
        '''albert-xlarge-v1''': '''https://huggingface.co/albert-xlarge-v1/resolve/main/tokenizer.json''',
        '''albert-xxlarge-v1''': '''https://huggingface.co/albert-xxlarge-v1/resolve/main/tokenizer.json''',
        '''albert-base-v2''': '''https://huggingface.co/albert-base-v2/resolve/main/tokenizer.json''',
        '''albert-large-v2''': '''https://huggingface.co/albert-large-v2/resolve/main/tokenizer.json''',
        '''albert-xlarge-v2''': '''https://huggingface.co/albert-xlarge-v2/resolve/main/tokenizer.json''',
        '''albert-xxlarge-v2''': '''https://huggingface.co/albert-xxlarge-v2/resolve/main/tokenizer.json''',
    },
}

A    :					List[str] =      {
    '''albert-base-v1''': 5_1_2,
    '''albert-large-v1''': 5_1_2,
    '''albert-xlarge-v1''': 5_1_2,
    '''albert-xxlarge-v1''': 5_1_2,
    '''albert-base-v2''': 5_1_2,
    '''albert-large-v2''': 5_1_2,
    '''albert-xlarge-v2''': 5_1_2,
    '''albert-xxlarge-v2''': 5_1_2,
}

A    :					Optional[int] =      '''▁'''


class   A			(SCREAMING_SNAKE_CASE    ):
			'''simple docstring'''




			__lowerCamelCase	:       str							=    VOCAB_FILES_NAMES
			__lowerCamelCase	:       List[Any]							=    PRETRAINED_VOCAB_FILES_MAP
			__lowerCamelCase	:       Dict							=    PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
			__lowerCamelCase	:       List[str]							=    AlbertTokenizer






			def __init__(			self   :    Tuple							,	__lowerCAmelCase   :    Tuple=None							,	__lowerCAmelCase   :    List[str]=None							,	__lowerCAmelCase   :    Optional[Any]=True							,	__lowerCAmelCase   :    List[Any]=True							,	__lowerCAmelCase   :    str=False							,	__lowerCAmelCase   :    Union[str, Any]="[CLS]"							,	__lowerCAmelCase   :    int="[SEP]"							,	__lowerCAmelCase   :    Dict="<unk>"							,	__lowerCAmelCase   :    Dict="[SEP]"							,	__lowerCAmelCase   :    Union[str, Any]="<pad>"							,	__lowerCAmelCase   :    str="[CLS]"							,	__lowerCAmelCase   :    int="[MASK]"							,	**__lowerCAmelCase   :    Optional[Any]							,	)	->	Optional[Any]:







					"""simple docstring"""






					A__        =   (
					    AddedToken(__lowerCAmelCase							,	lstrip=__lowerCAmelCase							,	rstrip=__lowerCAmelCase							,	normalized=__lowerCAmelCase   )
					    if isinstance(__lowerCAmelCase							,	__lowerCAmelCase   )
					    else mask_token
					)

					super().__init__(
					    __lowerCAmelCase							,	tokenizer_file=__lowerCAmelCase							,	do_lower_case=__lowerCAmelCase							,	remove_space=__lowerCAmelCase							,	keep_accents=__lowerCAmelCase							,	bos_token=__lowerCAmelCase							,	eos_token=__lowerCAmelCase							,	unk_token=__lowerCAmelCase							,	sep_token=__lowerCAmelCase							,	pad_token=__lowerCAmelCase							,	cls_token=__lowerCAmelCase							,	mask_token=__lowerCAmelCase							,	**__lowerCAmelCase							,	)

					A__        =   do_lower_case
					A__        =   remove_space
					A__        =   keep_accents
					A__        =   vocab_file
					A__        =   False if not self.vocab_file else True






			def    a_       (			self   :    List[Any]							,	__lowerCAmelCase   :    List[int]							,	__lowerCAmelCase   :    Optional[List[int]] = None   )	->	List[int]:







					"""simple docstring"""






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






			def    a_       (			self   :    Union[str, Any]							,	__lowerCAmelCase   :    List[int]							,	__lowerCAmelCase   :    Optional[List[int]] = None   )	->	List[int]:







					"""simple docstring"""






					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   ) * [0] + len(token_ids_a + sep   ) * [1]







			def    a_       (			self   :    Tuple							,	__lowerCAmelCase   :    str							,	__lowerCAmelCase   :    Optional[str] = None   )	->	Tuple[str]:







					"""simple docstring"""






					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(__lowerCAmelCase   ):
							logger.error(f'Vocabulary path ({save_directory}) should be a directory'   )
							return
					A__        =   os.path.join(
					    __lowerCAmelCase							,	(filename_prefix + """-""" if filename_prefix else """""") + VOCAB_FILES_NAMES["""vocab_file"""]   )

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

					return (out_vocab_file,)



