


import json
from typing import List, Optional, Tuple

from tokenizers import pre_tokenizers, processors

from ...tokenization_utils_base import AddedToken, BatchEncoding
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_roberta import RobertaTokenizer


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

_lowerCAmelCase:						Optional[int]   				=       {'''vocab_file''': '''vocab.json''', '''merges_file''': '''merges.txt''', '''tokenizer_file''': '''tokenizer.json'''}

_lowerCAmelCase:						Union[str, Any]   				=       {
    '''vocab_file''': {
        '''roberta-base''': '''https://huggingface.co/roberta-base/resolve/main/vocab.json''',
        '''roberta-large''': '''https://huggingface.co/roberta-large/resolve/main/vocab.json''',
        '''roberta-large-mnli''': '''https://huggingface.co/roberta-large-mnli/resolve/main/vocab.json''',
        '''distilroberta-base''': '''https://huggingface.co/distilroberta-base/resolve/main/vocab.json''',
        '''roberta-base-openai-detector''': '''https://huggingface.co/roberta-base-openai-detector/resolve/main/vocab.json''',
        '''roberta-large-openai-detector''': (
            '''https://huggingface.co/roberta-large-openai-detector/resolve/main/vocab.json'''
        ),
    },
    '''merges_file''': {
        '''roberta-base''': '''https://huggingface.co/roberta-base/resolve/main/merges.txt''',
        '''roberta-large''': '''https://huggingface.co/roberta-large/resolve/main/merges.txt''',
        '''roberta-large-mnli''': '''https://huggingface.co/roberta-large-mnli/resolve/main/merges.txt''',
        '''distilroberta-base''': '''https://huggingface.co/distilroberta-base/resolve/main/merges.txt''',
        '''roberta-base-openai-detector''': '''https://huggingface.co/roberta-base-openai-detector/resolve/main/merges.txt''',
        '''roberta-large-openai-detector''': (
            '''https://huggingface.co/roberta-large-openai-detector/resolve/main/merges.txt'''
        ),
    },
    '''tokenizer_file''': {
        '''roberta-base''': '''https://huggingface.co/roberta-base/resolve/main/tokenizer.json''',
        '''roberta-large''': '''https://huggingface.co/roberta-large/resolve/main/tokenizer.json''',
        '''roberta-large-mnli''': '''https://huggingface.co/roberta-large-mnli/resolve/main/tokenizer.json''',
        '''distilroberta-base''': '''https://huggingface.co/distilroberta-base/resolve/main/tokenizer.json''',
        '''roberta-base-openai-detector''': (
            '''https://huggingface.co/roberta-base-openai-detector/resolve/main/tokenizer.json'''
        ),
        '''roberta-large-openai-detector''': (
            '''https://huggingface.co/roberta-large-openai-detector/resolve/main/tokenizer.json'''
        ),
    },
}

_lowerCAmelCase:						Optional[int]   				=       {
    '''roberta-base''': 512,
    '''roberta-large''': 512,
    '''roberta-large-mnli''': 512,
    '''distilroberta-base''': 512,
    '''roberta-base-openai-detector''': 512,
    '''roberta-large-openai-detector''': 512,
}




