






"""simple docstring"""
import collections
import os
from shutil import copyfile
from typing import Any, Dict, List, Optional, Tuple

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


snake_case : Any     		=		logging.get_logger(__name__)

snake_case : Optional[int]     		=		"""▁"""

snake_case : List[Any]     		=		{"""vocab_file""": """prophetnet.tokenizer"""}

snake_case : Union[str, Any]     		=		{
    """vocab_file""": {
        """microsoft/xprophetnet-large-wiki100-cased""": (
            """https://huggingface.co/microsoft/xprophetnet-large-wiki100-cased/resolve/main/prophetnet.tokenizer"""
        ),
    }
}

snake_case : Any     		=		{
    """microsoft/xprophetnet-large-wiki100-cased""": {"""do_lower_case""": False},
}

snake_case : Tuple     		=		{
    """microsoft/xprophetnet-large-wiki100-cased""": 5_1_2,
}


def 							A						(				__snake_case: Optional[Any]  )    ->		Any:

       """simple docstring"""





       __magic_name__      				=    collections.OrderedDict()
       with open(__snake_case ,     'r' ,     encoding='utf-8'  ) as reader:
              __magic_name__      				=    reader.readlines()
       for index, token in enumerate(__snake_case  ):
              __magic_name__      				=    token.rstrip('\n'  )
              __magic_name__      				=    index
       return vocab






