





import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_base import BatchEncoding
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import PaddingStrategy, logging
from .tokenization_realm import RealmTokenizer


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

_lowerCAmelCase				:   List[str]						       =						{'''vocab_file''': '''vocab.txt''', '''tokenizer_file''': '''tokenizer.json'''}

_lowerCAmelCase				:   List[Any]						       =						{
    '''vocab_file''': {
        '''google/realm-cc-news-pretrained-embedder''': (
            '''https://huggingface.co/google/realm-cc-news-pretrained-embedder/resolve/main/vocab.txt'''
        ),
        '''google/realm-cc-news-pretrained-encoder''': (
            '''https://huggingface.co/google/realm-cc-news-pretrained-encoder/resolve/main/vocab.txt'''
        ),
        '''google/realm-cc-news-pretrained-scorer''': (
            '''https://huggingface.co/google/realm-cc-news-pretrained-scorer/resolve/main/vocab.txt'''
        ),
        '''google/realm-cc-news-pretrained-openqa''': (
            '''https://huggingface.co/google/realm-cc-news-pretrained-openqa/aresolve/main/vocab.txt'''
        ),
        '''google/realm-orqa-nq-openqa''': '''https://huggingface.co/google/realm-orqa-nq-openqa/resolve/main/vocab.txt''',
        '''google/realm-orqa-nq-reader''': '''https://huggingface.co/google/realm-orqa-nq-reader/resolve/main/vocab.txt''',
        '''google/realm-orqa-wq-openqa''': '''https://huggingface.co/google/realm-orqa-wq-openqa/resolve/main/vocab.txt''',
        '''google/realm-orqa-wq-reader''': '''https://huggingface.co/google/realm-orqa-wq-reader/resolve/main/vocab.txt''',
    },
    '''tokenizer_file''': {
        '''google/realm-cc-news-pretrained-embedder''': (
            '''https://huggingface.co/google/realm-cc-news-pretrained-embedder/resolve/main/tokenizer.jsont'''
        ),
        '''google/realm-cc-news-pretrained-encoder''': (
            '''https://huggingface.co/google/realm-cc-news-pretrained-encoder/resolve/main/tokenizer.json'''
        ),
        '''google/realm-cc-news-pretrained-scorer''': (
            '''https://huggingface.co/google/realm-cc-news-pretrained-scorer/resolve/main/tokenizer.json'''
        ),
        '''google/realm-cc-news-pretrained-openqa''': (
            '''https://huggingface.co/google/realm-cc-news-pretrained-openqa/aresolve/main/tokenizer.json'''
        ),
        '''google/realm-orqa-nq-openqa''': (
            '''https://huggingface.co/google/realm-orqa-nq-openqa/resolve/main/tokenizer.json'''
        ),
        '''google/realm-orqa-nq-reader''': (
            '''https://huggingface.co/google/realm-orqa-nq-reader/resolve/main/tokenizer.json'''
        ),
        '''google/realm-orqa-wq-openqa''': (
            '''https://huggingface.co/google/realm-orqa-wq-openqa/resolve/main/tokenizer.json'''
        ),
        '''google/realm-orqa-wq-reader''': (
            '''https://huggingface.co/google/realm-orqa-wq-reader/resolve/main/tokenizer.json'''
        ),
    },
}

_lowerCAmelCase				:   int						       =						{
    '''google/realm-cc-news-pretrained-embedder''': 512,
    '''google/realm-cc-news-pretrained-encoder''': 512,
    '''google/realm-cc-news-pretrained-scorer''': 512,
    '''google/realm-cc-news-pretrained-openqa''': 512,
    '''google/realm-orqa-nq-openqa''': 512,
    '''google/realm-orqa-nq-reader''': 512,
    '''google/realm-orqa-wq-openqa''': 512,
    '''google/realm-orqa-wq-reader''': 512,
}

_lowerCAmelCase				:   Dict						       =						{
    '''google/realm-cc-news-pretrained-embedder''': {'''do_lower_case''': True},
    '''google/realm-cc-news-pretrained-encoder''': {'''do_lower_case''': True},
    '''google/realm-cc-news-pretrained-scorer''': {'''do_lower_case''': True},
    '''google/realm-cc-news-pretrained-openqa''': {'''do_lower_case''': True},
    '''google/realm-orqa-nq-openqa''': {'''do_lower_case''': True},
    '''google/realm-orqa-nq-reader''': {'''do_lower_case''': True},
    '''google/realm-orqa-wq-openqa''': {'''do_lower_case''': True},
    '''google/realm-orqa-wq-reader''': {'''do_lower_case''': True},
}


