






"""simple docstring"""







from google.protobuf import descriptor as _descriptor
from google.protobuf import descriptor_pool as _descriptor_pool
from google.protobuf import symbol_database as _symbol_database
from google.protobuf.internal import builder as _builder


# @@protoc_insertion_point(imports)

a			:    Optional[Any]				 =		_symbol_database.Default()


a			:    Optional[Any]				 =		_descriptor_pool.Default().AddSerializedFile(
    B"""\n\x19sentencepiece_model.proto\x12\rsentencepiece\"\x80\x0c\n\x0bTrainerSpec\x12\r\n\x05input\x18\x01 \x03(\t\x12\x14\n\x0cinput_format\x18\x07 \x01(\t\x12\x14\n\x0cmodel_prefix\x18\x02 \x01(\t\x12\x41\n\nmodel_type\x18\x03 \x01(\x0e\x32$.sentencepiece.TrainerSpec.ModelType:\x07UNIGRAM\x12\x18\n\nvocab_size\x18\x04 \x01(\x05:\x04\x38\x30\x30\x30\x12\x17\n\x0f\x61\x63\x63\x65pt_language\x18\x05 \x03(\t\x12 \n\x15self_test_sample_size\x18\x06 \x01(\x05:\x01\x30\x12*\n\x1b\x65nable_differential_privacy\x18\x32 \x01(\x08:\x05\x66\x61lse\x12+\n differential_privacy_noise_level\x18\x33 \x01(\x02:\x01\x30\x12\x32\n\'differential_privacy_clipping_threshold\x18\x34 \x01(\x04:\x01\x30\x12\"\n\x12\x63haracter_coverage\x18\n \x01(\x02:\x06\x30.9995\x12\x1e\n\x13input_sentence_size\x18\x0b \x01(\x04:\x01\x30\x12$\n\x16shuffle_input_sentence\x18\x13 \x01(\x08:\x04true\x12 \n\x14mining_sentence_size\x18\x0c \x01(\x05\x42\x02\x18\x01\x12\"\n\x16training_sentence_size\x18\r \x01(\x05\x42\x02\x18\x01\x12(\n\x17seed_sentencepiece_size\x18\x0e \x01(\x05:\x07\x31\x30\x30\x30\x30\x30\x30\x12\x1e\n\x10shrinking_factor\x18\x0f \x01(\x02:\x04\x30.75\x12!\n\x13max_sentence_length\x18\x12 \x01(\x05:\x04\x34\x31\x39\x32\x12\x17\n\x0bnum_threads\x18\x10 \x01(\x05:\x02\x31\x36\x12\x1d\n\x12num_sub_iterations\x18\x11 \x01(\x05:\x01\x32\x12$\n\x18max_sentencepiece_length\x18\x14 \x01(\x05:\x02\x31\x36\x12%\n\x17split_by_unicode_script\x18\x15 \x01(\x08:\x04true\x12\x1d\n\x0fsplit_by_number\x18\x17 \x01(\x08:\x04true\x12!\n\x13split_by_whitespace\x18\x16 \x01(\x08:\x04true\x12)\n\x1atreat_whitespace_as_suffix\x18\x18 \x01(\x08:\x05\x66\x61lse\x12+\n\x1c\x61llow_whitespace_only_pieces\x18\x1a \x01(\x08:\x05\x66\x61lse\x12\x1b\n\x0csplit_digits\x18\x19 \x01(\x08:\x05\x66\x61lse\x12#\n\x19pretokenization_delimiter\x18\x35 \x01(\t:\x00\x12\x17\n\x0f\x63ontrol_symbols\x18\x1e \x03(\t\x12\x1c\n\x14user_defined_symbols\x18\x1f \x03(\t\x12\x16\n\x0erequired_chars\x18$ \x01(\t\x12\x1c\n\rbyte_fallback\x18# \x01(\x08:\x05\x66\x61lse\x12+\n\x1dvocabulary_output_piece_score\x18  \x01(\x08:\x04true\x12\x1e\n\x10hard_vocab_limit\x18! \x01(\x08:\x04true\x12\x1c\n\ruse_all_vocab\x18\" \x01(\x08:\x05\x66\x61lse\x12\x11\n\x06unk_id\x18( \x01(\x05:\x01\x30\x12\x11\n\x06\x62os_id\x18) \x01(\x05:\x01\x31\x12\x11\n\x06\x65os_id\x18* \x01(\x05:\x01\x32\x12\x12\n\x06pad_id\x18+ \x01(\x05:\x02-1\x12\x18\n\tunk_piece\x18- \x01(\t:\x05<unk>\x12\x16\n\tbos_piece\x18. \x01(\t:\x03<s>\x12\x17\n\teos_piece\x18/ \x01(\t:\x04</s>\x12\x18\n\tpad_piece\x18\x30 \x01(\t:\x05<pad>\x12\x1a\n\x0bunk_surface\x18, \x01(\t:\x05 \xe2\x81\x87 \x12+\n\x1ctrain_extremely_large_corpus\x18\x31 \x01(\x08:\x05\x66\x61lse\"5\n\tModelType\x12\x0b\n\x07UNIGRAM\x10\x01\x12\x07\n\x03\x42PE\x10\x02\x12\x08\n\x04WORD\x10\x03\x12\x08\n\x04\x43HAR\x10\x04*\t\x08\xc8\x01\x10\x80\x80\x80\x80\x02\"\xd1\x01\n\x0eNormalizerSpec\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x1c\n\x14precompiled_charsmap\x18\x02 \x01(\x0c\x12\x1e\n\x10\x61\x64\x64_dummy_prefix\x18\x03 \x01(\x08:\x04true\x12&\n\x18remove_extra_whitespaces\x18\x04 \x01(\x08:\x04true\x12 \n\x12\x65scape_whitespaces\x18\x05 \x01(\x08:\x04true\x12\x1e\n\x16normalization_rule_tsv\x18\x06 \x01(\t*\t\x08\xc8\x01\x10\x80\x80\x80\x80\x02\"y\n\x0cSelfTestData\x12\x33\n\x07samples\x18\x01 \x03(\x0b\x32\".sentencepiece.SelfTestData.Sample\x1a)\n\x06Sample\x12\r\n\x05input\x18\x01 \x01(\t\x12\x10\n\x08\x65xpected\x18\x02 \x01(\t*\t\x08\xc8\x01\x10\x80\x80\x80\x80\x02\"\xfe\x03\n\nModelProto\x12\x37\n\x06pieces\x18\x01 \x03(\x0b\x32\'.sentencepiece.ModelProto.SentencePiece\x12\x30\n\x0ctrainer_spec\x18\x02 \x01(\x0b\x32\x1a.sentencepiece.TrainerSpec\x12\x36\n\x0fnormalizer_spec\x18\x03 \x01(\x0b\x32\x1d.sentencepiece.NormalizerSpec\x12\x33\n\x0eself_test_data\x18\x04 \x01(\x0b\x32\x1b.sentencepiece.SelfTestData\x12\x38\n\x11\x64\x65normalizer_spec\x18\x05 \x01(\x0b\x32\x1d.sentencepiece.NormalizerSpec\x1a\xd2\x01\n\rSentencePiece\x12\r\n\x05piece\x18\x01 \x01(\t\x12\r\n\x05score\x18\x02 \x01(\x02\x12\x42\n\x04type\x18\x03 \x01(\x0e\x32,.sentencepiece.ModelProto.SentencePiece.Type:\x06NORMAL\"T\n\x04Type\x12\n\n\x06NORMAL\x10\x01\x12\x0b\n\x07UNKNOWN\x10\x02\x12\x0b\n\x07\x43ONTROL\x10\x03\x12\x10\n\x0cUSER_DEFINED\x10\x04\x12\x08\n\x04\x42YTE\x10\x06\x12\n\n\x06UNUSED\x10\x05*\t\x08\xc8\x01\x10\x80\x80\x80\x80\x02*\t\x08\xc8\x01\x10\x80\x80\x80\x80\x02\x42\x02H\x03"""
)

