





'''simple docstring'''







from __future__ import annotations

import unittest

from transformers import is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
					import numpy
					import tensorflow as tf

					from transformers import (
					    TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
					    TF_DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
					    TF_DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST,
					    BertConfig,
					    DPRConfig,
					    TFDPRContextEncoder,
					    TFDPRQuestionEncoder,
					    TFDPRReader,
					)


class 					__a      :

							def __init__(							self							:     Optional[Any]       ,     __magic_name__							:     Dict       ,     __magic_name__							:     Any=13       ,     __magic_name__							:     Any=7       ,     __magic_name__							:     Any=True       ,     __magic_name__							:     Any=True       ,     __magic_name__							:     List[str]=True       ,     __magic_name__							:     Union[str, Any]=True       ,     __magic_name__							:     Optional[int]=99       ,     __magic_name__							:     Any=32       ,     __magic_name__							:     Tuple=2       ,     __magic_name__							:     List[str]=4       ,     __magic_name__							:     Dict=37       ,     __magic_name__							:     Tuple="gelu"       ,     __magic_name__							:     int=0.1       ,     __magic_name__							:     Tuple=0.1       ,     __magic_name__							:     str=5_12       ,     __magic_name__							:     Any=16       ,     __magic_name__							:     Dict=2       ,     __magic_name__							:     str=0.0_2       ,     __magic_name__							:     Any=3       ,     __magic_name__							:     List[Any]=4       ,     __magic_name__							:     Optional[Any]=None       ,     __magic_name__							:     Dict=0       ,     )					->       Dict:







													"""simple docstring"""
													UpperCAmelCase_			:      Tuple     						=  parent
													UpperCAmelCase_			:      Optional[int]     						=  batch_size
													UpperCAmelCase_			:      Optional[Any]     						=  seq_length
													UpperCAmelCase_			:      List[str]     						=  is_training
													UpperCAmelCase_			:      Optional[int]     						=  use_input_mask
													UpperCAmelCase_			:      Optional[Any]     						=  use_token_type_ids
													UpperCAmelCase_			:      Dict     						=  use_labels
													UpperCAmelCase_			:      Tuple     						=  vocab_size
													UpperCAmelCase_			:      int     						=  hidden_size
													UpperCAmelCase_			:      Dict     						=  num_hidden_layers
													UpperCAmelCase_			:      int     						=  num_attention_heads
													UpperCAmelCase_			:      Optional[int]     						=  intermediate_size
													UpperCAmelCase_			:      Dict     						=  hidden_act
													UpperCAmelCase_			:      Dict     						=  hidden_dropout_prob
													UpperCAmelCase_			:      Tuple     						=  attention_probs_dropout_prob
													UpperCAmelCase_			:      List[Any]     						=  max_position_embeddings
													UpperCAmelCase_			:      Union[str, Any]     						=  type_vocab_size
													UpperCAmelCase_			:      Any     						=  type_sequence_label_size
													UpperCAmelCase_			:      List[Any]     						=  initializer_range
													UpperCAmelCase_			:      Optional[int]     						=  num_labels
													UpperCAmelCase_			:      Optional[int]     						=  num_choices
													UpperCAmelCase_			:      Union[str, Any]     						=  scope
													UpperCAmelCase_			:      Optional[Any]     						=  projection_dim

							def     UpperCAmelCase__	(							self							:     Dict   )					->       List[Any]:







													"""simple docstring"""
													UpperCAmelCase_			:      Dict     						=  ids_tensor([self.batch_size, self.seq_length]       ,     self.vocab_size   )

													UpperCAmelCase_			:      int     						=  None
													if self.use_input_mask:
																			# follow test_modeling_tf_ctrl.py
																			UpperCAmelCase_			:      int     						=  random_attention_mask([self.batch_size, self.seq_length]   )

													UpperCAmelCase_			:      Any     						=  None
													if self.use_token_type_ids:
																			UpperCAmelCase_			:      List[str]     						=  ids_tensor([self.batch_size, self.seq_length]       ,     self.type_vocab_size   )

													UpperCAmelCase_			:      Any     						=  None
													UpperCAmelCase_			:      Optional[int]     						=  None
													UpperCAmelCase_			:      Tuple     						=  None
													if self.use_labels:
																			UpperCAmelCase_			:      Optional[int]     						=  ids_tensor([self.batch_size]       ,     self.type_sequence_label_size   )
																			UpperCAmelCase_			:      List[Any]     						=  ids_tensor([self.batch_size, self.seq_length]       ,     self.num_labels   )
																			UpperCAmelCase_			:      Optional[Any]     						=  ids_tensor([self.batch_size]       ,     self.num_choices   )

													UpperCAmelCase_			:      int     						=  BertConfig(
													    vocab_size=self.vocab_size       ,     hidden_size=self.hidden_size       ,     num_hidden_layers=self.num_hidden_layers       ,     num_attention_heads=self.num_attention_heads       ,     intermediate_size=self.intermediate_size       ,     hidden_act=self.hidden_act       ,     hidden_dropout_prob=self.hidden_dropout_prob       ,     attention_probs_dropout_prob=self.attention_probs_dropout_prob       ,     max_position_embeddings=self.max_position_embeddings       ,     type_vocab_size=self.type_vocab_size       ,     is_decoder=__magic_name__       ,     initializer_range=self.initializer_range       ,     )
													UpperCAmelCase_			:      Union[str, Any]     						=  DPRConfig(projection_dim=self.projection_dim       ,     **config.to_dict()   )

													return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels

							def     UpperCAmelCase__	(							self							:     List[str]       ,     __magic_name__							:     Tuple       ,     __magic_name__							:     Any       ,     __magic_name__							:     str       ,     __magic_name__							:     Dict       ,     __magic_name__							:     Any       ,     __magic_name__							:     Any       ,     __magic_name__							:     Union[str, Any]   )					->       str:







													"""simple docstring"""
													UpperCAmelCase_			:      Any     						=  TFDPRContextEncoder(config=__magic_name__   )
													UpperCAmelCase_			:      Tuple     						=  model(__magic_name__       ,     attention_mask=__magic_name__       ,     token_type_ids=__magic_name__   )
													UpperCAmelCase_			:      Optional[Any]     						=  model(__magic_name__       ,     token_type_ids=__magic_name__   )
													UpperCAmelCase_			:      Optional[Any]     						=  model(__magic_name__   )
													self.parent.assertEqual(result.pooler_output.shape       ,     (self.batch_size, self.projection_dim or self.hidden_size)   )

							def     UpperCAmelCase__	(							self							:     Optional[int]       ,     __magic_name__							:     Optional[Any]       ,     __magic_name__							:     Union[str, Any]       ,     __magic_name__							:     Optional[Any]       ,     __magic_name__							:     str       ,     __magic_name__							:     int       ,     __magic_name__							:     Tuple       ,     __magic_name__							:     int   )					->       Dict:







													"""simple docstring"""
													UpperCAmelCase_			:      Any     						=  TFDPRQuestionEncoder(config=__magic_name__   )
													UpperCAmelCase_			:      int     						=  model(__magic_name__       ,     attention_mask=__magic_name__       ,     token_type_ids=__magic_name__   )
													UpperCAmelCase_			:      Optional[int]     						=  model(__magic_name__       ,     token_type_ids=__magic_name__   )
													UpperCAmelCase_			:      int     						=  model(__magic_name__   )
													self.parent.assertEqual(result.pooler_output.shape       ,     (self.batch_size, self.projection_dim or self.hidden_size)   )

							def     UpperCAmelCase__	(							self							:     int       ,     __magic_name__							:     Union[str, Any]       ,     __magic_name__							:     Any       ,     __magic_name__							:     Any       ,     __magic_name__							:     str       ,     __magic_name__							:     Union[str, Any]       ,     __magic_name__							:     Dict       ,     __magic_name__							:     Tuple   )					->       Tuple:







													"""simple docstring"""
													UpperCAmelCase_			:      Dict     						=  TFDPRReader(config=__magic_name__   )
													UpperCAmelCase_			:      int     						=  model(__magic_name__       ,     attention_mask=__magic_name__   )

													self.parent.assertEqual(result.start_logits.shape       ,     (self.batch_size, self.seq_length)   )
													self.parent.assertEqual(result.end_logits.shape       ,     (self.batch_size, self.seq_length)   )
													self.parent.assertEqual(result.relevance_logits.shape       ,     (self.batch_size,)   )



							def     UpperCAmelCase__	(							self							:     Tuple   )					->       Optional[Any]:







													"""simple docstring"""
													UpperCAmelCase_			:      Dict     						=  self.prepare_config_and_inputs()
													(
													    (
													    UpperCAmelCase_
													)						,       (
													    UpperCAmelCase_
													)						,       (
													    UpperCAmelCase_
													)						,       (
													    UpperCAmelCase_
													)						,       (
													    UpperCAmelCase_
													)						,       (
													    UpperCAmelCase_
													)						,       (
													    UpperCAmelCase_
													)						,       
													)			:      Optional[Any]     						=  config_and_inputs
													UpperCAmelCase_			:      int     						=  {'''input_ids''': input_ids}
													return config, inputs_dict