class        __magic_name__	(				lowerCamelCase__				):





     """simple docstring"""



     __UpperCamelCase            =  VOCAB_FILES_NAMES
     __UpperCamelCase            =  PRETRAINED_VOCAB_FILES_MAP
     __UpperCamelCase            =  PRETRAINED_INIT_CONFIGURATION
     __UpperCamelCase            =  PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
     __UpperCamelCase            =  RealmTokenizer



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





        '''simple docstring'''




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

        A_       :					Union[str, Any]        =      json.loads(self.backend_tokenizer.normalizer.__getstate__()	)
        if (
            normalizer_state.get("lowercase"      ,   snake_case	) != do_lower_case
            or normalizer_state.get("strip_accents"      ,   snake_case	) != strip_accents
            or normalizer_state.get("handle_chinese_chars"      ,   snake_case	) != tokenize_chinese_chars
        ):
           A_       :					Dict        =      getattr(snake_case      ,   normalizer_state.pop("type"	)	)
           A_       :					Dict        =      do_lower_case
           A_       :					Tuple        =      strip_accents
           A_       :					str        =      tokenize_chinese_chars
           A_       :					int        =      normalizer_class(**snake_case	)

        A_       :					int        =      do_lower_case



     def     SCREAMING_SNAKE_CASE		(				self							:Tuple      ,   snake_case							:Any      ,   **snake_case							:Any	):





        '''simple docstring'''




        A_       :					List[Any]        =      PaddingStrategy.MAX_LENGTH

        A_       :					str        =      text
        A_       :					Any        =      kwargs.pop("text_pair"      ,   snake_case	)
        A_       :					List[str]        =      kwargs.pop("return_tensors"      ,   snake_case	)

        A_       :					Any        =      {
            "input_ids": [],
            "attention_mask": [],
            "token_type_ids": [],
        }

        for idx, candidate_text in enumerate(snake_case	):
           if batch_text_pair is not None:
              A_       :					Optional[Any]        =      batch_text_pair[idx]
           else:
              A_       :					Optional[int]        =      None

           A_       :					Optional[int]        =      super().__call__(snake_case      ,   snake_case      ,   return_tensors=snake_case      ,   **snake_case	)

           A_       :					Union[str, Any]        =      encoded_candidates.get("input_ids"	)
           A_       :					Union[str, Any]        =      encoded_candidates.get("attention_mask"	)
           A_       :					Dict        =      encoded_candidates.get("token_type_ids"	)

           if encoded_input_ids is not None:
              output_data["input_ids"].append(snake_case	)
           if encoded_attention_mask is not None:
              output_data["attention_mask"].append(snake_case	)
           if encoded_token_type_ids is not None:
              output_data["token_type_ids"].append(snake_case	)

        A_       :					List[Any]        =      {key: item for key, item in output_data.items() if len(snake_case	) != 0}

        return BatchEncoding(snake_case      ,   tensor_type=snake_case	)



     def     SCREAMING_SNAKE_CASE		(				self							:List[str]      ,   snake_case							:Any      ,   snake_case							:Tuple=None	):





        '''simple docstring'''




        A_       :					Optional[int]        =      [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     SCREAMING_SNAKE_CASE		(				self							:Dict      ,   snake_case							:List[int]      ,   snake_case							:Optional[List[int]] = None	):





        '''simple docstring'''




        A_       :					Dict        =      [self.sep_token_id]
        A_       :					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	) * [0] + len(token_ids_a + sep	) * [1]





     def     SCREAMING_SNAKE_CASE		(				self							:Optional[int]      ,   snake_case							:str      ,   snake_case							:Optional[str] = None	):





        '''simple docstring'''




        A_       :					Optional[int]        =      self._tokenizer.model.save(snake_case      ,   name=snake_case	)
        return tuple(snake_case	)







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_bart import BartTokenizer


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


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