class       lowercase_					(_snake_case   ):
				snake_case	    =VOCAB_FILES_NAMES
				snake_case	    =PRETRAINED_VOCAB_FILES_MAP
				snake_case	    =PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
				snake_case	    =['input_ids', 'attention_mask']
				snake_case	    =RobertaTokenizer





				def __init__(				self       ,  lowercase_=None       ,  lowercase_=None       ,  lowercase_=None       ,  lowercase_="replace"       ,  lowercase_="<s>"       ,  lowercase_="</s>"       ,  lowercase_="</s>"       ,  lowercase_="<s>"       ,  lowercase_="<unk>"       ,  lowercase_="<pad>"       ,  lowercase_="<mask>"       ,  lowercase_=False       ,  lowercase_=True       ,  **lowercase_       ,  )  -> List[Any]:
											super().__init__(
											    _lowerCamelCase       ,  _lowerCamelCase       ,  tokenizer_file=_lowerCamelCase       ,  errors=_lowerCamelCase       ,  bos_token=_lowerCamelCase       ,  eos_token=_lowerCamelCase       ,  sep_token=_lowerCamelCase       ,  cls_token=_lowerCamelCase       ,  unk_token=_lowerCamelCase       ,  pad_token=_lowerCamelCase       ,  mask_token=_lowerCamelCase       ,  add_prefix_space=_lowerCamelCase       ,  trim_offsets=_lowerCamelCase       ,  **_lowerCamelCase       ,  )

											a__      =json.loads(self.backend_tokenizer.pre_tokenizer.__getstate__())
											if pre_tok_state.get('add_prefix_space'       ,  _lowerCamelCase) != add_prefix_space:
																		a__      =getattr(_lowerCamelCase       ,  pre_tok_state.pop('type'))
																		a__      =add_prefix_space
																		a__      =pre_tok_class(**_lowerCamelCase)

											a__      =add_prefix_space

											a__      ='''post_processor'''
											a__      =getattr(self.backend_tokenizer       ,  _lowerCamelCase       ,  _lowerCamelCase)
											if tokenizer_component_instance:
																		a__      =json.loads(tokenizer_component_instance.__getstate__())

																		# The lists 'sep' and 'cls' must be cased in tuples for the object `post_processor_class`
																		if "sep" in state:
																									a__      =tuple(state['sep'])
																		if "cls" in state:
																									a__      =tuple(state['cls'])

																		a__      =False

																		if state.get('add_prefix_space'       ,  _lowerCamelCase) != add_prefix_space:
																									a__      =add_prefix_space
																									a__      =True

																		if state.get('trim_offsets'       ,  _lowerCamelCase) != trim_offsets:
																									a__      =trim_offsets
																									a__      =True

																		if changes_to_apply:
																									a__      =getattr(_lowerCamelCase       ,  state.pop('type'))
																									a__      =component_class(**_lowerCamelCase)
																									setattr(self.backend_tokenizer       ,  _lowerCamelCase       ,  _lowerCamelCase)





				@property
				def 						__UpperCamelCase    (				self)  -> Dict:
											if self._mask_token is None:
																		if self.verbose:
																									logger.error('Using mask_token, but it is not set yet.')
																		return None
											return str(self._mask_token)





				@mask_token.setter
				def 						__UpperCamelCase    (				self       ,  lowercase_)  -> Any:
											a__      =AddedToken(_lowerCamelCase       ,  lstrip=_lowerCamelCase       ,  rstrip=_lowerCamelCase) if isinstance(_lowerCamelCase       ,  _lowerCamelCase) else value
											a__      =value





				def 						__UpperCamelCase    (				self       ,  *lowercase_       ,  **lowercase_)  -> Optional[int]:
											a__      =kwargs.get('is_split_into_words'       ,  _lowerCamelCase)
											assert self.add_prefix_space or not is_split_into_words, (
											    F"""You need to instantiate {self.__class__.__name__} with add_prefix_space=True """
											    "to use it with pretokenized inputs."
											)

											return super()._batch_encode_plus(*_lowerCamelCase       ,  **_lowerCamelCase)





				def 						__UpperCamelCase    (				self       ,  *lowercase_       ,  **lowercase_)  -> Optional[Any]:
											a__      =kwargs.get('is_split_into_words'       ,  _lowerCamelCase)

											assert self.add_prefix_space or not is_split_into_words, (
											    F"""You need to instantiate {self.__class__.__name__} with add_prefix_space=True """
											    "to use it with pretokenized inputs."
											)

											return super()._encode_plus(*_lowerCamelCase       ,  **_lowerCamelCase)





				def 						__UpperCamelCase    (				self       ,  lowercase_       ,  lowercase_ = None)  -> Any:
											a__      =self._tokenizer.model.save(_lowerCamelCase       ,  name=_lowerCamelCase)
											return tuple(_lowerCamelCase)





				def 						__UpperCamelCase    (				self       ,  lowercase_       ,  lowercase_=None)  -> Optional[int]:
											a__      =[self.bos_token_id] + token_ids_a + [self.eos_token_id]
											if token_ids_a is None:
																		return output

											return output + [self.eos_token_id] + token_ids_a + [self.eos_token_id]





				def 						__UpperCamelCase    (				self       ,  lowercase_       ,  lowercase_ = None)  -> Tuple:
											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]





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


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

