





import json
import os
from typing import Optional, Tuple

from ...tokenization_utils import PreTrainedTokenizer
from ...utils import logging


lowercase__						:      Optional[Any]	=    logging.get_logger(__name__)

lowercase__						:      Tuple	=    {'vocab_file': 'vocab.json'}

lowercase__						:      Union[str, Any]	=    {
    'vocab_file': {
        'mgp-str': 'https://huggingface.co/alibaba-damo/mgp-str-base/blob/main/vocab.json',
    }
}

lowercase__						:      int	=    {'mgp-str': 27}
class     __lowerCAmelCase					(   lowerCamelCase__			):






       """simple docstring"""
       _snake_case     :					Union[str, Any]						    =   VOCAB_FILES_NAMES
       _snake_case     :					int						    =   PRETRAINED_VOCAB_FILES_MAP
       _snake_case     :					List[str]						    =   PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES





       def __init__(							self       :		Optional[int]	,			lowerCAmelCase__       :		Any	,			lowerCAmelCase__       :		Union[str, Any]="[GO]"	,			lowerCAmelCase__       :		List[str]="[GO]"	,			lowerCAmelCase__       :		List[str]="[s]"	,			lowerCAmelCase__       :		str="[GO]"	,			**lowerCAmelCase__       :		Optional[int]					)   ->					Any:

            '''simple docstring'''




            super().__init__(
                unk_token=snake_case__	,			bos_token=snake_case__	,			eos_token=snake_case__	,			pad_token=snake_case__	,			**snake_case__	,			)

            with open(snake_case__	,			encoding='''utf-8'''					) as vocab_handle:
                 _UpperCamelCase       =	json.load(snake_case__					)
            _UpperCamelCase       =	{v: k for k, v in self.vocab.items()}





       @property
       def snake_case__						(							self       :		List[str]					)   ->					Optional[int]:

            '''simple docstring'''




            return len(self.vocab					)





       def snake_case__						(							self       :		str					)   ->					Union[str, Any]:

            '''simple docstring'''




            return dict(self.vocab	,			**self.added_tokens_encoder					)





       def snake_case__						(							self       :		Any	,			lowerCAmelCase__       :		Optional[int]					)   ->					Optional[Any]:

            '''simple docstring'''




            _UpperCamelCase       =	[]
            for s in text:
                 char_tokens.extend(snake_case__					)
            return char_tokens





       def snake_case__						(							self       :		Dict	,			lowerCAmelCase__       :		Optional[int]					)   ->					Union[str, Any]:

            '''simple docstring'''




            return self.vocab.get(snake_case__	,			self.vocab.get(self.unk_token					)					)





       def snake_case__						(							self       :		Any	,			lowerCAmelCase__       :		Tuple					)   ->					Union[str, Any]:

            '''simple docstring'''




            return self.decoder.get(snake_case__					)







       def snake_case__						(							self       :		List[str]	,			lowerCAmelCase__       :		Optional[Any]	,			lowerCAmelCase__       :		int = None					)   ->					Tuple[str]:

            '''simple docstring'''




            if not os.path.isdir(snake_case__					):
                 logger.error('''Vocabulary path ({}) should be a directory'''.format(snake_case__					)					)
                 return
            _UpperCamelCase       =	os.path.join(
                snake_case__	,			(filename_prefix + '''-''' if filename_prefix else '''''') + VOCAB_FILES_NAMES['''vocab_file''']					)

            with open(snake_case__	,			'''w'''	,			encoding='''utf-8'''					) as f:
                 f.write(json.dumps(self.vocab	,			indent=2	,			sort_keys=snake_case__	,			ensure_ascii=snake_case__					) + '''\n'''					)

            return (vocab_file,)










'''simple docstring'''

from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowercase__						:      List[Any]	=    logging.get_logger(__name__)

lowercase__						:      Tuple	=    {
    'microsoft/trocr-base-handwritten': (
        'https://huggingface.co/microsoft/trocr-base-handwritten/resolve/main/config.json'
    ),
    # See all TrOCR models at https://huggingface.co/models?filter=trocr
}
class     __lowerCAmelCase					(   __magic_name__			):






       """simple docstring"""
       _snake_case     :					int						    =   'trocr'
       _snake_case     :					List[str]						    =   ['past_key_values']
       _snake_case     :					Tuple						    =   {
           'num_attention_heads': 'decoder_attention_heads',
           'hidden_size': 'd_model',
           'num_hidden_layers': 'decoder_layers',
       }





       def __init__(							self       :		Tuple	,			lowerCAmelCase__       :		Union[str, Any]=50265	,			lowerCAmelCase__       :		List[Any]=1024	,			lowerCAmelCase__       :		List[str]=12	,			lowerCAmelCase__       :		int=16	,			lowerCAmelCase__       :		List[Any]=4096	,			lowerCAmelCase__       :		Optional[int]="gelu"	,			lowerCAmelCase__       :		int=512	,			lowerCAmelCase__       :		Optional[Any]=0.1	,			lowerCAmelCase__       :		Optional[int]=0.0	,			lowerCAmelCase__       :		Dict=0.0	,			lowerCAmelCase__       :		Tuple=2	,			lowerCAmelCase__       :		Dict=0.02	,			lowerCAmelCase__       :		Tuple=0.0	,			lowerCAmelCase__       :		int=True	,			lowerCAmelCase__       :		Optional[Any]=False	,			lowerCAmelCase__       :		Any=True	,			lowerCAmelCase__       :		Dict=True	,			lowerCAmelCase__       :		Optional[int]=1	,			lowerCAmelCase__       :		List[Any]=0	,			lowerCAmelCase__       :		Any=2	,			**lowerCAmelCase__       :		Optional[int]	,			)   ->					Any:

            '''simple docstring'''




            _UpperCamelCase       =	vocab_size
            _UpperCamelCase       =	d_model
            _UpperCamelCase       =	decoder_layers
            _UpperCamelCase       =	decoder_attention_heads
            _UpperCamelCase       =	decoder_ffn_dim
            _UpperCamelCase       =	activation_function
            _UpperCamelCase       =	max_position_embeddings
            _UpperCamelCase       =	dropout
            _UpperCamelCase       =	attention_dropout
            _UpperCamelCase       =	activation_dropout
            _UpperCamelCase       =	init_std
            _UpperCamelCase       =	decoder_layerdrop
            _UpperCamelCase       =	use_cache
            _UpperCamelCase       =	scale_embedding
            _UpperCamelCase       =	use_learned_position_embeddings
            _UpperCamelCase       =	layernorm_embedding

            super().__init__(
                pad_token_id=lowerCAmelCase__	,			bos_token_id=lowerCAmelCase__	,			eos_token_id=lowerCAmelCase__	,			decoder_start_token_id=lowerCAmelCase__	,			**lowerCAmelCase__	,			)