@require_tf
class 					__a      (lowerCamelCase       ,		lowerCamelCase       ,		unittest.TestCase     ):
							__a					:   Union[str, Any]									=       (
							    (
							        TFDPRContextEncoder,
							        TFDPRQuestionEncoder,
							        TFDPRReader,
							    )
							    if is_tf_available()
							    else ()
							)
							__a					:   Dict									=       {"feature-extraction": TFDPRQuestionEncoder} if is_tf_available() else {}

							__a					:   str									=       False
							__a					:   Optional[int]									=       False
							__a					:   List[str]									=       False
							__a					:   Optional[Any]									=       False
							__a					:   List[str]									=       False

							def     UpperCAmelCase__	(							self							:     Dict   )					->       Optional[Any]:







													"""simple docstring"""
													UpperCAmelCase_			:      Any     						=  TFDPRModelTester(self   )
													UpperCAmelCase_			:      Tuple     						=  ConfigTester(self       ,     config_class=__magic_name__       ,     hidden_size=37   )

							def     UpperCAmelCase__	(							self							:     Optional[int]   )					->       int:







													"""simple docstring"""
													self.config_tester.run_common_tests()

							def     UpperCAmelCase__	(							self							:     Optional[int]   )					->       Union[str, Any]:







													"""simple docstring"""
													UpperCAmelCase_			:      Any     						=  self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_dpr_context_encoder(*__magic_name__   )

							def     UpperCAmelCase__	(							self							:     Optional[Any]   )					->       Any:







													"""simple docstring"""
													UpperCAmelCase_			:      Optional[int]     						=  self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_dpr_question_encoder(*__magic_name__   )

							def     UpperCAmelCase__	(							self							:     Dict   )					->       Optional[int]:







													"""simple docstring"""
													UpperCAmelCase_			:      str     						=  self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_dpr_reader(*__magic_name__   )



							@slow
							def     UpperCAmelCase__	(							self							:     Union[str, Any]   )					->       int:







													"""simple docstring"""
													for model_name in TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																			UpperCAmelCase_			:      List[str]     						=  TFDPRContextEncoder.from_pretrained(__magic_name__   )
																			self.assertIsNotNone(__magic_name__   )

													for model_name in TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																			UpperCAmelCase_			:      Optional[int]     						=  TFDPRContextEncoder.from_pretrained(__magic_name__   )
																			self.assertIsNotNone(__magic_name__   )

													for model_name in TF_DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																			UpperCAmelCase_			:      Dict     						=  TFDPRQuestionEncoder.from_pretrained(__magic_name__   )
																			self.assertIsNotNone(__magic_name__   )

													for model_name in TF_DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																			UpperCAmelCase_			:      Union[str, Any]     						=  TFDPRReader.from_pretrained(__magic_name__   )
																			self.assertIsNotNone(__magic_name__   )





