

import json
from typing import Iterator, List, Union

from tokenizers import AddedToken, Regex, Tokenizer, decoders, normalizers, pre_tokenizers, trainers
from tokenizers.implementations.base_tokenizer import BaseTokenizer
from tokenizers.models import Unigram
from tokenizers.processors import TemplateProcessing

class 				__UpperCamelCase				(					__UpperCAmelCase			):







 def __init__(   self: List[str]  , __UpperCamelCase: str = "▁"  , __UpperCamelCase: bool = True  , __UpperCamelCase: Union[str, AddedToken] = "<unk>"  , __UpperCamelCase: Union[str, AddedToken] = "</s>"  , __UpperCamelCase: Union[str, AddedToken] = "<pad>"  , ):

      '''simple docstring'''





      __magic_name__							=    {
          'pad': {'id': 0, 'token': pad_token},
          'eos': {'id': 1, 'token': eos_token},
          'unk': {'id': 2, 'token': unk_token},
      }

      __magic_name__							=    [None] * len(self.special_tokens      )
      for token_dict in self.special_tokens.values():
           __magic_name__							=    token_dict['token']

      __magic_name__							=    Tokenizer(Unigram()      )

      __magic_name__							=    normalizers.Sequence(
          [
              normalizers.Nmt(),
              normalizers.NFKC(),
              normalizers.Replace(Regex(' {2,}'      )  , ' '      ),
              normalizers.Lowercase(),
          ]      )
      __magic_name__							=    pre_tokenizers.Sequence(
          [
              pre_tokenizers.Metaspace(replacement=__SCREAMING_SNAKE_CASE  , add_prefix_space=__SCREAMING_SNAKE_CASE      ),
              pre_tokenizers.Digits(individual_digits=__SCREAMING_SNAKE_CASE      ),
              pre_tokenizers.Punctuation(),
          ]      )
      __magic_name__							=    decoders.Metaspace(replacement=__SCREAMING_SNAKE_CASE  , add_prefix_space=__SCREAMING_SNAKE_CASE      )

      __magic_name__							=    TemplateProcessing(
          single=F'$A {self.special_tokens["eos"]["token"]}'  , special_tokens=[(self.special_tokens['eos']['token'], self.special_tokens['eos']['id'])]  , )

      __magic_name__							=    {
          'model': 'SentencePieceUnigram',
          'replacement': replacement,
          'add_prefix_space': add_prefix_space,
      }

      super().__init__(__SCREAMING_SNAKE_CASE  , __SCREAMING_SNAKE_CASE      )







 def 	_SCREAMING_SNAKE_CASE							(   self: Optional[int]  , __UpperCamelCase: Union[str, List[str]]  , __UpperCamelCase: int = 80_00  , __UpperCamelCase: bool = True  , ):

      '''simple docstring'''





      __magic_name__							=    trainers.UnigramTrainer(
          vocab_size=__SCREAMING_SNAKE_CASE  , special_tokens=self.special_tokens_list  , show_progress=__SCREAMING_SNAKE_CASE  , )

      if isinstance(__SCREAMING_SNAKE_CASE  , __SCREAMING_SNAKE_CASE      ):
           __magic_name__							=    [files]
      self._tokenizer.train(__SCREAMING_SNAKE_CASE  , trainer=__SCREAMING_SNAKE_CASE      )

      self.add_unk_id()







 def 	_SCREAMING_SNAKE_CASE							(   self: int  , __UpperCamelCase: Union[Iterator[str], Iterator[Iterator[str]]]  , __UpperCamelCase: int = 80_00  , __UpperCamelCase: bool = True  , ):

      '''simple docstring'''





      __magic_name__							=    trainers.UnigramTrainer(
          vocab_size=__SCREAMING_SNAKE_CASE  , special_tokens=self.special_tokens_list  , show_progress=__SCREAMING_SNAKE_CASE  , )

      self._tokenizer.train_from_iterator(__SCREAMING_SNAKE_CASE  , trainer=__SCREAMING_SNAKE_CASE      )

      self.add_unk_id()







 def 	_SCREAMING_SNAKE_CASE							(   self: Dict      ):

      '''simple docstring'''





      __magic_name__							=    json.loads(self._tokenizer.to_str()      )

      __magic_name__							=    self.special_tokens['unk']['id']

      __magic_name__							=    Tokenizer.from_str(json.dumps(__SCREAMING_SNAKE_CASE      )      )







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 				__UpperCamelCase				(					SCREAMING_SNAKE_CASE			):
	_lowercase  :   Optional[Any]       				=  "layoutlmv3"







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

						'''simple docstring'''





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




class 				__UpperCamelCase				(					SCREAMING_SNAKE_CASE			):
	_lowercase  :   Any       				=  version.parse("1.12"			)







	@property
	def 	_SCREAMING_SNAKE_CASE							(   self: Any      ):

						'''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 	_SCREAMING_SNAKE_CASE							(   self: int      ):

						'''simple docstring'''





						return 1E-5







	@property
	def 	_SCREAMING_SNAKE_CASE							(   self: Optional[int]      ):

						'''simple docstring'''





						return 12







	def 	_SCREAMING_SNAKE_CASE							(   self: Tuple  , __UpperCamelCase: "ProcessorMixin"  , __UpperCamelCase: int = -1  , __UpperCamelCase: int = -1  , __UpperCamelCase: bool = False  , __UpperCamelCase: Optional["TensorType"] = None  , __UpperCamelCase: int = 3  , __UpperCamelCase: int = 40  , __UpperCamelCase: int = 40  , ):

						'''simple docstring'''





						setattr(processor.image_processor  , 'apply_ocr'  , __UpperCamelCase      )

						# If dynamic axis (-1) we forward with a fixed dimension of 2 samples to avoid optimizations made by ONNX
						__magic_name__							=    compute_effective_axis_dimension(
						    __UpperCamelCase  , 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
						__magic_name__							=    processor.tokenizer.num_special_tokens_to_add(__UpperCamelCase      )
						__magic_name__							=    compute_effective_axis_dimension(
						    __UpperCamelCase  , fixed_dimension=OnnxConfig.default_fixed_sequence  , num_token_to_add=__UpperCamelCase      )
						# Generate dummy inputs according to compute batch and sequence
						__magic_name__							=    [[' '.join([processor.tokenizer.unk_token]      ) * seq_length]] * batch_size

						# Generate dummy bounding boxes
						__magic_name__							=    [[[48, 84, 73, 1_28]]] * 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)
						__magic_name__							=    self._generate_dummy_images(__UpperCamelCase  , __UpperCamelCase  , __UpperCamelCase  , __UpperCamelCase      )

						__magic_name__							=    dict(
						    processor(
						        __UpperCamelCase  , text=__UpperCamelCase  , boxes=__UpperCamelCase  , return_tensors=__UpperCamelCase  , )      )

						return inputs




