
"""simple docstring"""






# Lint as: python3
import sys
from collections.abc import Mapping
from typing import TYPE_CHECKING

import numpy as np
import pyarrow as pa

from .. import config
from ..utils.py_utils import map_nested
from .formatting import TensorFormatter


if TYPE_CHECKING:
 import torch





class 				a__					(						TensorFormatter[Mapping, '''torch.Tensor''', Mapping]       ):



     def __init__(							self :str      ,  _lowerCamelCase :Optional[Any]=None      ,  **_lowerCamelCase :Tuple   ):







      '''simple docstring'''



      super().__init__(features=_lowerCamelCase   )
      UpperCamelCase_     :					Optional[Any]   	=torch_tensor_kwargs
      import torch  # noqa import torch at initialization



     def  lowerCamelCase_						(							self :Optional[int]      ,  _lowerCamelCase :Optional[Any]   ):







      '''simple docstring'''



      import torch

      if isinstance(_lowerCamelCase      ,  _lowerCamelCase   ) and column:
       if all(
           isinstance(_lowerCamelCase      ,  torch.Tensor   ) and x.shape == column[0].shape and x.dtype == column[0].dtype
           for x in column   ):
        return torch.stack(_lowerCamelCase   )
      return column



     def  lowerCamelCase_						(							self :Any      ,  _lowerCamelCase :List[Any]   ):







      '''simple docstring'''



      import torch

      if isinstance(_lowerCamelCase      ,  (str, bytes, type(_lowerCamelCase   ))   ):
       return value
      elif isinstance(_lowerCamelCase      ,  (np.character, np.ndarray)   ) and np.issubdtype(value.dtype      ,  np.character   ):
       return value.tolist()

      UpperCamelCase_     :					str   	={}

      if isinstance(_lowerCamelCase      ,  (np.number, np.ndarray)   ) and np.issubdtype(value.dtype      ,  np.integer   ):
       UpperCamelCase_     :					Any   	={'dtype': torch.intaa}
      elif isinstance(_lowerCamelCase      ,  (np.number, np.ndarray)   ) and np.issubdtype(value.dtype      ,  np.floating   ):
       UpperCamelCase_     :					int   	={'dtype': torch.floataa}
      elif config.PIL_AVAILABLE and "PIL" in sys.modules:
       import PIL.Image

       if isinstance(_lowerCamelCase      ,  PIL.Image.Image   ):
        UpperCamelCase_     :					str   	=np.asarray(_lowerCamelCase   )
      return torch.tensor(_lowerCamelCase      ,  **{**default_dtype, **self.torch_tensor_kwargs}   )



     def  lowerCamelCase_						(							self :Dict      ,  _lowerCamelCase :Union[str, Any]   ):







      '''simple docstring'''



      import torch

      # support for torch, tf, jax etc.
      if hasattr(_lowerCamelCase      ,  '__array__'   ) and not isinstance(_lowerCamelCase      ,  torch.Tensor   ):
       UpperCamelCase_     :					Optional[int]   	=data_struct.__array__()
      # support for nested types like struct of list of struct
      if isinstance(_lowerCamelCase      ,  np.ndarray   ):
       if data_struct.dtype == object:  # torch tensors cannot be instantied from an array of objects
        return self._consolidate([self.recursive_tensorize(_lowerCamelCase   ) for substruct in data_struct]   )
      elif isinstance(_lowerCamelCase      ,  (list, tuple)   ):
       return self._consolidate([self.recursive_tensorize(_lowerCamelCase   ) for substruct in data_struct]   )
      return self._tensorize(_lowerCamelCase   )



     def  lowerCamelCase_						(							self :Any      ,  _lowerCamelCase :dict   ):







      '''simple docstring'''



      return map_nested(self._recursive_tensorize      ,  _lowerCamelCase      ,  map_list=_lowerCamelCase   )



     def  lowerCamelCase_						(							self :Union[str, Any]      ,  _lowerCamelCase :pa.Table   ):







      '''simple docstring'''



      UpperCamelCase_     :					List[Any]   	=self.numpy_arrow_extractor().extract_row(_lowerCamelCase   )
      UpperCamelCase_     :					Dict   	=self.python_features_decoder.decode_row(_lowerCamelCase   )
      return self.recursive_tensorize(_lowerCamelCase   )



     def  lowerCamelCase_						(							self :List[Any]      ,  _lowerCamelCase :pa.Table   ):







      '''simple docstring'''



      UpperCamelCase_     :					List[str]   	=self.numpy_arrow_extractor().extract_column(_lowerCamelCase   )
      UpperCamelCase_     :					Any   	=self.python_features_decoder.decode_column(_lowerCamelCase      ,  pa_table.column_names[0]   )
      UpperCamelCase_     :					Union[str, Any]   	=self.recursive_tensorize(_lowerCamelCase   )
      UpperCamelCase_     :					Tuple   	=self._consolidate(_lowerCamelCase   )
      return column




     def  lowerCamelCase_						(							self :Optional[Any]      ,  _lowerCamelCase :pa.Table   ):







      '''simple docstring'''



      UpperCamelCase_     :					List[str]   	=self.numpy_arrow_extractor().extract_batch(_lowerCamelCase   )
      UpperCamelCase_     :					Union[str, Any]   	=self.python_features_decoder.decode_batch(_lowerCamelCase   )
      UpperCamelCase_     :					Union[str, Any]   	=self.recursive_tensorize(_lowerCamelCase   )
      for column_name in batch:
       UpperCamelCase_     :					int   	=self._consolidate(batch[column_name]   )
      return batch


"""simple docstring"""






import json
from typing import List, Optional, Tuple

