





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

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_distilbert import DistilBertTokenizer


__UpperCamelCase     :						Optional[int]						       =  logging.get_logger(__name__)

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

__UpperCamelCase     :						Dict						       =  {
    '''vocab_file''': {
        '''distilbert-base-uncased''': '''https://huggingface.co/distilbert-base-uncased/resolve/main/vocab.txt''',
        '''distilbert-base-uncased-distilled-squad''': (
            '''https://huggingface.co/distilbert-base-uncased-distilled-squad/resolve/main/vocab.txt'''
        ),
        '''distilbert-base-cased''': '''https://huggingface.co/distilbert-base-cased/resolve/main/vocab.txt''',
        '''distilbert-base-cased-distilled-squad''': (
            '''https://huggingface.co/distilbert-base-cased-distilled-squad/resolve/main/vocab.txt'''
        ),
        '''distilbert-base-german-cased''': '''https://huggingface.co/distilbert-base-german-cased/resolve/main/vocab.txt''',
        '''distilbert-base-multilingual-cased''': (
            '''https://huggingface.co/distilbert-base-multilingual-cased/resolve/main/vocab.txt'''
        ),
    },
    '''tokenizer_file''': {
        '''distilbert-base-uncased''': '''https://huggingface.co/distilbert-base-uncased/resolve/main/tokenizer.json''',
        '''distilbert-base-uncased-distilled-squad''': (
            '''https://huggingface.co/distilbert-base-uncased-distilled-squad/resolve/main/tokenizer.json'''
        ),
        '''distilbert-base-cased''': '''https://huggingface.co/distilbert-base-cased/resolve/main/tokenizer.json''',
        '''distilbert-base-cased-distilled-squad''': (
            '''https://huggingface.co/distilbert-base-cased-distilled-squad/resolve/main/tokenizer.json'''
        ),
        '''distilbert-base-german-cased''': (
            '''https://huggingface.co/distilbert-base-german-cased/resolve/main/tokenizer.json'''
        ),
        '''distilbert-base-multilingual-cased''': (
            '''https://huggingface.co/distilbert-base-multilingual-cased/resolve/main/tokenizer.json'''
        ),
    },
}

__UpperCamelCase     :						Union[str, Any]						       =  {
    '''distilbert-base-uncased''': 512,
    '''distilbert-base-uncased-distilled-squad''': 512,
    '''distilbert-base-cased''': 512,
    '''distilbert-base-cased-distilled-squad''': 512,
    '''distilbert-base-german-cased''': 512,
    '''distilbert-base-multilingual-cased''': 512,
}


__UpperCamelCase     :						Union[str, Any]						       =  {
    '''distilbert-base-uncased''': {'''do_lower_case''': True},
    '''distilbert-base-uncased-distilled-squad''': {'''do_lower_case''': True},
    '''distilbert-base-cased''': {'''do_lower_case''': False},
    '''distilbert-base-cased-distilled-squad''': {'''do_lower_case''': False},
    '''distilbert-base-german-cased''': {'''do_lower_case''': False},
    '''distilbert-base-multilingual-cased''': {'''do_lower_case''': False},
}