@require_tf
class 					__a      (unittest.TestCase     ):

							@slow
							def     UpperCAmelCase__	(							self							:     Any   )					->       Union[str, Any]:







													"""simple docstring"""
													UpperCAmelCase_			:      Tuple     						=  TFDPRQuestionEncoder.from_pretrained('''facebook/dpr-question_encoder-single-nq-base'''   )

													UpperCAmelCase_			:      Tuple     						=  tf.constant(
													    [[1_01, 75_92, 10_10, 20_03, 20_26, 38_99, 1_01_40, 10_29, 1_02]]   )  # [CLS] hello, is my dog cute? [SEP]
													UpperCAmelCase_			:      Tuple     						=  model(__magic_name__   )[0]  # embedding shape = (1, 768)
													# compare the actual values for a slice.
													UpperCAmelCase_			:      Optional[Any]     						=  tf.constant(
													    [
													        [
													            0.0_3_2_3_6_2_5_3,
													            0.1_2_7_5_3_3_3_5,
													            0.1_6_8_1_8_5_0_9,
													            0.0_0_2_7_9_7_8_6,
													            0.3_8_9_6_9_3_3,
													            0.2_4_2_6_4_9_4_5,
													            0.2_1_7_8_9_7_1,
													            -0.0_2_3_3_5_2_2_7,
													            -0.0_8_4_8_1_9_5_9,
													            -0.1_4_3_2_4_1_1_7,
													        ]
													    ]   )
													self.assertTrue(numpy.allclose(output[:, :10].numpy()       ,     expected_slice.numpy()       ,     atol=1E-4   )   )