class        UpperCamelCase__ (				a_):







    """simple docstring"""
    __UpperCAmelCase           = VOCAB_FILES_NAMES
    __UpperCAmelCase           = PRETRAINED_VOCAB_FILES_MAP
    __UpperCAmelCase           = PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
    __UpperCAmelCase           = ["""input_ids""", """attention_mask"""]







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





           '''simple docstring'''

           __magic_name__      				=    {} if sp_model_kwargs is None else sp_model_kwargs

           super().__init__(
               bos_token=UpperCamelCase_				,    eos_token=UpperCamelCase_				,    sep_token=UpperCamelCase_				,    unk_token=UpperCamelCase_				,    pad_token=UpperCamelCase_				,    cls_token=UpperCamelCase_				,    mask_token=UpperCamelCase_				,    sp_model_kwargs=self.sp_model_kwargs				,    **UpperCamelCase_				,    )

           try:
                  import sentencepiece as spm
           except ImportError:
                  logger.warning(
                      'You need to install SentencePiece to use XLMRobertaTokenizer: https://github.com/google/sentencepiece'
                      ' pip install sentencepiece' )
                  raise

           __magic_name__      				=    spm.SentencePieceProcessor(**self.sp_model_kwargs )
           self.sp_model.Load(str(UpperCamelCase_ ) )
           __magic_name__      				=    vocab_file

           # Original fairseq vocab and spm vocab must be "aligned":
           # Vocab    |    0    |    1    |   2    |    3    |  4  |  5  |  6  |   7   |   8   |  9
           # -------- | ------- | ------- | ------ | ------- | --- | --- | --- | ----- | ----- | ----
           # fairseq  | '<s>'   | '<pad>' | '</s>' | '<unk>' | ',' | '.' | '▁' | 's'   | '▁de' | '-'
           # spm      | '<unk>' | '<s>'   | '</s>' | ','     | '.' | '▁' | 's' | '▁de' | '-'   | '▁a'

           # put special tokens and [unused] tokens into the vocab
           __magic_name__      				=    {'[PAD]': 0, '[CLS]': 1, '[SEP]': 2, '[UNK]': 3, '[MASK]': 4}

           for i in range(1_0 ):
                  __magic_name__      				=    f"""[unused{i}]"""
                  __magic_name__      				=    5 + i

           # The first "real" token "," has position 15 in the embedding vocab and position 3 in the spm vocab
           __magic_name__      				=    1_2
           __magic_name__      				=    {v: k for k, v in self.fairseq_tokens_to_ids.items()}
           for k in self.fairseq_tokens_to_ids.keys():
                  self.unique_no_split_tokens.append(UpperCamelCase_ )







    def __getstate__(		self :	int ):





           '''simple docstring'''

           __magic_name__      				=    self.__dict__.copy()
           __magic_name__      				=    None
           return state







    def __setstate__(		self :	Dict				,    UpperCamelCase_ :	Optional[int] ):





           '''simple docstring'''

           __magic_name__      				=    d
           try:
                  import sentencepiece as spm
           except ImportError:
                  logger.warning(
                      'You need to install SentencePiece to use XLMRobertaTokenizer: https://github.com/google/sentencepiece'
                      ' pip install sentencepiece' )
                  raise

           # for backward compatibility
           if not hasattr(self				,    'sp_model_kwargs' ):
                  __magic_name__      				=    {}

           __magic_name__      				=    spm.SentencePieceProcessor(**self.sp_model_kwargs )
           self.sp_model.Load(self.vocab_file )







    def 				a__			(		self :	List[Any]				,    UpperCamelCase_ :	List[int]				,    UpperCamelCase_ :	Optional[List[int]] = None				,    UpperCamelCase_ :	bool = False ):





           '''simple docstring'''

           if already_has_special_tokens:
                  return super().get_special_tokens_mask(
                      token_ids_a=UpperCamelCase_				,    token_ids_a=UpperCamelCase_				,    already_has_special_tokens=UpperCamelCase_ )

           if token_ids_a is None:
                  return ([0] * len(UpperCamelCase_ )) + [1]
           return ([0] * len(UpperCamelCase_ )) + [1] + ([0] * len(UpperCamelCase_ )) + [1]







    def 				a__			(		self :	List[str]				,    UpperCamelCase_ :	List[int]				,    UpperCamelCase_ :	Optional[List[int]] = None ):





           '''simple docstring'''

           __magic_name__      				=    [self.sep_token_id]

           if token_ids_a is None:
                  return len(token_ids_a + sep ) * [0]
           return len(token_ids_a + sep + sep + token_ids_a + sep ) * [0]







    @property
    def 				a__			(		self :	Dict ):





           '''simple docstring'''

           return len(self.sp_model ) + self.fairseq_offset







    def 				a__			(		self :	Union[str, Any] ):





           '''simple docstring'''

           __magic_name__      				=    {self.convert_ids_to_tokens(UpperCamelCase_ ): i for i in range(self.vocab_size )}
           vocab.update(self.added_tokens_encoder )
           return vocab







    def 				a__			(		self :	int				,    UpperCamelCase_ :	str ):





           '''simple docstring'''

           return self.sp_model.encode(UpperCamelCase_				,    out_type=UpperCamelCase_ )







    def 				a__			(		self :	str				,    UpperCamelCase_ :	Union[str, Any] ):





           '''simple docstring'''

           if token in self.fairseq_tokens_to_ids:
                  return self.fairseq_tokens_to_ids[token]
           __magic_name__      				=    self.sp_model.PieceToId(UpperCamelCase_ )

           # Need to return unknown token if the SP model returned 0
           return spm_id + self.fairseq_offset if spm_id else self.unk_token_id







    def 				a__			(		self :	Dict				,    UpperCamelCase_ :	int ):





           '''simple docstring'''

           if index in self.fairseq_ids_to_tokens:
                  return self.fairseq_ids_to_tokens[index]
           return self.sp_model.IdToPiece(index - self.fairseq_offset )







    def 				a__			(		self :	Dict				,    UpperCamelCase_ :	Optional[Any] ):





           '''simple docstring'''

           __magic_name__      				=    ''.join(UpperCamelCase_ ).replace(UpperCamelCase_				,    ' ' ).strip()
           return out_string







    def 				a__			(		self :	Tuple				,    UpperCamelCase_ :	str				,    UpperCamelCase_ :	Optional[str] = None ):





           '''simple docstring'''

           if not os.path.isdir(UpperCamelCase_ ):
                  logger.error(f"""Vocabulary path ({save_directory}) should be a directory""" )
                  return
           __magic_name__      				=    os.path.join(
               UpperCamelCase_				,    (filename_prefix + '-' if filename_prefix else '') + VOCAB_FILES_NAMES['vocab_file'] )

           if os.path.abspath(self.vocab_file ) != os.path.abspath(UpperCamelCase_ ) and os.path.isfile(self.vocab_file ):
                  copyfile(self.vocab_file				,    UpperCamelCase_ )
           elif not os.path.isfile(self.vocab_file ):
                  with open(UpperCamelCase_				,    'wb' ) as fi:
                         __magic_name__      				=    self.sp_model.serialized_model_proto()
                         fi.write(UpperCamelCase_ )

           return (out_vocab_file,)







    def 				a__			(		self :	int				,    UpperCamelCase_ :	List[int]				,    UpperCamelCase_ :	Optional[List[int]] = None ):





           '''simple docstring'''

           if token_ids_a is None:
                  return token_ids_a + [self.sep_token_id]
           __magic_name__      				=    [self.sep_token_id]
           return token_ids_a + sep + token_ids_a + sep