class       a							(   a__  ):
 snake_case__             =       VOCAB_FILES_NAMES
 snake_case__             =       PRETRAINED_VOCAB_FILES_MAP
 snake_case__             =       PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
 snake_case__             =       PRETRAINED_INIT_CONFIGURATION
 snake_case__             =       ['''input_ids''', '''attention_mask''']
 snake_case__             =       DistilBertTokenizer



 def __init__(     self				,       _snake_case=None				,       _snake_case=None				,       _snake_case=True				,       _snake_case="[UNK]"				,       _snake_case="[SEP]"				,       _snake_case="[PAD]"				,       _snake_case="[CLS]"				,       _snake_case="[MASK]"				,       _snake_case=True				,       _snake_case=None				,       **_snake_case				,       ):







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

  lowerCAmelCase    				= 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
  ):
   lowerCAmelCase    				= getattr(_snake_case				,       normalizer_state.pop('type'     )     )
   lowerCAmelCase    				= do_lower_case
   lowerCAmelCase    				= strip_accents
   lowerCAmelCase    				= tokenize_chinese_chars
   lowerCAmelCase    				= normalizer_class(**_snake_case     )

  lowerCAmelCase    				= do_lower_case



 def    UpperCamelCase__  (     self				,       _snake_case				,       _snake_case=None     ):







  """simple docstring"""






  lowerCAmelCase    				= [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    UpperCamelCase__  (     self				,       _snake_case				,       _snake_case = None     ):







  """simple docstring"""






  lowerCAmelCase    				= [self.sep_token_id]
  lowerCAmelCase    				= [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    UpperCamelCase__  (     self				,       _snake_case				,       _snake_case = None     ):







  """simple docstring"""






  lowerCAmelCase    				= self._tokenizer.model.save(_snake_case				,       name=_snake_case     )
  return tuple(_snake_case     )













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


UpperCAmelCase__							  =						logging.get_logger(__name__)

UpperCAmelCase__							  =						{"vocab_file": "vocab.txt", "tokenizer_file": "tokenizer.json"}

UpperCAmelCase__							  =						{
    "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"
        ),
    },
}

UpperCAmelCase__							  =						{
    "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,
}

UpperCAmelCase__							  =						{
    "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 						lowercase_   (      lowercase  ):






      '''simple docstring'''




      __snake_case	    =    VOCAB_FILES_NAMES
      __snake_case	    =    PRETRAINED_VOCAB_FILES_MAP
      __snake_case	    =    PRETRAINED_INIT_CONFIGURATION
      __snake_case	    =    PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
      __snake_case	    =    RealmTokenizer







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




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

       a						    = 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
       ):
        a						    = getattr(__UpperCAmelCase					,   normalizer_state.pop('''type'''    )    )
        a						    = do_lower_case
        a						    = strip_accents
        a						    = tokenize_chinese_chars
        a						    = normalizer_class(**__UpperCAmelCase    )

       a						    = do_lower_case







      def  __lowerCAmelCase   ( self :		str					,   __UpperCAmelCase :		List[Any]					,   **__UpperCAmelCase :		List[str]    )       ->List[Any]:




       """simple docstring"""


       a						    = PaddingStrategy.MAX_LENGTH

       a						    = text
       a						    = kwargs.pop('''text_pair'''					,   __UpperCAmelCase    )
       a						    = kwargs.pop('''return_tensors'''					,   __UpperCAmelCase    )

       a						    = {
           '''input_ids''': [],
           '''attention_mask''': [],
           '''token_type_ids''': [],
       }

       for idx, candidate_text in enumerate(__UpperCAmelCase    ):
        if batch_text_pair is not None:
         a						    = batch_text_pair[idx]
        else:
         a						    = None

        a						    = super().__call__(__UpperCAmelCase					,   __UpperCAmelCase					,   return_tensors=__UpperCAmelCase					,   **__UpperCAmelCase    )

        a						    = encoded_candidates.get('''input_ids'''    )
        a						    = encoded_candidates.get('''attention_mask'''    )
        a						    = encoded_candidates.get('''token_type_ids'''    )

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

       a						    = {key: item for key, item in output_data.items() if len(__UpperCAmelCase    ) != 0}

       return BatchEncoding(__UpperCAmelCase					,   tensor_type=__UpperCAmelCase    )







      def  __lowerCAmelCase   ( self :		Tuple					,   __UpperCAmelCase :		Optional[int]					,   __UpperCAmelCase :		Dict=None    )       ->str:




       """simple docstring"""


       a						    = [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  __lowerCAmelCase   ( self :		str					,   __UpperCAmelCase :		List[int]					,   __UpperCAmelCase :		Optional[List[int]] = None    )       ->List[int]:




       """simple docstring"""


       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    ) * [0] + len(token_ids_a + sep    ) * [1]







      def  __lowerCAmelCase   ( self :		Dict					,   __UpperCAmelCase :		str					,   __UpperCAmelCase :		Optional[str] = None    )       ->Tuple[str]:




       """simple docstring"""


       a						    = self._tokenizer.model.save(__UpperCAmelCase					,   name=__UpperCAmelCase    )
       return tuple(__UpperCAmelCase    )


