






from importlib import import_module

from .logging import get_logger


UpperCAmelCase__				   =		get_logger(__name__)






class 		lowercase_					:






      '''simple docstring'''




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




       """simple docstring"""


       a		  =      attrs or []
       if module is not None:
        for key in module.__dict__:
         if key in attrs or not key.startswith('''__'''  ):
          setattr(self ,					__UpperCAmelCase ,					getattr(__UpperCAmelCase ,					__UpperCAmelCase  )  )
       a		  =      module._original_module if isinstance(__UpperCAmelCase ,					_PatchedModuleObj  ) else module






class 		lowercase_					:






      '''simple docstring'''




      __snake_case       =  []







      def __init__(      self      :						List[str] ,					__UpperCAmelCase      :						List[Any] ,					__UpperCAmelCase      :						str ,					__UpperCAmelCase      :						Optional[Any] ,					__UpperCAmelCase      :						Dict=None  )    ->Union[str, Any]:




       """simple docstring"""


       a		  =      obj
       a		  =      target
       a		  =      new
       a		  =      target.split('''.'''  )[0]
       a		  =      {}
       a		  =      attrs or []







      def __enter__(      self      :						Tuple  )    ->Union[str, Any]:




       """simple docstring"""


       *a  ,     a		  =      self.target.split('''.'''  )

       # Patch modules:
       # it's used to patch attributes of submodules like "os.path.join";
       # in this case we need to patch "os" and "os.path"

       for i in range(len(__UpperCAmelCase  )  ):
        try:
         a		  =      import_module('''.'''.join(submodules[: i + 1]  )  )
        except ModuleNotFoundError:
         continue
        # We iterate over all the globals in self.obj in case we find "os" or "os.path"
        for attr in self.obj.__dir__():
         a		  =      getattr(self.obj ,					__UpperCAmelCase  )
         # We don't check for the name of the global, but rather if its value *is* "os" or "os.path".
         # This allows to patch renamed modules like "from os import path as ospath".
         if obj_attr is submodule or (
             (isinstance(__UpperCAmelCase ,					_PatchedModuleObj  ) and obj_attr._original_module is submodule)
         ):
          a		  =      obj_attr
          # patch at top level
          setattr(self.obj ,					__UpperCAmelCase ,					_PatchedModuleObj(__UpperCAmelCase ,					attrs=self.attrs  )  )
          a		  =      getattr(self.obj ,					__UpperCAmelCase  )
          # construct lower levels patches
          for key in submodules[i + 1 :]:
           setattr(__UpperCAmelCase ,					__UpperCAmelCase ,					_PatchedModuleObj(getattr(__UpperCAmelCase ,					__UpperCAmelCase ,					__UpperCAmelCase  ) ,					attrs=self.attrs  )  )
           a		  =      getattr(__UpperCAmelCase ,					__UpperCAmelCase  )
          # finally set the target attribute
          setattr(__UpperCAmelCase ,					__UpperCAmelCase ,					self.new  )

        # Patch attribute itself:
        # it's used for builtins like "open",
        # and also to patch "os.path.join" we may also need to patch "join"
        # itself if it was imported as "from os.path import join".

       if submodules:  # if it's an attribute of a submodule like "os.path.join"
        try:
         a		  =      getattr(import_module('''.'''.join(__UpperCAmelCase  )  ) ,					__UpperCAmelCase  )
        except (AttributeError, ModuleNotFoundError):
         return
        # We iterate over all the globals in self.obj in case we find "os.path.join"
        for attr in self.obj.__dir__():
         # We don't check for the name of the global, but rather if its value *is* "os.path.join".
         # This allows to patch renamed attributes like "from os.path import join as pjoin".
         if getattr(self.obj ,					__UpperCAmelCase  ) is attr_value:
          a		  =      getattr(self.obj ,					__UpperCAmelCase  )
          setattr(self.obj ,					__UpperCAmelCase ,					self.new  )
       elif target_attr in globals()["__builtins__"]:  # if it'a s builtin like "open"
        a		  =      globals()['''__builtins__'''][target_attr]
        setattr(self.obj ,					__UpperCAmelCase ,					self.new  )
       else:
        raise RuntimeError(F"""Tried to patch attribute {target_attr} instead of a submodule."""  )







      def __exit__(      self      :						List[str] ,					*__UpperCAmelCase      :						Optional[int]  )    ->Tuple:




       """simple docstring"""


       for attr in list(self.original  ):
        setattr(self.obj ,					__UpperCAmelCase ,					self.original.pop(__UpperCAmelCase  )  )







      def       __lowerCAmelCase					(      self      :						Any  )    ->List[Any]:




       """simple docstring"""


       self.__enter__()
       self._active_patches.append(self  )







      def       __lowerCAmelCase					(      self      :						Any  )    ->Union[str, Any]:




       """simple docstring"""


       try:
        self._active_patches.remove(self  )
       except ValueError:
        # If the patch hasn't been started this will fail
        return None

       return self.__exit__()