# See all BART models at https://huggingface.co/models?filter=bart
_lowerCAmelCase				:   int						       =						{
    '''vocab_file''': {
        '''facebook/bart-base''': '''https://huggingface.co/facebook/bart-base/resolve/main/vocab.json''',
        '''facebook/bart-large''': '''https://huggingface.co/facebook/bart-large/resolve/main/vocab.json''',
        '''facebook/bart-large-mnli''': '''https://huggingface.co/facebook/bart-large-mnli/resolve/main/vocab.json''',
        '''facebook/bart-large-cnn''': '''https://huggingface.co/facebook/bart-large-cnn/resolve/main/vocab.json''',
        '''facebook/bart-large-xsum''': '''https://huggingface.co/facebook/bart-large-xsum/resolve/main/vocab.json''',
        '''yjernite/bart_eli5''': '''https://huggingface.co/yjernite/bart_eli5/resolve/main/vocab.json''',
    },
    '''merges_file''': {
        '''facebook/bart-base''': '''https://huggingface.co/facebook/bart-base/resolve/main/merges.txt''',
        '''facebook/bart-large''': '''https://huggingface.co/facebook/bart-large/resolve/main/merges.txt''',
        '''facebook/bart-large-mnli''': '''https://huggingface.co/facebook/bart-large-mnli/resolve/main/merges.txt''',
        '''facebook/bart-large-cnn''': '''https://huggingface.co/facebook/bart-large-cnn/resolve/main/merges.txt''',
        '''facebook/bart-large-xsum''': '''https://huggingface.co/facebook/bart-large-xsum/resolve/main/merges.txt''',
        '''yjernite/bart_eli5''': '''https://huggingface.co/yjernite/bart_eli5/resolve/main/merges.txt''',
    },
    '''tokenizer_file''': {
        '''facebook/bart-base''': '''https://huggingface.co/facebook/bart-base/resolve/main/tokenizer.json''',
        '''facebook/bart-large''': '''https://huggingface.co/facebook/bart-large/resolve/main/tokenizer.json''',
        '''facebook/bart-large-mnli''': '''https://huggingface.co/facebook/bart-large-mnli/resolve/main/tokenizer.json''',
        '''facebook/bart-large-cnn''': '''https://huggingface.co/facebook/bart-large-cnn/resolve/main/tokenizer.json''',
        '''facebook/bart-large-xsum''': '''https://huggingface.co/facebook/bart-large-xsum/resolve/main/tokenizer.json''',
        '''yjernite/bart_eli5''': '''https://huggingface.co/yjernite/bart_eli5/resolve/main/tokenizer.json''',
    },
}

_lowerCAmelCase				:   Optional[int]						       =						{
    '''facebook/bart-base''': 1_024,
    '''facebook/bart-large''': 1_024,
    '''facebook/bart-large-mnli''': 1_024,
    '''facebook/bart-large-cnn''': 1_024,
    '''facebook/bart-large-xsum''': 1_024,
    '''yjernite/bart_eli5''': 1_024,
}