a			:    List[Any]				 =		globals()
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, """sentencepiece_model_pb2""", _globals)
if _descriptor._USE_C_DESCRIPTORS is False:
			a			:    Tuple				 =		None
			a			:    List[str]				 =		B"""H\003"""
			# (generated by protobuf compiler, but `_TRAINERSPEC` is not defined)
			# _TRAINERSPEC.fields_by_name["mining_sentence_size"]._options = None
			# _TRAINERSPEC.fields_by_name["mining_sentence_size"]._serialized_options = b"\030\001"
			# _TRAINERSPEC.fields_by_name["training_sentence_size"]._options = None
			# _TRAINERSPEC.fields_by_name["training_sentence_size"]._serialized_options = b"\030\001"
			a			:    List[str]				 =		45
			a			:    Optional[Any]				 =		1581
			a			:    Optional[int]				 =		1517
			a			:    Optional[int]				 =		1570
			a			:    List[Any]				 =		1584
			a			:    int				 =		1793
			a			:    int				 =		1795
			a			:    Tuple				 =		1916
			a			:    Dict				 =		1864
			a			:    List[str]				 =		1905
			a			:    Any				 =		1919
			a			:    List[Any]				 =		2429
			a			:    Optional[int]				 =		2208
			a			:    Optional[int]				 =		2418
			a			:    List[Any]				 =		2323
			a			:    List[Any]				 =		2407
