






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


lowercase_    					=					logging.get_logger(__name__)

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

lowercase_    					=					{
    '''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'''
        ),
    },
}

lowercase_    					=					{
    '''microsoft/layoutlm-base-uncased''': 512,
    '''microsoft/layoutlm-large-uncased''': 512,
}

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


class  snake_case		(							A__						):


   '''simple docstring'''

   A_						:     Union[str, Any]									=			VOCAB_FILES_NAMES
   A_						:     Any									=			PRETRAINED_VOCAB_FILES_MAP
   A_						:     int									=			PRETRAINED_INIT_CONFIGURATION
   A_						:     Optional[Any]									=			PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
   A_						:     str									=			LayoutLMTokenizer


   def __init__(     self			:					List[str],	_lowerCamelCase			:					Optional[int]=None,	_lowerCamelCase			:					List[Any]=None,	_lowerCamelCase			:					int=True,	_lowerCamelCase			:					List[str]="[UNK]",	_lowerCamelCase			:					Union[str, Any]="[SEP]",	_lowerCamelCase			:					Optional[int]="[PAD]",	_lowerCamelCase			:					Optional[int]="[CLS]",	_lowerCamelCase			:					Tuple="[MASK]",	_lowerCamelCase			:					Any=True,	_lowerCamelCase			:					List[Any]=None,	**_lowerCamelCase			:					str,	):

     '''simple docstring'''
     super().__init__(
         _A,	tokenizer_file=_A,	do_lower_case=_A,	unk_token=_A,	sep_token=_A,	pad_token=_A,	cls_token=_A,	mask_token=_A,	tokenize_chinese_chars=_A,	strip_accents=_A,	**_A,	)

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

     __A						      =			do_lower_case


   def     _SCREAMING_SNAKE_CASE    (     self			:					str,	_lowerCamelCase			:					Optional[int],	_lowerCamelCase			:					List[Any]=None  ):

     '''simple docstring'''
     __A						      =			[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     _SCREAMING_SNAKE_CASE    (     self			:					str,	_lowerCamelCase			:					List[int],	_lowerCamelCase			:					Optional[List[int]] = None  ):

     '''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     _SCREAMING_SNAKE_CASE    (     self			:					Any,	_lowerCamelCase			:					str,	_lowerCamelCase			:					Optional[str] = None  ):

     '''simple docstring'''
     __A						      =			self._tokenizer.model.save(_A,	name=_A  )
     return tuple(_A  )












"""simple docstring"""


from collections import OrderedDict
from dataclasses import fields
from typing import Any, Tuple

import numpy as np

from .import_utils import is_torch_available



def  lowerCAmelCase    (   __UpperCamelCase			):




  """simple docstring"""







  if is_torch_available():
    import torch

    if isinstance(__UpperCamelCase		,	torch.Tensor			):
      return True

  return isinstance(__UpperCamelCase		,	np.ndarray			)





class  snake_case		(							_lowerCAmelCase						):


   '''simple docstring'''

   def     _SCREAMING_SNAKE_CASE    (     self			:					Dict  ):

     '''simple docstring'''
     __A						      =			fields(self  )

     # Safety and consistency checks
     if not len(_lowerCamelCase  ):
       raise ValueError(f'{self.__class__.__name__} has no fields.'  )

     __A						      =			getattr(self,	class_fields[0].name  )
     __A						      =			all(getattr(self,	field.name  ) is None for field in class_fields[1:]  )

     if other_fields_are_none and isinstance(_lowerCamelCase,	_lowerCamelCase  ):
       for key, value in first_field.items():
         __A						      =			value
     else:
       for field in class_fields:
         __A						      =			getattr(self,	field.name  )
         if v is not None:
           __A						      =			v


   def __delitem__(     self			:					Dict,	*_lowerCamelCase			:					int,	**_lowerCamelCase			:					Any  ):

     '''simple docstring'''
     raise Exception(f'You cannot use ``__delitem__`` on a {self.__class__.__name__} instance.'  )


   def     _SCREAMING_SNAKE_CASE    (     self			:					List[Any],	*_lowerCamelCase			:					List[str],	**_lowerCamelCase			:					str  ):

     '''simple docstring'''
     raise Exception(f'You cannot use ``setdefault`` on a {self.__class__.__name__} instance.'  )


   def     _SCREAMING_SNAKE_CASE    (     self			:					Any,	*_lowerCamelCase			:					Optional[Any],	**_lowerCamelCase			:					str  ):

     '''simple docstring'''
     raise Exception(f'You cannot use ``pop`` on a {self.__class__.__name__} instance.'  )


   def     _SCREAMING_SNAKE_CASE    (     self			:					List[str],	*_lowerCamelCase			:					Any,	**_lowerCamelCase			:					Optional[int]  ):

     '''simple docstring'''
     raise Exception(f'You cannot use ``update`` on a {self.__class__.__name__} instance.'  )


   def __getitem__(     self			:					int,	_lowerCamelCase			:					List[Any]  ):

     '''simple docstring'''
     if isinstance(_lowerCamelCase,	_lowerCamelCase  ):
       __A						      =			dict(self.items()  )
       return inner_dict[k]
     else:
       return self.to_tuple()[k]


   def __setattr__(     self			:					Optional[int],	_lowerCamelCase			:					Tuple,	_lowerCamelCase			:					Union[str, Any]  ):

     '''simple docstring'''
     if name in self.keys() and value is not None:
       # Don't call self.__setitem__ to avoid recursion errors
       super().__setitem__(_lowerCamelCase,	_lowerCamelCase  )
     super().__setattr__(_lowerCamelCase,	_lowerCamelCase  )


   def __setitem__(     self			:					List[str],	_lowerCamelCase			:					Optional[int],	_lowerCamelCase			:					str  ):

     '''simple docstring'''
     # Will raise a KeyException if needed
     super().__setitem__(_lowerCamelCase,	_lowerCamelCase  )
     # Don't call self.__setattr__ to avoid recursion errors
     super().__setattr__(_lowerCamelCase,	_lowerCamelCase  )






   def     _SCREAMING_SNAKE_CASE    (     self			:					Any  ):

     '''simple docstring'''
     return tuple(self[k] for k in self.keys()  )