class        __magic_name__	(				lowerCamelCase__				):





     """simple docstring"""



     __UpperCamelCase            =  VOCAB_FILES_NAMES
     __UpperCamelCase            =  PRETRAINED_VOCAB_FILES_MAP
     __UpperCamelCase            =  PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
     __UpperCamelCase            =  ['''input_ids''', '''attention_mask''']
     __UpperCamelCase            =  BartTokenizer



     def __init__(				self							:List[str]      ,   snake_case							:Tuple=None      ,   snake_case							:Union[str, Any]=None      ,   snake_case							:Union[str, Any]=None      ,   snake_case							:List[Any]="replace"      ,   snake_case							:List[str]="<s>"      ,   snake_case							:Optional[int]="</s>"      ,   snake_case							:Union[str, Any]="</s>"      ,   snake_case							:Optional[Any]="<s>"      ,   snake_case							:List[Any]="<unk>"      ,   snake_case							:Optional[Any]="<pad>"      ,   snake_case							:Dict="<mask>"      ,   snake_case							:int=False      ,   snake_case							:List[Any]=True      ,   **snake_case							:Union[str, Any]      ,   ):





        '''simple docstring'''




        super().__init__(
            snake_case      ,   snake_case      ,   tokenizer_file=snake_case      ,   errors=snake_case      ,   bos_token=snake_case      ,   eos_token=snake_case      ,   sep_token=snake_case      ,   cls_token=snake_case      ,   unk_token=snake_case      ,   pad_token=snake_case      ,   mask_token=snake_case      ,   add_prefix_space=snake_case      ,   trim_offsets=snake_case      ,   **snake_case      ,   )

        A_       :					Optional[Any]        =      json.loads(self.backend_tokenizer.pre_tokenizer.__getstate__()	)
        if pre_tok_state.get("add_prefix_space"      ,   snake_case	) != add_prefix_space:
           A_       :					Dict        =      getattr(snake_case      ,   pre_tok_state.pop("type"	)	)
           A_       :					List[str]        =      add_prefix_space
           A_       :					int        =      pre_tok_class(**snake_case	)

        A_       :					Any        =      add_prefix_space

        # the pre_tokenizer is already updated in the GPT2TokenizerFast `__init__`
        A_       :					Tuple        =      "post_processor"
        A_       :					Union[str, Any]        =      getattr(self.backend_tokenizer      ,   snake_case      ,   snake_case	)
        if tokenizer_component_instance:
           A_       :					Any        =      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_       :					List[Any]        =      tuple(state["sep"]	)
           if "cls" in state:
              A_       :					str        =      tuple(state["cls"]	)

           A_       :					int        =      False

           if state.get("add_prefix_space"      ,   snake_case	) != add_prefix_space:
              A_       :					List[Any]        =      add_prefix_space
              A_       :					Union[str, Any]        =      True

           if state.get("trim_offsets"      ,   snake_case	) != trim_offsets:
              A_       :					int        =      trim_offsets
              A_       :					str        =      True

           if changes_to_apply:
              A_       :					Tuple        =      getattr(snake_case      ,   state.pop("type"	)	)
              A_       :					Union[str, Any]        =      component_class(**snake_case	)
              setattr(self.backend_tokenizer      ,   snake_case      ,   snake_case	)



     @property
     def     SCREAMING_SNAKE_CASE		(				self							:List[Any]	):





        '''simple docstring'''




        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     SCREAMING_SNAKE_CASE		(				self							:Tuple      ,   snake_case							:Dict	):





        '''simple docstring'''




        A_       :					Optional[int]        =      AddedToken(snake_case      ,   lstrip=snake_case      ,   rstrip=snake_case	) if isinstance(snake_case      ,   snake_case	) else value
        A_       :					List[Any]        =      value



     def     SCREAMING_SNAKE_CASE		(				self							:Tuple      ,   *snake_case							:str      ,   **snake_case							:str	):





        '''simple docstring'''




        A_       :					Tuple        =      kwargs.get("is_split_into_words"      ,   snake_case	)

        if is_split_into_words and not self.add_prefix_space:
           raise ValueError(
               f"You need to instantiate {self.__class__.__name__} with add_prefix_space=True "
               "to use it with pretokenized inputs."	)

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



     def     SCREAMING_SNAKE_CASE		(				self							:Union[str, Any]      ,   *snake_case							:Any      ,   **snake_case							:Optional[Any]	):





        '''simple docstring'''




        A_       :					List[Any]        =      kwargs.get("is_split_into_words"      ,   snake_case	)

        if is_split_into_words and not self.add_prefix_space:
           raise ValueError(
               f"You need to instantiate {self.__class__.__name__} with add_prefix_space=True "
               "to use it with pretokenized inputs."	)

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



     def     SCREAMING_SNAKE_CASE		(				self							:int      ,   snake_case							:str      ,   snake_case							:Optional[str] = None	):





        '''simple docstring'''




        A_       :					Any        =      self._tokenizer.model.save(snake_case      ,   name=snake_case	)
        return tuple(snake_case	)



     def     SCREAMING_SNAKE_CASE		(				self							:Dict      ,   snake_case							:List[str]      ,   snake_case							:Optional[int]=None	):





        '''simple docstring'''




        A_       :					str        =      [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     SCREAMING_SNAKE_CASE		(				self							:int      ,   snake_case							:List[int]      ,   snake_case							:Optional[List[int]] = None	):





        '''simple docstring'''




        A_       :					Dict        =      [self.sep_token_id]
        A_       :					List[str]        =      [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]
