



"""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


lowerCamelCase       	=						logging.get_logger(__name__)

lowerCamelCase       	=						"""▁"""

lowerCamelCase       	=						{"""vocab_file""": """sentencepiece.bpe.model""", """monolingual_vocab_file""": """dict.txt"""}

lowerCamelCase       	=						{
    """vocab_file""": {
        """vinai/bartpho-syllable""": """https://huggingface.co/vinai/bartpho-syllable/resolve/main/sentencepiece.bpe.model""",
    },
    """monolingual_vocab_file""": {
        """vinai/bartpho-syllable""": """https://huggingface.co/vinai/bartpho-syllable/resolve/main/dict.txt""",
    },
}

lowerCamelCase       	=						{"""vinai/bartpho-syllable""": 1_024}
class 				lowercase__       (   SCREAMING_SNAKE_CASE				):







       '''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      :  Optional[int]		,    _UpperCAmelCase      :  Tuple		,    _UpperCAmelCase      :  Dict="<s>"		,    _UpperCAmelCase      :  List[str]="</s>"		,    _UpperCAmelCase      :  List[Any]="</s>"		,    _UpperCAmelCase      :  int="<s>"		,    _UpperCAmelCase      :  Tuple="<unk>"		,    _UpperCAmelCase      :  List[Any]="<pad>"		,    _UpperCAmelCase      :  Tuple="<mask>"		,    _UpperCAmelCase      :  Optional[Dict[str, Any]] = None		,    **_UpperCAmelCase      :  Dict		,    )			->						None:


             '''simple docstring'''




             UpperCAmelCase_      			=							AddedToken(_UpperCAmelCase		,    lstrip=_UpperCAmelCase		,    rstrip=_UpperCAmelCase   ) if isinstance(_UpperCAmelCase		,    _UpperCAmelCase   ) else mask_token

             UpperCAmelCase_      			=							{} if sp_model_kwargs is None else sp_model_kwargs

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

             UpperCAmelCase_      			=							vocab_file
             UpperCAmelCase_      			=							monolingual_vocab_file
             UpperCAmelCase_      			=							spm.SentencePieceProcessor(**self.sp_model_kwargs   )
             self.sp_model.Load(str(_UpperCAmelCase   )   )

             # Load the reduced vocab

             # Keep order of special tokens for backward compatibility
             UpperCAmelCase_      			=							{}
             UpperCAmelCase_      			=							0
             for token in [bos_token, pad_token, eos_token, unk_token, sep_token, cls_token]:
                   if str(_UpperCAmelCase   ) not in self.fairseq_tokens_to_ids:
                         UpperCAmelCase_      			=							cnt
                         cnt += 1
             with open(_UpperCAmelCase		,    "r"		,    encoding="utf-8"   ) as f:
                   for line in f.readlines():
                         UpperCAmelCase_      			=							line.strip().split()[0]
                         UpperCAmelCase_      			=							len(self.fairseq_tokens_to_ids   )
             if str(_UpperCAmelCase   ) not in self.fairseq_tokens_to_ids:
                   UpperCAmelCase_      			=							len(self.fairseq_tokens_to_ids   )

             UpperCAmelCase_      			=							{v: k for k, v in self.fairseq_tokens_to_ids.items()}



       def __getstate__(							self      :  int   )			->						List[str]:


             '''simple docstring'''




             UpperCAmelCase_      			=							self.__dict__.copy()
             UpperCAmelCase_      			=							None
             UpperCAmelCase_      			=							self.sp_model.serialized_model_proto()
             return state



       def __setstate__(							self      :  int		,    _UpperCAmelCase      :  Optional[int]   )			->						Dict:


             '''simple docstring'''




             UpperCAmelCase_      			=							d

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

             UpperCAmelCase_      			=							spm.SentencePieceProcessor(**self.sp_model_kwargs   )
             self.sp_model.LoadFromSerializedProto(self.sp_model_proto   )



       def 					lowercase__    (							self      :  Union[str, Any]		,    _UpperCAmelCase      :  List[int]		,    _UpperCAmelCase      :  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]
             UpperCAmelCase_      			=							[self.cls_token_id]
             UpperCAmelCase_      			=							[self.sep_token_id]
             return cls + token_ids_a + sep + sep + token_ids_a + sep



       def 					lowercase__    (							self      :  Union[str, Any]		,    _UpperCAmelCase      :  List[int]		,    _UpperCAmelCase      :  Optional[List[int]] = None		,    _UpperCAmelCase      :  bool = False   )			->						List[int]:


             '''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 [1] + ([0] * len(_UpperCAmelCase   )) + [1]
             return [1] + ([0] * len(_UpperCAmelCase   )) + [1, 1] + ([0] * len(_UpperCAmelCase   )) + [1]



       def 					lowercase__    (							self      :  Tuple		,    _UpperCAmelCase      :  List[int]		,    _UpperCAmelCase      :  Optional[List[int]] = None   )			->						List[int]:


             '''simple docstring'''




             UpperCAmelCase_      			=							[self.sep_token_id]
             UpperCAmelCase_      			=							[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 					lowercase__    (							self      :  Dict   )			->						Any:


             '''simple docstring'''




             return len(self.fairseq_ids_to_tokens   )



       def 					lowercase__    (							self      :  int   )			->						Dict:


             '''simple docstring'''




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



       def 					lowercase__    (							self      :  List[str]		,    _UpperCAmelCase      :  str   )			->						List[str]:


             '''simple docstring'''




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



       def 					lowercase__    (							self      :  str		,    _UpperCAmelCase      :  List[Any]   )			->						Any:


             '''simple docstring'''




             if token in self.fairseq_tokens_to_ids:
                   return self.fairseq_tokens_to_ids[token]
             else:
                   return self.unk_token_id



       def 					lowercase__    (							self      :  List[str]		,    _UpperCAmelCase      :  int   )			->						List[str]:


             '''simple docstring'''




             return self.fairseq_ids_to_tokens[index]



       def 					lowercase__    (							self      :  int		,    _UpperCAmelCase      :  int   )			->						Optional[int]:


             '''simple docstring'''




             UpperCAmelCase_      			=							"".join(_UpperCAmelCase   ).replace(_UpperCAmelCase		,    " "   ).strip()
             return out_string







       def 					lowercase__    (							self      :  Optional[Any]		,    _UpperCAmelCase      :  str		,    _UpperCAmelCase      :  Optional[str] = None   )			->						Tuple[str]:


             '''simple docstring'''




             if not os.path.isdir(_UpperCAmelCase   ):
                   logger.error(F"""Vocabulary path ({save_directory}) should be a directory"""   )
                   return
             UpperCAmelCase_      			=							os.path.join(
                 _UpperCAmelCase		,    (filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"]   )
             UpperCAmelCase_      			=							os.path.join(
                 _UpperCAmelCase		,    (filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["monolingual_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:
                         UpperCAmelCase_      			=							self.sp_model.serialized_model_proto()
                         fi.write(_UpperCAmelCase   )

             if os.path.abspath(self.monolingual_vocab_file   ) != os.path.abspath(
                 _UpperCAmelCase   ) and os.path.isfile(self.monolingual_vocab_file   ):
                   copyfile(self.monolingual_vocab_file		,    _UpperCAmelCase   )
             elif not os.path.isfile(self.monolingual_vocab_file   ):
                   with open(_UpperCAmelCase		,    "w"		,    encoding="utf-8"   ) as fp:
                         for token in self.fairseq_tokens_to_ids:
                               if token not in self.all_special_tokens:
                                     fp.write(F"""{str(_UpperCAmelCase   )} \n"""   )

             return out_vocab_file, out_monolingual_vocab_file









"""simple docstring"""





from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


lowerCamelCase       	=						logging.get_logger(__name__)

lowerCamelCase       	=						{
    """roberta-base""": """https://huggingface.co/roberta-base/resolve/main/config.json""",
    """roberta-large""": """https://huggingface.co/roberta-large/resolve/main/config.json""",
    """roberta-large-mnli""": """https://huggingface.co/roberta-large-mnli/resolve/main/config.json""",
    """distilroberta-base""": """https://huggingface.co/distilroberta-base/resolve/main/config.json""",
    """roberta-base-openai-detector""": """https://huggingface.co/roberta-base-openai-detector/resolve/main/config.json""",
    """roberta-large-openai-detector""": """https://huggingface.co/roberta-large-openai-detector/resolve/main/config.json""",
}
class 				lowercase__       (   SCREAMING_SNAKE_CASE				):







       '''simple docstring'''


       UpperCamelCase						=					'''roberta'''



       def __init__(							self      :  int		,    _UpperCAmelCase      :  List[Any]=50265		,    _UpperCAmelCase      :  str=768		,    _UpperCAmelCase      :  List[str]=12		,    _UpperCAmelCase      :  int=12		,    _UpperCAmelCase      :  Tuple=3072		,    _UpperCAmelCase      :  Dict="gelu"		,    _UpperCAmelCase      :  int=0.1		,    _UpperCAmelCase      :  Optional[int]=0.1		,    _UpperCAmelCase      :  Optional[int]=512		,    _UpperCAmelCase      :  Optional[Any]=2		,    _UpperCAmelCase      :  Optional[int]=0.02		,    _UpperCAmelCase      :  Optional[Any]=1e-12		,    _UpperCAmelCase      :  Dict=1		,    _UpperCAmelCase      :  str=0		,    _UpperCAmelCase      :  int=2		,    _UpperCAmelCase      :  Tuple="absolute"		,    _UpperCAmelCase      :  Any=True		,    _UpperCAmelCase      :  int=None		,    **_UpperCAmelCase      :  List[str]		,    )			->						Any:


             '''simple docstring'''




             super().__init__(pad_token_id=_UpperCAmelCase		,    bos_token_id=_UpperCAmelCase		,    eos_token_id=_UpperCAmelCase		,    **_UpperCAmelCase   )

             UpperCAmelCase_      			=							vocab_size
             UpperCAmelCase_      			=							hidden_size
             UpperCAmelCase_      			=							num_hidden_layers
             UpperCAmelCase_      			=							num_attention_heads
             UpperCAmelCase_      			=							hidden_act
             UpperCAmelCase_      			=							intermediate_size
             UpperCAmelCase_      			=							hidden_dropout_prob
             UpperCAmelCase_      			=							attention_probs_dropout_prob
             UpperCAmelCase_      			=							max_position_embeddings
             UpperCAmelCase_      			=							type_vocab_size
             UpperCAmelCase_      			=							initializer_range
             UpperCAmelCase_      			=							layer_norm_eps
             UpperCAmelCase_      			=							position_embedding_type
             UpperCAmelCase_      			=							use_cache
             UpperCAmelCase_      			=							classifier_dropout



class 				lowercase__       (   SCREAMING_SNAKE_CASE				):







       '''simple docstring'''


       @property
       def 					lowercase__    (							self      :  List[Any]   )			->						Mapping[str, Mapping[int, str]]:


             '''simple docstring'''




             if self.task == "multiple-choice":
                   UpperCAmelCase_      			=							{0: "batch", 1: "choice", 2: "sequence"}
             else:
                   UpperCAmelCase_      			=							{0: "batch", 1: "sequence"}
             return OrderedDict(
                 [
                     ("input_ids", dynamic_axis),
                     ("attention_mask", dynamic_axis),
                 ]   )