import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from .tokenization_electra import ElectraTokenizer


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

UpperCAmelCase__				   =		{
    "vocab_file": {
        "google/electra-small-generator": (
            "https://huggingface.co/google/electra-small-generator/resolve/main/vocab.txt"
        ),
        "google/electra-base-generator": "https://huggingface.co/google/electra-base-generator/resolve/main/vocab.txt",
        "google/electra-large-generator": (
            "https://huggingface.co/google/electra-large-generator/resolve/main/vocab.txt"
        ),
        "google/electra-small-discriminator": (
            "https://huggingface.co/google/electra-small-discriminator/resolve/main/vocab.txt"
        ),
        "google/electra-base-discriminator": (
            "https://huggingface.co/google/electra-base-discriminator/resolve/main/vocab.txt"
        ),
        "google/electra-large-discriminator": (
            "https://huggingface.co/google/electra-large-discriminator/resolve/main/vocab.txt"
        ),
    },
    "tokenizer_file": {
        "google/electra-small-generator": (
            "https://huggingface.co/google/electra-small-generator/resolve/main/tokenizer.json"
        ),
        "google/electra-base-generator": (
            "https://huggingface.co/google/electra-base-generator/resolve/main/tokenizer.json"
        ),
        "google/electra-large-generator": (
            "https://huggingface.co/google/electra-large-generator/resolve/main/tokenizer.json"
        ),
        "google/electra-small-discriminator": (
            "https://huggingface.co/google/electra-small-discriminator/resolve/main/tokenizer.json"
        ),
        "google/electra-base-discriminator": (
            "https://huggingface.co/google/electra-base-discriminator/resolve/main/tokenizer.json"
        ),
        "google/electra-large-discriminator": (
            "https://huggingface.co/google/electra-large-discriminator/resolve/main/tokenizer.json"
        ),
    },
}

UpperCAmelCase__				   =		{
    "google/electra-small-generator": 512,
    "google/electra-base-generator": 512,
    "google/electra-large-generator": 512,
    "google/electra-small-discriminator": 512,
    "google/electra-base-discriminator": 512,
    "google/electra-large-discriminator": 512,
}

UpperCAmelCase__				   =		{
    "google/electra-small-generator": {"do_lower_case": True},
    "google/electra-base-generator": {"do_lower_case": True},
    "google/electra-large-generator": {"do_lower_case": True},
    "google/electra-small-discriminator": {"do_lower_case": True},
    "google/electra-base-discriminator": {"do_lower_case": True},
    "google/electra-large-discriminator": {"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       =  ElectraTokenizer







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




       """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      :						List[Any] ,					__UpperCAmelCase      :						Optional[int] ,					__UpperCAmelCase      :						Tuple=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      :						Optional[Any] ,					__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      :						List[str] ,					__UpperCAmelCase      :						str ,					__UpperCAmelCase      :						Optional[str] = None  )    ->Tuple[str]:




       """simple docstring"""


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