"""simple docstring"""
import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from .tokenization_lxmert import LxmertTokenizer


snake_case : List[Any]     		=		{"""vocab_file""": """vocab.txt""", """tokenizer_file""": """tokenizer.json"""}

snake_case : List[Any]     		=		{
    """vocab_file""": {
        """unc-nlp/lxmert-base-uncased""": """https://huggingface.co/unc-nlp/lxmert-base-uncased/resolve/main/vocab.txt""",
    },
    """tokenizer_file""": {
        """unc-nlp/lxmert-base-uncased""": (
            """https://huggingface.co/unc-nlp/lxmert-base-uncased/resolve/main/tokenizer.json"""
        ),
    },
}

snake_case : Optional[int]     		=		{
    """unc-nlp/lxmert-base-uncased""": 5_1_2,
}

snake_case : List[Any]     		=		{
    """unc-nlp/lxmert-base-uncased""": {"""do_lower_case""": True},
}



class        UpperCamelCase__ (				a_):







    """simple docstring"""
    __UpperCAmelCase           = VOCAB_FILES_NAMES
    __UpperCAmelCase           = PRETRAINED_VOCAB_FILES_MAP
    __UpperCAmelCase           = PRETRAINED_INIT_CONFIGURATION
    __UpperCAmelCase           = PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
    __UpperCAmelCase           = LxmertTokenizer







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





           '''simple docstring'''

           super().__init__(
               UpperCamelCase_				,    tokenizer_file=UpperCamelCase_				,    do_lower_case=UpperCamelCase_				,    unk_token=UpperCamelCase_				,    sep_token=UpperCamelCase_				,    pad_token=UpperCamelCase_				,    cls_token=UpperCamelCase_				,    mask_token=UpperCamelCase_				,    tokenize_chinese_chars=UpperCamelCase_				,    strip_accents=UpperCamelCase_				,    **UpperCamelCase_				,    )

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

           __magic_name__      				=    do_lower_case







    def 				a__			(		self :	Dict				,    UpperCamelCase_ :	Optional[Any]				,    UpperCamelCase_ :	Optional[int]=None ):





           '''simple docstring'''

           __magic_name__      				=    [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 				a__			(		self :	int				,    UpperCamelCase_ :	List[int]				,    UpperCamelCase_ :	Optional[List[int]] = None ):





           '''simple docstring'''

           __magic_name__      				=    [self.sep_token_id]
           __magic_name__      				=    [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 :	Dict				,    UpperCamelCase_ :	str				,    UpperCamelCase_ :	Optional[str] = None ):





           '''simple docstring'''

           __magic_name__      				=    self._tokenizer.model.save(UpperCamelCase_				,    name=UpperCamelCase_ )
           return tuple(UpperCamelCase_ )