



'''simple docstring'''





import os
from shutil import copyfile
from typing import Any, Dict, List, Optional, Tuple

import sentencepiece as spm

from ...tokenization_utils import AddedToken, PreTrainedTokenizer
from ...utils import logging


A__    :   Dict           =					logging.get_logger(__name__)

A__    :   List[Any]           =					'''▁'''

A__    :   Tuple           =					{'''vocab_file''': '''sentencepiece.bpe.model'''}

A__    :   Dict           =					{
    '''vocab_file''': {
        '''xlm-roberta-base''': '''https://huggingface.co/xlm-roberta-base/resolve/main/sentencepiece.bpe.model''',
        '''xlm-roberta-large''': '''https://huggingface.co/xlm-roberta-large/resolve/main/sentencepiece.bpe.model''',
        '''xlm-roberta-large-finetuned-conll02-dutch''': (
            '''https://huggingface.co/xlm-roberta-large-finetuned-conll02-dutch/resolve/main/sentencepiece.bpe.model'''
        ),
        '''xlm-roberta-large-finetuned-conll02-spanish''': (
            '''https://huggingface.co/xlm-roberta-large-finetuned-conll02-spanish/resolve/main/sentencepiece.bpe.model'''
        ),
        '''xlm-roberta-large-finetuned-conll03-english''': (
            '''https://huggingface.co/xlm-roberta-large-finetuned-conll03-english/resolve/main/sentencepiece.bpe.model'''
        ),
        '''xlm-roberta-large-finetuned-conll03-german''': (
            '''https://huggingface.co/xlm-roberta-large-finetuned-conll03-german/resolve/main/sentencepiece.bpe.model'''
        ),
    }
}

A__    :   List[Any]           =					{
    '''xlm-roberta-base''': 5_1_2,
    '''xlm-roberta-large''': 5_1_2,
    '''xlm-roberta-large-finetuned-conll02-dutch''': 5_1_2,
    '''xlm-roberta-large-finetuned-conll02-spanish''': 5_1_2,
    '''xlm-roberta-large-finetuned-conll03-english''': 5_1_2,
    '''xlm-roberta-large-finetuned-conll03-german''': 5_1_2,
}