from tokenizers import normalizers
from tokenizers.pre_tokenizers import BertPreTokenizer, PreTokenizer

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_roformer import RoFormerTokenizer
from .tokenization_utils import JiebaPreTokenizer


__SCREAMING_SNAKE_CASE							=     logging.get_logger(__name__)

__SCREAMING_SNAKE_CASE							=     {'vocab_file': 'vocab.txt', 'tokenizer_file': 'tokenizer.json'}

__SCREAMING_SNAKE_CASE							=     {
    'vocab_file': {
        'junnyu/roformer_chinese_small': 'https://huggingface.co/junnyu/roformer_chinese_small/resolve/main/vocab.txt',
        'junnyu/roformer_chinese_base': 'https://huggingface.co/junnyu/roformer_chinese_base/resolve/main/vocab.txt',
        'junnyu/roformer_chinese_char_small': (
            'https://huggingface.co/junnyu/roformer_chinese_char_small/resolve/main/vocab.txt'
        ),
        'junnyu/roformer_chinese_char_base': (
            'https://huggingface.co/junnyu/roformer_chinese_char_base/resolve/main/vocab.txt'
        ),
        'junnyu/roformer_small_discriminator': (
            'https://huggingface.co/junnyu/roformer_small_discriminator/resolve/main/vocab.txt'
        ),
        'junnyu/roformer_small_generator': (
            'https://huggingface.co/junnyu/roformer_small_generator/resolve/main/vocab.txt'
        ),
    }
}

__SCREAMING_SNAKE_CASE							=     {
    'junnyu/roformer_chinese_small': 1_536,
    'junnyu/roformer_chinese_base': 1_536,
    'junnyu/roformer_chinese_char_small': 512,
    'junnyu/roformer_chinese_char_base': 512,
    'junnyu/roformer_small_discriminator': 128,
    'junnyu/roformer_small_generator': 128,
}


__SCREAMING_SNAKE_CASE							=     {
    'junnyu/roformer_chinese_small': {'do_lower_case': True},
    'junnyu/roformer_chinese_base': {'do_lower_case': True},
    'junnyu/roformer_chinese_char_small': {'do_lower_case': True},
    'junnyu/roformer_chinese_char_base': {'do_lower_case': True},
    'junnyu/roformer_small_discriminator': {'do_lower_case': True},
    'junnyu/roformer_small_generator': {'do_lower_case': True},
}





class 				a__					(						A__       ):
     UpperCAmelCase__         =      VOCAB_FILES_NAMES
     UpperCAmelCase__         =      PRETRAINED_VOCAB_FILES_MAP
     UpperCAmelCase__         =      PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
     UpperCAmelCase__         =      PRETRAINED_INIT_CONFIGURATION
     UpperCAmelCase__         =      RoFormerTokenizer



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







      '''simple docstring'''



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

      UpperCamelCase_     :					Any   	=json.loads(self.backend_tokenizer.normalizer.__getstate__()   )
      if (
          pre_tok_state.get('lowercase'      ,  _lowerCamelCase   ) != do_lower_case
          or pre_tok_state.get('strip_accents'      ,  _lowerCamelCase   ) != strip_accents
      ):
       UpperCamelCase_     :					Optional[Any]   	=getattr(_lowerCamelCase      ,  pre_tok_state.pop('type'   )   )
       UpperCamelCase_     :					Tuple   	=do_lower_case
       UpperCamelCase_     :					Union[str, Any]   	=strip_accents
       UpperCamelCase_     :					Union[str, Any]   	=pre_tok_class(**_lowerCamelCase   )

      UpperCamelCase_     :					List[str]   	=do_lower_case



     def __getstate__(							self :Any   ):







      '''simple docstring'''



      UpperCamelCase_     :					str   	=self.__dict__.copy()
      UpperCamelCase_     :					Union[str, Any]   	=BertPreTokenizer()
      return state



     def __setstate__(							self :str      ,  _lowerCamelCase :Optional[Any]   ):







      '''simple docstring'''



      UpperCamelCase_     :					int   	=d
      UpperCamelCase_     :					Optional[int]   	=self.__dict__['_tokenizer'].get_vocab()
      UpperCamelCase_     :					Any   	=PreTokenizer.custom(JiebaPreTokenizer(_lowerCamelCase   )   )



     def  lowerCamelCase_						(							self :Dict      ,  _lowerCamelCase :Optional[Any]      ,  _lowerCamelCase :Any=None   ):







      '''simple docstring'''



      UpperCamelCase_     :					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  lowerCamelCase_						(							self :Union[str, Any]      ,  _lowerCamelCase :List[int]      ,  _lowerCamelCase :Optional[List[int]] = None   ):







      '''simple docstring'''



      UpperCamelCase_     :					List[Any]   	=[self.sep_token_id]
      UpperCamelCase_     :					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  lowerCamelCase_						(							self :Optional[int]      ,  _lowerCamelCase :str      ,  _lowerCamelCase :Optional[str] = None   ):







      '''simple docstring'''



      UpperCamelCase_     :					List[Any]   	=self._tokenizer.model.save(_lowerCamelCase      ,  name=_lowerCamelCase   )
      return tuple(_lowerCamelCase   )




     def  lowerCamelCase_						(							self :str      ,  _lowerCamelCase :List[str]      ,  _lowerCamelCase :List[Any]=None      ,  _lowerCamelCase :Optional[Any]=None      ,  _lowerCamelCase :int=False      ,  **_lowerCamelCase :Optional[int]      ,  ):







      '''simple docstring'''



      UpperCamelCase_     :					str   	=BertPreTokenizer()
      return super().save_pretrained(_lowerCamelCase      ,  _lowerCamelCase      ,  _lowerCamelCase      ,  _lowerCamelCase      ,  **_lowerCamelCase   )