# @@protoc_insertion_point(module_scope)














"""simple docstring"""







import json
import os
from functools import lru_cache
from typing import Dict, List, Optional, Tuple, Union

import regex as re

from ...tokenization_utils import AddedToken, PreTrainedTokenizer
from ...tokenization_utils_base import BatchEncoding, EncodedInput
from ...utils import PaddingStrategy, logging


a			:    Dict				 =		logging.get_logger(__name__)


a			:    Optional[Any]				 =		{"""vocab_file""": """vocab.json""", """merges_file""": """merges.txt"""}

# See all LED models at https://huggingface.co/models?filter=LED
a			:    List[str]				 =		{
    """vocab_file""": {
        """allenai/led-base-16384""": """https://huggingface.co/allenai/led-base-16384/resolve/main/vocab.json""",
    },
    """merges_file""": {
        """allenai/led-base-16384""": """https://huggingface.co/allenai/led-base-16384/resolve/main/merges.txt""",
    },
    """tokenizer_file""": {
        """allenai/led-base-16384""": """https://huggingface.co/allenai/led-base-16384/resolve/main/tokenizer.json""",
    },
}

a			:    Dict				 =		{
    """allenai/led-base-16384""": 16384,
}





@lru_cache()
# Copied from transformers.models.bart.tokenization_bart.bytes_to_unicode
def 						lowercase__()    ->List[Any]:




						"""simple docstring"""



						lowercase__    :				Optional[int]=	(
						    list(range(ord("!"						) ,		ord("~"						) + 1						)						) + list(range(ord("¡"						) ,		ord("¬"						) + 1						)						) + list(range(ord("®"						) ,		ord("ÿ"						) + 1						)						)
						)
						lowercase__    :				str=	bs[:]
						lowercase__    :				List[str]=	0
						for b in range(2**8						):
												if b not in bs:
																		bs.append(A						)
																		cs.append(2**8 + n						)
																		n += 1
						lowercase__    :				Union[str, Any]=	[chr(A						) for n in cs]
						return dict(zip(A ,		A						)						)





def 						lowercase__(A						)    ->str:




						"""simple docstring"""



						lowercase__    :				Optional[int]=	set()
						lowercase__    :				Optional[int]=	word[0]
						for char in word[1:]:
												pairs.add((prev_char, char)						)
												lowercase__    :				Tuple=	char
						return pairs