'''simple docstring'''







import io
import os
import unicodedata
from typing import Any, Dict, List, Optional, Tuple

import sentencepiece as spm

from ...tokenization_utils import PreTrainedTokenizer
from ...utils import logging


snake_case_     :       str						=  logging.get_logger(__name__)

snake_case_     :       int						=  "▁"

snake_case_     :       str						=  {"vocab_file": "vocab.txt", "sentencepiece_model_ckpt": "sentencepiece.bpe.model"}

snake_case_     :       int						=  {
    "sentencepiece_model_file": "sentencepiece.bpe.model",
    "vocab_file": "vocab.txt",
}

snake_case_     :       Optional[Any]						=  {
    "vocab_file": {
        "ernie-m-base": "https://huggingface.co/susnato/ernie-m-base_pytorch/blob/main/vocab.txt",
        "ernie-m-large": "https://huggingface.co/susnato/ernie-m-base_pytorch/blob/main/vocab.txt",
    },
    "sentencepiece_model_file": {
        "ernie-m-base": "https://huggingface.co/susnato/ernie-m-base_pytorch/blob/main/sentencepiece.bpe.model",
        "ernie-m-large": "https://huggingface.co/susnato/ernie-m-base_pytorch/blob/main/sentencepiece.bpe.model",
    },
}

snake_case_     :       Dict						=  {
    "ernie-m-base": 5_14,
    "ernie-m-large": 5_14,
}

snake_case_     :       Any						=  {
    "ernie-m-base": {"do_lower_case": False},
    "ernie-m-large": {"do_lower_case": False},
}