class  snake_case__						(    SCREAMING_SNAKE_CASE_				):
 A__				= VOCAB_FILES_NAMES
 A__				= PRETRAINED_VOCAB_FILES_MAP
 A__				= PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
 A__				= ['''input_ids''', '''attention_mask''']
 def __init__(   self						:							Union[str, Any]      ,     __a						:							str      ,     __a						:							List[str]="<s>"      ,     __a						:							str="</s>"      ,     __a						:							Optional[int]="</s>"      ,     __a						:							List[Any]="<s>"      ,     __a						:							List[Any]="<unk>"      ,     __a						:							Union[str, Any]="<pad>"      ,     __a						:							Optional[Any]="<mask>"      ,     __a						:							Optional[Dict[str, Any]] = None      ,     **__a						:							int      ,     )      ->   None:







       '''simple docstring'''
       # Mask token behave like a normal word, i.e. include the space before it
       __snake_case :   Union[str, Any]													=    AddedToken(__a      ,     lstrip=__a      ,     rstrip=__a  ) if isinstance(__a      ,     __a  ) else mask_token

       __snake_case :   List[Any]													=    {} if sp_model_kwargs is None else sp_model_kwargs

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

       __snake_case :   Any													=    spm.SentencePieceProcessor(**self.sp_model_kwargs  )
       self.sp_model.Load(str(__a  )  )
       __snake_case :   Tuple													=    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'

       # Mimic fairseq token-to-id alignment for the first 4 token
       __snake_case :   Tuple													=    {'<s>': 0, '<pad>': 1, '</s>': 2, '<unk>': 3}

       # The first "real" token "," has position 4 in the original fairseq vocab and position 3 in the spm vocab
       __snake_case :   Union[str, Any]													=    1

       __snake_case :   List[str]													=    len(self.sp_model  ) + self.fairseq_offset
       __snake_case :   Union[str, Any]													=    {v: k for k, v in self.fairseq_tokens_to_ids.items()}
 def __getstate__(   self						:							List[Any]  )      ->   Optional[Any]:







       '''simple docstring'''
       __snake_case :   Optional[int]													=    self.__dict__.copy()
       __snake_case :   List[Any]													=    None
       __snake_case :   Any													=    self.sp_model.serialized_model_proto()
       return state
 def __setstate__(   self						:							Optional[Any]      ,     __a						:							str  )      ->   Optional[Any]:







       '''simple docstring'''
       __snake_case :   Optional[int]													=    d

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

       __snake_case :   List[str]													=    spm.SentencePieceProcessor(**self.sp_model_kwargs  )
       self.sp_model.LoadFromSerializedProto(self.sp_model_proto  )
 def A_   (   self						:							List[Any]      ,     __a						:							List[int]      ,     __a						:							Optional[List[int]] = None  )      ->   List[int]:







       '''simple docstring'''

       if token_ids_a is None:
             return [self.cls_token_id] + token_ids_a + [self.sep_token_id]
       __snake_case :   Optional[Any]													=    [self.cls_token_id]
       __snake_case :   List[Any]													=    [self.sep_token_id]
       return cls + token_ids_a + sep + sep + token_ids_a + sep
 def A_   (   self						:							Optional[Any]      ,     __a						:							List[int]      ,     __a						:							Optional[List[int]] = None      ,     __a						:							bool = False  )      ->   List[int]:







       '''simple docstring'''

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

       if token_ids_a is None:
             return [1] + ([0] * len(__a  )) + [1]
       return [1] + ([0] * len(__a  )) + [1, 1] + ([0] * len(__a  )) + [1]
 def A_   (   self						:							int      ,     __a						:							List[int]      ,     __a						:							Optional[List[int]] = None  )      ->   List[int]:







       '''simple docstring'''
       __snake_case :   List[str]													=    [self.sep_token_id]
       __snake_case :   List[Any]													=    [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]
 @property
 def A_   (   self						:							Optional[Any]  )      ->   List[Any]:







       '''simple docstring'''
       return len(self.sp_model  ) + self.fairseq_offset + 1  # Add the <mask> token
 def A_   (   self						:							List[Any]  )      ->   Dict:







       '''simple docstring'''
       __snake_case :   Optional[Any]													=    {self.convert_ids_to_tokens(__a  ): i for i in range(self.vocab_size  )}
       vocab.update(self.added_tokens_encoder  )
       return vocab
 def A_   (   self						:							Dict      ,     __a						:							str  )      ->   List[str]:







       '''simple docstring'''
       return self.sp_model.encode(__a      ,     out_type=__a  )
 def A_   (   self						:							Tuple      ,     __a						:							Tuple  )      ->   str:







       '''simple docstring'''
       if token in self.fairseq_tokens_to_ids:
             return self.fairseq_tokens_to_ids[token]
       __snake_case :   Optional[int]													=    self.sp_model.PieceToId(__a  )

       # 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						:							Any      ,     __a						:							List[Any]  )      ->   Optional[Any]:







       '''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						:							Tuple      ,     __a						:							List[str]  )      ->   Union[str, Any]:







       '''simple docstring'''
       __snake_case :   Dict													=    ''.join(__a  ).replace(__a      ,     ' '  ).strip()
       return out_string





 def A_   (   self						:							Optional[int]      ,     __a						:							str      ,     __a						:							Optional[str] = None  )      ->   Tuple[str]:







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

       if os.path.abspath(self.vocab_file  ) != os.path.abspath(__a  ) and os.path.isfile(self.vocab_file  ):
             copyfile(self.vocab_file      ,     __a  )
       elif not os.path.isfile(self.vocab_file  ):
             with open(__a      ,     'wb'  ) as fi:
                   __snake_case :   Union[str, Any]													=    self.sp_model.serialized_model_proto()
                   fi.write(__a  )

       return (out_vocab_file,)








'''simple docstring'''





from typing import TYPE_CHECKING

# rely on isort to merge the imports
from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


A__    :   List[str]           =					{
    '''configuration_autoformer''': [
        '''AUTOFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''AutoformerConfig''',
    ],
}

try:
    if not is_torch_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    A__    :   Optional[Any]           =					[
        '''AUTOFORMER_PRETRAINED_MODEL_ARCHIVE_LIST''',
        '''AutoformerForPrediction''',
        '''AutoformerModel''',
        '''AutoformerPreTrainedModel''',
    ]


if TYPE_CHECKING:
    from .configuration_autoformer import (
        AUTOFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP,
        AutoformerConfig,
    )

    try:
        if not is_torch_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_autoformer import (
            AUTOFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
            AutoformerForPrediction,
            AutoformerModel,
            AutoformerPreTrainedModel,
        )

else:
    import sys

    A__    :   Optional[int]           =					_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)