class    __UpperCAmelCase(       SCREAMING_SNAKE_CASE__							):




						"""simple docstring"""




						__lowerCamelCase    	= VOCAB_FILES_NAMES
						__lowerCamelCase    	= PRETRAINED_VOCAB_FILES_MAP
						__lowerCamelCase    	= PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
						__lowerCamelCase    	= ["input_ids", "attention_mask"]




						def __init__(       self	,  snake_case__	,  snake_case__	,  snake_case__="replace"	,  snake_case__="<s>"	,  snake_case__="</s>"	,  snake_case__="</s>"	,  snake_case__="<s>"	,  snake_case__="<unk>"	,  snake_case__="<pad>"	,  snake_case__="<mask>"	,  snake_case__=False	,  **snake_case__	,  ):
												'''simple docstring'''
												lowercase__    :				Dict=	AddedToken(snake_case__	,  lstrip=snake_case__	,  rstrip=snake_case__      ) if isinstance(snake_case__	,  snake_case__      ) else bos_token
												lowercase__    :				Dict=	AddedToken(snake_case__	,  lstrip=snake_case__	,  rstrip=snake_case__      ) if isinstance(snake_case__	,  snake_case__      ) else eos_token
												lowercase__    :				str=	AddedToken(snake_case__	,  lstrip=snake_case__	,  rstrip=snake_case__      ) if isinstance(snake_case__	,  snake_case__      ) else sep_token
												lowercase__    :				Optional[Any]=	AddedToken(snake_case__	,  lstrip=snake_case__	,  rstrip=snake_case__      ) if isinstance(snake_case__	,  snake_case__      ) else cls_token
												lowercase__    :				List[str]=	AddedToken(snake_case__	,  lstrip=snake_case__	,  rstrip=snake_case__      ) if isinstance(snake_case__	,  snake_case__      ) else unk_token
												lowercase__    :				Any=	AddedToken(snake_case__	,  lstrip=snake_case__	,  rstrip=snake_case__      ) if isinstance(snake_case__	,  snake_case__      ) else pad_token

												# Mask token behave like a normal word, i.e. include the space before it
												lowercase__    :				int=	AddedToken(snake_case__	,  lstrip=snake_case__	,  rstrip=snake_case__      ) if isinstance(snake_case__	,  snake_case__      ) else mask_token

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

												with open(snake_case__	,  encoding="utf-8"      ) as vocab_handle:
																		lowercase__    :				int=	json.load(snake_case__      )
												lowercase__    :				List[str]=	{v: k for k, v in self.encoder.items()}
												lowercase__    :				Dict=	errors  # how to handle errors in decoding
												lowercase__    :				Optional[int]=	bytes_to_unicode()
												lowercase__    :				str=	{v: k for k, v in self.byte_encoder.items()}
												with open(snake_case__	,  encoding="utf-8"      ) as merges_handle:
																		lowercase__    :				Tuple=	merges_handle.read().split("\n"      )[1:-1]
												lowercase__    :				List[str]=	[tuple(merge.split()      ) for merge in bpe_merges]
												lowercase__    :				int=	dict(zip(snake_case__	,  range(len(snake_case__      )      )      )      )
												lowercase__    :				Optional[int]=	{}
												lowercase__    :				Tuple=	add_prefix_space

												# Should have added re.IGNORECASE so BPE merges can happen for capitalized versions of contractions
												lowercase__    :				Optional[int]=	re.compile(r"'s|'t|'re|'ve|'m|'ll|'d| ?\p{L}+| ?\p{N}+| ?[^\s\p{L}\p{N}]+|\s+(?!\S)|\s+"      )




						@property
						# Copied from transformers.models.bart.tokenization_bart.BartTokenizer.vocab_size
						def 		UpperCAmelCase_	(       self      ):
												'''simple docstring'''
												return len(self.encoder      )




						def 		UpperCAmelCase_	(       self      ):
												'''simple docstring'''
												return dict(self.encoder	,  **self.added_tokens_encoder      )




						def 		UpperCAmelCase_	(       self	,  snake_case__      ):
												'''simple docstring'''
												if token in self.cache:
																		return self.cache[token]
												lowercase__    :				Any=	tuple(snake_case__      )
												lowercase__    :				Union[str, Any]=	get_pairs(snake_case__      )

												if not pairs:
																		return token

												while True:
																		lowercase__    :				Union[str, Any]=	min(snake_case__	,  key=lambda snake_case__      : self.bpe_ranks.get(snake_case__	,  float("inf"      )      )      )
																		if bigram not in self.bpe_ranks:
																								break
																		lowercase__,     lowercase__    :				Dict=	bigram
																		lowercase__    :				Optional[Any]=	[]
																		lowercase__    :				Optional[int]=	0
																		while i < len(snake_case__      ):
																								try:
																														lowercase__    :				Optional[int]=	word.index(snake_case__	,  snake_case__      )
																								except ValueError:
																														new_word.extend(word[i:]      )
																														break
																								else:
																														new_word.extend(word[i:j]      )
																														lowercase__    :				List[Any]=	j

																								if word[i] == first and i < len(snake_case__      ) - 1 and word[i + 1] == second:
																														new_word.append(first + second      )
																														i += 2
																								else:
																														new_word.append(word[i]      )
																														i += 1
																		lowercase__    :				Optional[int]=	tuple(snake_case__      )
																		lowercase__    :				List[Any]=	new_word
																		if len(snake_case__      ) == 1:
																								break
																		else:
																								lowercase__    :				Tuple=	get_pairs(snake_case__      )
												lowercase__    :				Tuple=	" ".join(snake_case__      )
												lowercase__    :				List[str]=	word
												return word




						def 		UpperCAmelCase_	(       self	,  snake_case__      ):
												'''simple docstring'''
												lowercase__    :				Optional[int]=	[]
												for token in re.findall(self.pat	,  snake_case__      ):
																		lowercase__    :				int=	"".join(
																		    self.byte_encoder[b] for b in token.encode("utf-8"      )      )  # Maps all our bytes to unicode strings, avoiding control tokens of the BPE (spaces in our case)
																		bpe_tokens.extend(bpe_token for bpe_token in self.bpe(snake_case__      ).split(" "      )      )
												return bpe_tokens




						def 		UpperCAmelCase_	(       self	,  snake_case__      ):
												'''simple docstring'''
												return self.encoder.get(snake_case__	,  self.encoder.get(self.unk_token      )      )




						def 		UpperCAmelCase_	(       self	,  snake_case__      ):
												'''simple docstring'''
												return self.decoder.get(snake_case__      )




						def 		UpperCAmelCase_	(       self	,  snake_case__      ):
												'''simple docstring'''
												lowercase__    :				Union[str, Any]=	"".join(snake_case__      )
												lowercase__    :				Optional[int]=	bytearray([self.byte_decoder[c] for c in text]      ).decode("utf-8"	,  errors=self.errors      )
												return text




						def 		UpperCAmelCase_	(       self	,  snake_case__	,  snake_case__ = None      ):
												'''simple docstring'''
												if not os.path.isdir(snake_case__      ):
																		logger.error(F'''Vocabulary path ({save_directory}) should be a directory'''      )
																		return
												lowercase__    :				Dict=	os.path.join(
												    snake_case__	,  (filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"]      )
												lowercase__    :				Tuple=	os.path.join(
												    snake_case__	,  (filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["merges_file"]      )

												with open(snake_case__	,  "w"	,  encoding="utf-8"      ) as f:
																		f.write(json.dumps(self.encoder	,  indent=2	,  sort_keys=snake_case__	,  ensure_ascii=snake_case__      ) + "\n"      )

												lowercase__    :				Any=	0
												with open(snake_case__	,  "w"	,  encoding="utf-8"      ) as writer:
																		writer.write("#version: 0.2\n"      )
																		for bpe_tokens, token_index in sorted(self.bpe_ranks.items()	,  key=lambda snake_case__      : kv[1]      ):
																								if index != token_index:
																														logger.warning(
																														    F'''Saving vocabulary to {merge_file}: BPE merge indices are not consecutive.'''
																														    " Please check that the tokenizer is not corrupted!"      )
																														lowercase__    :				Optional[Any]=	token_index
																								writer.write(" ".join(snake_case__      ) + "\n"      )
																								index += 1

												return vocab_file, merge_file




						def 		UpperCAmelCase_	(       self	,  snake_case__	,  snake_case__ = None      ):
												'''simple docstring'''
												if token_ids_a is None:
																		return [self.cls_token_id] + token_ids_a + [self.sep_token_id]
												lowercase__    :				Any=	[self.cls_token_id]
												lowercase__    :				Dict=	[self.sep_token_id]
												return cls + token_ids_a + sep + sep + token_ids_a + sep




						def 		UpperCAmelCase_	(       self	,  snake_case__	,  snake_case__ = None	,  snake_case__ = False      ):
												'''simple docstring'''
												if already_has_special_tokens:
																		return super().get_special_tokens_mask(
																		    token_ids_a=snake_case__	,  token_ids_a=snake_case__	,  already_has_special_tokens=snake_case__      )

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




						def 		UpperCAmelCase_	(       self	,  snake_case__	,  snake_case__ = None      ):
												'''simple docstring'''
												lowercase__    :				Tuple=	[self.sep_token_id]
												lowercase__    :				Optional[int]=	[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]




						def 		UpperCAmelCase_	(       self	,  snake_case__	,  snake_case__=False	,  **snake_case__      ):
												'''simple docstring'''
												lowercase__    :				str=	kwargs.pop("add_prefix_space"	,  self.add_prefix_space      )
												if (is_split_into_words or add_prefix_space) and (len(snake_case__      ) > 0 and not text[0].isspace()):
																		lowercase__    :				List[Any]=	" " + text
												return (text, kwargs)




						def 		UpperCAmelCase_	(       self	,  snake_case__	,  snake_case__ = None	,  snake_case__ = PaddingStrategy.DO_NOT_PAD	,  snake_case__ = None	,  snake_case__ = None	,  ):
												'''simple docstring'''
												lowercase__    :				List[str]=	super()._pad(
												    encoded_inputs=snake_case__	,  max_length=snake_case__	,  padding_strategy=snake_case__	,  pad_to_multiple_of=snake_case__	,  return_attention_mask=snake_case__	,  )

												# Load from model defaults
												if return_attention_mask is None:
																		lowercase__    :				Tuple=	"attention_mask" in self.model_input_names

												if return_attention_mask and "global_attention_mask" in encoded_inputs:
																		lowercase__    :				Any=	encoded_inputs[self.model_input_names[0]]
																		# `global_attention_mask` need to have the same length as other (sequential) inputs.
																		lowercase__    :				int=	len(encoded_inputs["global_attention_mask"]      ) != len(snake_case__      )

																		if needs_to_be_padded:
																								lowercase__    :				Dict=	len(snake_case__      ) - len(encoded_inputs["global_attention_mask"]      )

																								if self.padding_side == "right":
																														# Use `-1` since `0` in `global_attention_mask` means `local attention` instead of `not to attend`
																														lowercase__    :				Tuple=	(
																														    encoded_inputs["global_attention_mask"] + [-1] * difference
																														)
																								elif self.padding_side == "left":
																														lowercase__    :				Any=	[-1] * difference + encoded_inputs[
																														    "global_attention_mask"
																														]
																								else:
																														raise ValueError("Invalid padding strategy:" + str(self.padding_side      )      )

												return encoded_inputs