class 					__a      (lowerCamelCase     ):
							__a					:   List[str]									=       ["input_ids"]

							__a					:   Union[str, Any]									=       VOCAB_FILES_NAMES
							__a					:   Tuple									=       PRETRAINED_INIT_CONFIGURATION
							__a					:   Dict									=       PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
							__a					:   Optional[int]									=       PRETRAINED_VOCAB_FILES_MAP
							__a					:   Union[str, Any]									=       RESOURCE_FILES_NAMES

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







													"""simple docstring"""
													# Mask token behave like a normal word, i.e. include the space before it and
													# is included in the raw text, there should be a match in a non-normalized sentence.

													UpperCAmelCase_			:      List[Any]     						=  {} if sp_model_kwargs is None else sp_model_kwargs
													super().__init__(
													    do_lower_case=__magic_name__       ,     unk_token=__magic_name__       ,     sep_token=__magic_name__       ,     pad_token=__magic_name__       ,     cls_token=__magic_name__       ,     mask_token=__magic_name__       ,     vocab_file=__magic_name__       ,     encoding=__magic_name__       ,     sp_model_kwargs=self.sp_model_kwargs       ,     **__magic_name__       ,     )
													UpperCAmelCase_			:      Optional[Any]     						=  do_lower_case
													UpperCAmelCase_			:      List[str]     						=  sentencepiece_model_ckpt
													UpperCAmelCase_			:      Tuple     						=  spm.SentencePieceProcessor(**self.sp_model_kwargs   )
													self.sp_model.Load(__magic_name__   )

													# to mimic paddlenlp.transformers.ernie_m.tokenizer.ErnieMTokenizer functioning
													if vocab_file is not None:
																			UpperCAmelCase_			:      List[Any]     						=  self.load_vocab(filepath=__magic_name__   )
													else:
																			UpperCAmelCase_			:      str     						=  {self.sp_model.id_to_piece(__magic_name__   ): id for id in range(self.sp_model.get_piece_size()   )}
													UpperCAmelCase_			:      int     						=  {v: k for k, v in self.vocab.items()}

							def     UpperCAmelCase__	(							self							:     List[str]       ,     __magic_name__							:     Any   )					->       Any:







													"""simple docstring"""
													if text is None:
																			return None

													UpperCAmelCase_			:      str     						=  self.tokenize(__magic_name__   )
													UpperCAmelCase_						,       UpperCAmelCase_			:      str     						=  '''''', []

													for i, ch in enumerate(__magic_name__   ):
																			if ch in self.SP_CHAR_MAPPING:
																									UpperCAmelCase_			:      Optional[int]     						=  self.SP_CHAR_MAPPING.get(__magic_name__   )
																			else:
																									UpperCAmelCase_			:      Union[str, Any]     						=  unicodedata.normalize('''NFKC'''       ,     __magic_name__   )
																			if self.is_whitespace(__magic_name__   ):
																									continue
																			normalized_text += ch
																			char_mapping.extend([i] * len(__magic_name__   )   )

													UpperCAmelCase_						,       UpperCAmelCase_						,       UpperCAmelCase_			:      Union[str, Any]     						=  normalized_text, [], 0

													if self.do_lower_case:
																			UpperCAmelCase_			:      Optional[int]     						=  text.lower()

													for token in split_tokens:
																			if token[:1] == "▁":
																									UpperCAmelCase_			:      Tuple     						=  token[1:]
																			UpperCAmelCase_			:      int     						=  text[offset:].index(__magic_name__   ) + offset
																			UpperCAmelCase_			:      Optional[int]     						=  start + len(__magic_name__   )

																			token_mapping.append((char_mapping[start], char_mapping[end - 1] + 1)   )
																			UpperCAmelCase_			:      int     						=  end
													return token_mapping

							@property
							def     UpperCAmelCase__	(							self							:     Any   )					->       Any:







													"""simple docstring"""
													return len(self.vocab   )

							def     UpperCAmelCase__	(							self							:     List[Any]   )					->       int:







													"""simple docstring"""
													return dict(self.vocab       ,     **self.added_tokens_encoder   )

							def __getstate__(							self							:     str   )					->       Any:







													"""simple docstring"""
													UpperCAmelCase_			:      Optional[Any]     						=  self.__dict__.copy()
													UpperCAmelCase_			:      Optional[Any]     						=  None
													return state

							def __setstate__(							self							:     str       ,     __magic_name__							:     Any   )					->       Dict:







													"""simple docstring"""
													UpperCAmelCase_			:      Dict     						=  d

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

													UpperCAmelCase_			:      List[Any]     						=  spm.SentencePieceProcessor(**self.sp_model_kwargs   )
													self.sp_model.Load(self.sentencepiece_model_ckpt   )

							def     UpperCAmelCase__	(							self							:     Optional[int]       ,     __magic_name__							:     Any   )					->       List[str]:







													"""simple docstring"""
													return "".join((self.SP_CHAR_MAPPING.get(__magic_name__       ,     __magic_name__   ) for c in text)   )

							def     UpperCAmelCase__	(							self							:     List[str]       ,     __magic_name__							:     Tuple       ,     __magic_name__							:     Any=False       ,     __magic_name__							:     List[str]=64       ,     __magic_name__							:     List[str]=0.1   )					->       List[str]:







													"""simple docstring"""

													if self.sp_model_kwargs.get('''enable_sampling'''   ) is True:
																			UpperCAmelCase_			:      Dict     						=  True
													if self.sp_model_kwargs.get('''alpha'''   ) is not None:
																			UpperCAmelCase_			:      Union[str, Any]     						=  self.sp_model_kwargs.get('''alpha'''   )
													if self.sp_model_kwargs.get('''nbest_size'''   ) is not None:
																			UpperCAmelCase_			:      Any     						=  self.sp_model_kwargs.get('''nbest_size'''   )

													if not enable_sampling:
																			UpperCAmelCase_			:      Dict     						=  self.sp_model.EncodeAsPieces(__magic_name__   )
													else:
																			UpperCAmelCase_			:      Dict     						=  self.sp_model.SampleEncodeAsPieces(__magic_name__       ,     __magic_name__       ,     __magic_name__   )
													UpperCAmelCase_			:      List[Any]     						=  []
													for pi, piece in enumerate(__magic_name__   ):
																			if piece == SPIECE_UNDERLINE:
																									if not pieces[pi + 1].startswith(__magic_name__   ) and pi != 0:
																															new_pieces.append(__magic_name__   )
																															continue
																									else:
																															continue
																			UpperCAmelCase_			:      List[str]     						=  0
																			for i, chunk in enumerate(__magic_name__   ):
																									if chunk == SPIECE_UNDERLINE:
																															continue
																									if self.is_ch_char(__magic_name__   ) or self.is_punct(__magic_name__   ):
																															if i > lst_i and piece[lst_i:i] != SPIECE_UNDERLINE:
																																					new_pieces.append(piece[lst_i:i]   )
																															new_pieces.append(__magic_name__   )
																															UpperCAmelCase_			:      List[Any]     						=  i + 1
																									elif chunk.isdigit() and i > 0 and not piece[i - 1].isdigit():
																															if i > lst_i and piece[lst_i:i] != SPIECE_UNDERLINE:
																																					new_pieces.append(piece[lst_i:i]   )
																															UpperCAmelCase_			:      List[str]     						=  i
																									elif not chunk.isdigit() and i > 0 and piece[i - 1].isdigit():
																															if i > lst_i and piece[lst_i:i] != SPIECE_UNDERLINE:
																																					new_pieces.append(piece[lst_i:i]   )
																															UpperCAmelCase_			:      str     						=  i
																			if len(__magic_name__   ) > lst_i:
																									new_pieces.append(piece[lst_i:]   )
													return new_pieces

							def     UpperCAmelCase__	(							self							:     List[Any]       ,     __magic_name__							:     Optional[int]   )					->       List[str]:







													"""simple docstring"""
													UpperCAmelCase_			:      Optional[Any]     						=  ''''''.join(__magic_name__   ).replace(__magic_name__       ,     ''' '''   ).strip()
													return out_string

							def     UpperCAmelCase__	(							self							:     List[Any]       ,     __magic_name__							:     Union[str, Any]   )					->       List[str]:







													"""simple docstring"""
													UpperCAmelCase_			:      str     						=  self.convert_ids_to_tokens(__magic_name__   )
													UpperCAmelCase_			:      Optional[Any]     						=  ''''''.join(__magic_name__   ).replace(__magic_name__       ,     ''' '''   ).strip()
													return out_string

							def     UpperCAmelCase__	(							self							:     str       ,     __magic_name__							:     Optional[Any]   )					->       List[Any]:







													"""simple docstring"""
													return self.vocab.get(__magic_name__       ,     self.vocab.get(self.unk_token   )   )

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







													"""simple docstring"""
													return self.reverse_vocab.get(__magic_name__       ,     self.unk_token   )

							def     UpperCAmelCase__	(							self							:     Tuple       ,     __magic_name__							:     Any       ,     __magic_name__							:     Union[str, Any]=None   )					->       Any:







													"""simple docstring"""
													if token_ids_a is None:
																			return [self.cls_token_id] + token_ids_a + [self.sep_token_id]
													UpperCAmelCase_			:      Union[str, Any]     						=  [self.cls_token_id]
													UpperCAmelCase_			:      List[Any]     						=  [self.sep_token_id]
													return _cls + token_ids_a + _sep + _sep + token_ids_a + _sep

							def     UpperCAmelCase__	(							self							:     Any       ,     __magic_name__							:     Optional[Any]       ,     __magic_name__							:     List[str]=None   )					->       int:







													"""simple docstring"""
													if offset_mapping_a is None:
																			return [(0, 0)] + offset_mapping_a + [(0, 0)]

													return [(0, 0)] + offset_mapping_a + [(0, 0), (0, 0)] + offset_mapping_a + [(0, 0)]

							def     UpperCAmelCase__	(							self							:     Dict       ,     __magic_name__							:     Optional[Any]       ,     __magic_name__							:     List[str]=None       ,     __magic_name__							:     Optional[Any]=False   )					->       Optional[int]:







													"""simple docstring"""

													if already_has_special_tokens:
																			if token_ids_a is not None:
																									raise ValueError(
																									    '''You should not supply a second sequence if the provided sequence of '''
																									    '''ids is already formatted with special tokens for the model.'''   )
																			return [1 if x in [self.sep_token_id, self.cls_token_id] else 0 for x in token_ids_a]

													if token_ids_a is not None:
																			return [1] + ([0] * len(__magic_name__   )) + [1, 1] + ([0] * len(__magic_name__   )) + [1]
													return [1] + ([0] * len(__magic_name__   )) + [1]

							def     UpperCAmelCase__	(							self							:     List[str]       ,     __magic_name__							:     List[int]       ,     __magic_name__							:     Optional[List[int]] = None   )					->       List[int]:







													"""simple docstring"""
													# called when `add_special_tokens` is True, so align with `build_inputs_with_special_tokens` method
													if token_ids_a is None:
																			# [CLS] X [SEP]
																			return (len(__magic_name__   ) + 2) * [0]

													# [CLS] A [SEP] [SEP] B [SEP]
													return [0] * (len(__magic_name__   ) + 1) + [1] * (len(__magic_name__   ) + 3)

							def     UpperCAmelCase__	(							self							:     Dict       ,     __magic_name__							:     str   )					->       Tuple:







													"""simple docstring"""
													if "\u4e00" <= char <= "\u9fff":
																			return True
													return False

							def     UpperCAmelCase__	(							self							:     int       ,     __magic_name__							:     Optional[int]   )					->       str:







													"""simple docstring"""
													if ("a" <= char <= "z") or ("A" <= char <= "Z"):
																			return True
													return False

							def     UpperCAmelCase__	(							self							:     int       ,     __magic_name__							:     Optional[Any]   )					->       Dict:







													"""simple docstring"""
													if char in ",;:.?!~，；：。？！《》【】":
																			return True
													return False

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







													"""simple docstring"""
													if char == " " or char == "\t" or char == "\n" or char == "\r":
																			return True
													if len(__magic_name__   ) == 1:
																			UpperCAmelCase_			:      Optional[Any]     						=  unicodedata.category(__magic_name__   )
																			if cat == "Zs":
																									return True
													return False

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







													"""simple docstring"""
													UpperCAmelCase_			:      Optional[Any]     						=  {}
													with io.open(__magic_name__       ,     '''r'''       ,     encoding='''utf-8'''   ) as f:
																			for index, line in enumerate(__magic_name__   ):
																									UpperCAmelCase_			:      List[Any]     						=  line.rstrip('''\n'''   )
																									UpperCAmelCase_			:      Dict     						=  int(__magic_name__   )

													return token_to_idx



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







													"""simple docstring"""
													UpperCAmelCase_			:      Union[str, Any]     						=  0
													if os.path.isdir(__magic_name__   ):
																			UpperCAmelCase_			:      Any     						=  os.path.join(
																			    __magic_name__       ,     (filename_prefix + '''-''' if filename_prefix else '''''') + VOCAB_FILES_NAMES['''vocab_file''']   )
													else:
																			UpperCAmelCase_			:      List[str]     						=  (filename_prefix + '''-''' if filename_prefix else '''''') + save_directory
													with open(__magic_name__       ,     '''w'''       ,     encoding='''utf-8'''   ) as writer:
																			for token, token_index in sorted(self.vocab.items()       ,     key=lambda __magic_name__   : kv[1]   ):
																									if index != token_index:
																															logger.warning(
																															    F"""Saving vocabulary to {vocab_file}: vocabulary indices are not consecutive."""
																															    ''' Please check that the vocabulary is not corrupted!'''   )
																															UpperCAmelCase_			:      Dict     						=  token_index
																									writer.write(token + '''\n'''   )
																									index += 1

													UpperCAmelCase_			:      Union[str, Any]     						=  os.path.join(__magic_name__       ,     '''sentencepiece.bpe.model'''   )
													with open(__magic_name__       ,     '''wb'''   ) as fi:
																			UpperCAmelCase_			:      Optional[int]     						=  self.sp_model.serialized_model_proto()
																			fi.write(__magic_name__   )

													return (vocab_file,)