snake_case							:       Dict										=	{
    '''uclanlp/visualbert-vqa''': '''https://huggingface.co/uclanlp/visualbert-vqa/resolve/main/config.json''',
    '''uclanlp/visualbert-vqa-pre''': '''https://huggingface.co/uclanlp/visualbert-vqa-pre/resolve/main/config.json''',
    '''uclanlp/visualbert-vqa-coco-pre''': (
        '''https://huggingface.co/uclanlp/visualbert-vqa-coco-pre/resolve/main/config.json'''
    ),
    '''uclanlp/visualbert-vcr''': '''https://huggingface.co/uclanlp/visualbert-vcr/resolve/main/config.json''',
    '''uclanlp/visualbert-vcr-pre''': '''https://huggingface.co/uclanlp/visualbert-vcr-pre/resolve/main/config.json''',
    '''uclanlp/visualbert-vcr-coco-pre''': (
        '''https://huggingface.co/uclanlp/visualbert-vcr-coco-pre/resolve/main/config.json'''
    ),
    '''uclanlp/visualbert-nlvr2''': '''https://huggingface.co/uclanlp/visualbert-nlvr2/resolve/main/config.json''',
    '''uclanlp/visualbert-nlvr2-pre''': '''https://huggingface.co/uclanlp/visualbert-nlvr2-pre/resolve/main/config.json''',
    '''uclanlp/visualbert-nlvr2-coco-pre''': (
        '''https://huggingface.co/uclanlp/visualbert-nlvr2-coco-pre/resolve/main/config.json'''
    )
    # See all VisualBERT models at https://huggingface.co/models?filter=visual_bert
}







class 						_snake_case    ( _snake_case				):
 SCREAMING_SNAKE_CASE__ =			'visual_bert'




 def __init__(						self   ,    _lowerCamelCase=3_0522   ,    _lowerCamelCase=768   ,    _lowerCamelCase=512   ,    _lowerCamelCase=12   ,    _lowerCamelCase=12   ,    _lowerCamelCase=3072   ,    _lowerCamelCase="gelu"   ,    _lowerCamelCase=0.1   ,    _lowerCamelCase=0.1   ,    _lowerCamelCase=512   ,    _lowerCamelCase=2   ,    _lowerCamelCase=0.02   ,    _lowerCamelCase=1e-12   ,    _lowerCamelCase=False   ,    _lowerCamelCase=True   ,    _lowerCamelCase=1   ,    _lowerCamelCase=0   ,    _lowerCamelCase=2   ,    **_lowerCamelCase   ,    ):
       super().__init__(pad_token_id=_lowerCamelCase   ,    bos_token_id=_lowerCamelCase   ,    eos_token_id=_lowerCamelCase   ,    **_lowerCamelCase       )

       a		:Any									=			vocab_size
       a		:str									=			max_position_embeddings
       a		:str									=			hidden_size
       a		:List[Any]									=			visual_embedding_dim
       a		:str									=			num_hidden_layers
       a		:Optional[int]									=			num_attention_heads
       a		:int									=			intermediate_size
       a		:int									=			hidden_act
       a		:Union[str, Any]									=			hidden_dropout_prob
       a		:List[Any]									=			attention_probs_dropout_prob
       a		:int									=			initializer_range
       a		:List[Any]									=			type_vocab_size
       a		:str									=			layer_norm_eps
       a		:Optional[int]									=			bypass_transformer
       a		:str									=			special_visual_initialize





