

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

import regex as re

from ...tokenization_utils import AddedToken, PreTrainedTokenizer
from ...utils import logging


_a:    List[str] 							=			logging.get_logger(__name__)


_a:    Union[str, Any] 							=			{"""vocab_file""": """vocab.json""", """merges_file""": """merges.txt"""}

_a:    Union[str, Any] 							=			{
    """vocab_file""": {
        """allenai/longformer-base-4096""": """https://huggingface.co/allenai/longformer-base-4096/resolve/main/vocab.json""",
        """allenai/longformer-large-4096""": (
            """https://huggingface.co/allenai/longformer-large-4096/resolve/main/vocab.json"""
        ),
        """allenai/longformer-large-4096-finetuned-triviaqa""": (
            """https://huggingface.co/allenai/longformer-large-4096-finetuned-triviaqa/resolve/main/vocab.json"""
        ),
        """allenai/longformer-base-4096-extra.pos.embd.only""": (
            """https://huggingface.co/allenai/longformer-base-4096-extra.pos.embd.only/resolve/main/vocab.json"""
        ),
        """allenai/longformer-large-4096-extra.pos.embd.only""": (
            """https://huggingface.co/allenai/longformer-large-4096-extra.pos.embd.only/resolve/main/vocab.json"""
        ),
    },
    """merges_file""": {
        """allenai/longformer-base-4096""": """https://huggingface.co/allenai/longformer-base-4096/resolve/main/merges.txt""",
        """allenai/longformer-large-4096""": (
            """https://huggingface.co/allenai/longformer-large-4096/resolve/main/merges.txt"""
        ),
        """allenai/longformer-large-4096-finetuned-triviaqa""": (
            """https://huggingface.co/allenai/longformer-large-4096-finetuned-triviaqa/resolve/main/merges.txt"""
        ),
        """allenai/longformer-base-4096-extra.pos.embd.only""": (
            """https://huggingface.co/allenai/longformer-base-4096-extra.pos.embd.only/resolve/main/merges.txt"""
        ),
        """allenai/longformer-large-4096-extra.pos.embd.only""": (
            """https://huggingface.co/allenai/longformer-large-4096-extra.pos.embd.only/resolve/main/merges.txt"""
        ),
    },
}

_a:    List[Any] 							=			{
    """allenai/longformer-base-4096""": 4096,
    """allenai/longformer-large-4096""": 4096,
    """allenai/longformer-large-4096-finetuned-triviaqa""": 4096,
    """allenai/longformer-base-4096-extra.pos.embd.only""": 4096,
    """allenai/longformer-large-4096-extra.pos.embd.only""": 4096,
}



@lru_cache()
# Copied from transformers.models.roberta.tokenization_roberta.bytes_to_unicode
def       __lowerCAmelCase      (						):
	UpperCAmelCase_       				=			(
	    list(range(ord("!"    )       ,     ord("~"    ) + 1    )    ) + list(range(ord("¡"    )       ,     ord("¬"    ) + 1    )    ) + list(range(ord("®"    )       ,     ord("ÿ"    ) + 1    )    )
	)
	UpperCAmelCase_       				=			bs[:]
	UpperCAmelCase_       				=			0
	for b in range(2**8    ):
		if b not in bs:
			bs.append(A    )
			cs.append(2**8 + n    )
			n += 1
	UpperCAmelCase_       				=			[chr(A    ) for n in cs]
	return dict(zip(A       ,     A    )    )



def       __lowerCAmelCase      (						A    ):
	UpperCAmelCase_       				=			set()
	UpperCAmelCase_       				=			word[0]
	for char in word[1:]:
		pairs.add((prev_char, char)    )
		UpperCAmelCase_       				=			char
	return pairs




class 						__UpperCamelCase    (					lowercase						):
	SCREAMING_SNAKE_CASE__    				=     VOCAB_FILES_NAMES
	SCREAMING_SNAKE_CASE__    				=     PRETRAINED_VOCAB_FILES_MAP
	SCREAMING_SNAKE_CASE__    				=     PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
	SCREAMING_SNAKE_CASE__    				=     ['input_ids', 'attention_mask']




	def __init__(		self	:						Optional[Any]		,	lowerCAmelCase	:						Union[str, Any]		,	lowerCAmelCase	:						List[str]		,	lowerCAmelCase	:						int="replace"		,	lowerCAmelCase	:						List[str]="<s>"		,	lowerCAmelCase	:						List[Any]="</s>"		,	lowerCAmelCase	:						str="</s>"		,	lowerCAmelCase	:						Union[str, Any]="<s>"		,	lowerCAmelCase	:						Tuple="<unk>"		,	lowerCAmelCase	:						Dict="<pad>"		,	lowerCAmelCase	:						Optional[Any]="<mask>"		,	lowerCAmelCase	:						str=False		,	**lowerCAmelCase	:						List[Any]		,	):


		'''simple docstring'''







		UpperCAmelCase_       				=			AddedToken(lowerCAmelCase		,	lstrip=lowerCAmelCase		,	rstrip=lowerCAmelCase							) if isinstance(lowerCAmelCase		,	lowerCAmelCase							) else bos_token
		UpperCAmelCase_       				=			AddedToken(lowerCAmelCase		,	lstrip=lowerCAmelCase		,	rstrip=lowerCAmelCase							) if isinstance(lowerCAmelCase		,	lowerCAmelCase							) else eos_token
		UpperCAmelCase_       				=			AddedToken(lowerCAmelCase		,	lstrip=lowerCAmelCase		,	rstrip=lowerCAmelCase							) if isinstance(lowerCAmelCase		,	lowerCAmelCase							) else sep_token
		UpperCAmelCase_       				=			AddedToken(lowerCAmelCase		,	lstrip=lowerCAmelCase		,	rstrip=lowerCAmelCase							) if isinstance(lowerCAmelCase		,	lowerCAmelCase							) else cls_token
		UpperCAmelCase_       				=			AddedToken(lowerCAmelCase		,	lstrip=lowerCAmelCase		,	rstrip=lowerCAmelCase							) if isinstance(lowerCAmelCase		,	lowerCAmelCase							) else unk_token
		UpperCAmelCase_       				=			AddedToken(lowerCAmelCase		,	lstrip=lowerCAmelCase		,	rstrip=lowerCAmelCase							) if isinstance(lowerCAmelCase		,	lowerCAmelCase							) else pad_token

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

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

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

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




	@property
	def       __A					(		self	:						Dict							):


		'''simple docstring'''







		return len(self.encoder							)




	def       __A					(		self	:						Tuple							):


		'''simple docstring'''







		return dict(self.encoder		,	**self.added_tokens_encoder							)




	def       __A					(		self	:						Dict		,	lowerCAmelCase	:						Optional[Any]							):


		'''simple docstring'''







		if token in self.cache:
			return self.cache[token]
		UpperCAmelCase_       				=			tuple(lowerCAmelCase							)
		UpperCAmelCase_       				=			get_pairs(lowerCAmelCase							)

		if not pairs:
			return token

		while True:
			UpperCAmelCase_       				=			min(lowerCAmelCase		,	key=lambda lowerCAmelCase							: self.bpe_ranks.get(lowerCAmelCase		,	float("inf"							)							)							)
			if bigram not in self.bpe_ranks:
				break
			UpperCAmelCase_				,   UpperCAmelCase_       				=			bigram
			UpperCAmelCase_       				=			[]
			UpperCAmelCase_       				=			0
			while i < len(lowerCAmelCase							):
				try:
					UpperCAmelCase_       				=			word.index(lowerCAmelCase		,	lowerCAmelCase							)
				except ValueError:
					new_word.extend(word[i:]							)
					break
				else:
					new_word.extend(word[i:j]							)
					UpperCAmelCase_       				=			j

				if word[i] == first and i < len(lowerCAmelCase							) - 1 and word[i + 1] == second:
					new_word.append(first + second							)
					i += 2
				else:
					new_word.append(word[i]							)
					i += 1
			UpperCAmelCase_       				=			tuple(lowerCAmelCase							)
			UpperCAmelCase_       				=			new_word
			if len(lowerCAmelCase							) == 1:
				break
			else:
				UpperCAmelCase_       				=			get_pairs(lowerCAmelCase							)
		UpperCAmelCase_       				=			" ".join(lowerCAmelCase							)
		UpperCAmelCase_       				=			word
		return word




	def       __A					(		self	:						str		,	lowerCAmelCase	:						int							):


		'''simple docstring'''







		UpperCAmelCase_       				=			[]
		for token in re.findall(self.pat		,	lowerCAmelCase							):
			UpperCAmelCase_       				=			"".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(lowerCAmelCase							).split(" "							)							)
		return bpe_tokens




	def       __A					(		self	:						Tuple		,	lowerCAmelCase	:						int							):


		'''simple docstring'''







		return self.encoder.get(lowerCAmelCase		,	self.encoder.get(self.unk_token							)							)




	def       __A					(		self	:						List[str]		,	lowerCAmelCase	:						Any							):


		'''simple docstring'''







		return self.decoder.get(lowerCAmelCase							)




	def       __A					(		self	:						int		,	lowerCAmelCase	:						List[str]							):


		'''simple docstring'''







		UpperCAmelCase_       				=			"".join(lowerCAmelCase							)
		UpperCAmelCase_       				=			bytearray([self.byte_decoder[c] for c in text]							).decode("utf-8"		,	errors=self.errors							)
		return text




	def       __A					(		self	:						str		,	lowerCAmelCase	:						str		,	lowerCAmelCase	:						Optional[str] = None							):


		'''simple docstring'''







		if not os.path.isdir(lowerCAmelCase							):
			logger.error(F"Vocabulary path ({save_directory}) should be a directory"							)
			return
		UpperCAmelCase_       				=			os.path.join(
		    lowerCAmelCase		,	(filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"]							)
		UpperCAmelCase_       				=			os.path.join(
		    lowerCAmelCase		,	(filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["merges_file"]							)

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

		UpperCAmelCase_       				=			0
		with open(lowerCAmelCase		,	"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 lowerCAmelCase							: 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!"							)
					UpperCAmelCase_       				=			token_index
				writer.write(" ".join(lowerCAmelCase							) + "\n"							)
				index += 1

		return vocab_file, merge_file




	def       __A					(		self	:						Union[str, Any]		,	lowerCAmelCase	:						List[int]		,	lowerCAmelCase	:						Optional[List[int]] = None							):


		'''simple docstring'''







		if token_ids_a is None:
			return [self.cls_token_id] + token_ids_a + [self.sep_token_id]
		UpperCAmelCase_       				=			[self.cls_token_id]
		UpperCAmelCase_       				=			[self.sep_token_id]
		return cls + token_ids_a + sep + sep + token_ids_a + sep




	def       __A					(		self	:						int		,	lowerCAmelCase	:						List[int]		,	lowerCAmelCase	:						Optional[List[int]] = None		,	lowerCAmelCase	:						bool = False							):


		'''simple docstring'''







		if already_has_special_tokens:
			return super().get_special_tokens_mask(
			    token_ids_a=lowerCAmelCase		,	token_ids_a=lowerCAmelCase		,	already_has_special_tokens=lowerCAmelCase							)

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




	def       __A					(		self	:						Dict		,	lowerCAmelCase	:						List[int]		,	lowerCAmelCase	:						Optional[List[int]] = None							):


		'''simple docstring'''







		UpperCAmelCase_       				=			[self.sep_token_id]
		UpperCAmelCase_       				=			[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       __A					(		self	:						Any		,	lowerCAmelCase	:						List[str]		,	lowerCAmelCase	:						Optional[int]=False		,	**lowerCAmelCase	:						Dict							):


		'''simple docstring'''







		UpperCAmelCase_       				=			kwargs.pop("add_prefix_space"		,	self.add_prefix_space							)
		if (is_split_into_words or add_prefix_space) and (len(lowerCAmelCase							) > 0 and not text[0].isspace()):
			UpperCAmelCase_       				=			" " + text
		return (text, kwargs)


import json
import os
import shutil
import tempfile
import unittest

from transformers import BatchEncoding, CanineTokenizer
from transformers.testing_utils import require_tokenizers, require_torch
from transformers.tokenization_utils import AddedToken
from transformers.utils import cached_property

from ...test_tokenization_common import TokenizerTesterMixin

class 						__UpperCamelCase    (					lowercase     ,     unittest.TestCase						):
	SCREAMING_SNAKE_CASE__    				=     CanineTokenizer
	SCREAMING_SNAKE_CASE__    				=     False




	def       __A					(		self	:						List[str]							):


		'''simple docstring'''







		super().setUp()
		UpperCAmelCase_       				=			CanineTokenizer()
		tokenizer.save_pretrained(self.tmpdirname							)




	@cached_property
	def       __A					(		self	:						Tuple							):


		'''simple docstring'''







		return CanineTokenizer.from_pretrained("google/canine-s"							)




	def       __A					(		self	:						List[str]		,	**lowerCAmelCase	:						Any							):


		'''simple docstring'''







		UpperCAmelCase_       				=			self.tokenizer_class.from_pretrained(self.tmpdirname		,	**lowerCAmelCase							)
		UpperCAmelCase_       				=			1_024
		return tokenizer




	@require_torch
	def       __A					(		self	:						int							):


		'''simple docstring'''







		UpperCAmelCase_       				=			self.canine_tokenizer
		UpperCAmelCase_       				=			["Life is like a box of chocolates.", "You never know what you're gonna get."]
		# fmt: off
		UpperCAmelCase_       				=			[57_344, 76, 105, 102, 101, 32, 105, 115, 32, 108, 105, 107, 101, 32, 97, 32, 98, 111, 120, 32, 111, 102, 32, 99, 104, 111, 99, 111, 108, 97, 116, 101, 115, 46, 57_345, 0, 0, 0, 0]
		# fmt: on
		UpperCAmelCase_       				=			tokenizer(lowerCAmelCase		,	padding=lowerCAmelCase		,	return_tensors="pt"							)
		self.assertIsInstance(lowerCAmelCase		,	lowerCAmelCase							)

		UpperCAmelCase_       				=			list(batch.input_ids.numpy()[0]							)

		self.assertListEqual(lowerCAmelCase		,	lowerCAmelCase							)

		self.assertEqual((2, 39)		,	batch.input_ids.shape							)
		self.assertEqual((2, 39)		,	batch.attention_mask.shape							)




	@require_torch
	def       __A					(		self	:						Tuple							):


		'''simple docstring'''







		UpperCAmelCase_       				=			self.canine_tokenizer
		UpperCAmelCase_       				=			["Once there was a man.", "He wrote a test in HuggingFace Tranformers."]
		UpperCAmelCase_       				=			tokenizer(lowerCAmelCase		,	padding=lowerCAmelCase		,	return_tensors="pt"							)
		# check if input_ids, attention_mask and token_type_ids are returned
		self.assertIn("input_ids"		,	lowerCAmelCase							)
		self.assertIn("attention_mask"		,	lowerCAmelCase							)
		self.assertIn("token_type_ids"		,	lowerCAmelCase							)




	@require_torch
	def       __A					(		self	:						Dict							):


		'''simple docstring'''







		UpperCAmelCase_       				=			self.canine_tokenizer
		UpperCAmelCase_       				=			[
		    "What's the weater?",
		    "It's about 25 degrees.",
		]
		UpperCAmelCase_       				=			tokenizer(
		    text_target=lowerCAmelCase		,	max_length=32		,	padding="max_length"		,	truncation=lowerCAmelCase		,	return_tensors="pt"							)
		self.assertEqual(32		,	targets["input_ids"].shape[1]							)




	def       __A					(		self	:						Union[str, Any]							):


		'''simple docstring'''







		UpperCAmelCase_       				=			self.get_tokenizers()
		for tokenizer in tokenizers:
			with self.subTest(F"{tokenizer.__class__.__name__}"							):
				self.assertNotEqual(tokenizer.model_max_length		,	42							)

        # Now let's start the test
		UpperCAmelCase_       				=			self.get_tokenizers()
		for tokenizer in tokenizers:
			with self.subTest(F"{tokenizer.__class__.__name__}"							):
				# Isolate this from the other tests because we save additional tokens/etc
				UpperCAmelCase_       				=			tempfile.mkdtemp()

				UpperCAmelCase_       				=			" He is very happy, UNwant\u00E9d,running"
				UpperCAmelCase_       				=			tokenizer.encode(lowerCAmelCase		,	add_special_tokens=lowerCAmelCase							)
				tokenizer.save_pretrained(lowerCAmelCase							)

				UpperCAmelCase_       				=			tokenizer.__class__.from_pretrained(lowerCAmelCase							)
				UpperCAmelCase_       				=			after_tokenizer.encode(lowerCAmelCase		,	add_special_tokens=lowerCAmelCase							)
				self.assertListEqual(lowerCAmelCase		,	lowerCAmelCase							)

				shutil.rmtree(lowerCAmelCase							)

		UpperCAmelCase_       				=			self.get_tokenizers(model_max_length=42							)
		for tokenizer in tokenizers:
			with self.subTest(F"{tokenizer.__class__.__name__}"							):
				# Isolate this from the other tests because we save additional tokens/etc
				UpperCAmelCase_       				=			tempfile.mkdtemp()

				UpperCAmelCase_       				=			" He is very happy, UNwant\u00E9d,running"

				UpperCAmelCase_       				=			tokenizer.additional_special_tokens

				# We can add a new special token for Canine as follows:
				UpperCAmelCase_       				=			chr(0XE007							)
				additional_special_tokens.append(lowerCAmelCase							)
				tokenizer.add_special_tokens({"additional_special_tokens": additional_special_tokens}							)
				UpperCAmelCase_       				=			tokenizer.encode(lowerCAmelCase		,	add_special_tokens=lowerCAmelCase							)
				tokenizer.save_pretrained(lowerCAmelCase							)

				UpperCAmelCase_       				=			tokenizer.__class__.from_pretrained(lowerCAmelCase							)
				UpperCAmelCase_       				=			after_tokenizer.encode(lowerCAmelCase		,	add_special_tokens=lowerCAmelCase							)
				self.assertListEqual(lowerCAmelCase		,	lowerCAmelCase							)
				self.assertIn(lowerCAmelCase		,	after_tokenizer.additional_special_tokens							)
				self.assertEqual(after_tokenizer.model_max_length		,	42							)

				UpperCAmelCase_       				=			tokenizer.__class__.from_pretrained(lowerCAmelCase		,	model_max_length=43							)
				self.assertEqual(tokenizer.model_max_length		,	43							)

				shutil.rmtree(lowerCAmelCase							)




	def       __A					(		self	:						List[Any]							):


		'''simple docstring'''







		UpperCAmelCase_       				=			self.get_tokenizers(do_lower_case=lowerCAmelCase							)
		for tokenizer in tokenizers:
			with self.subTest(F"{tokenizer.__class__.__name__}"							):
				UpperCAmelCase_				,   UpperCAmelCase_       				=			self.get_clean_sequence(lowerCAmelCase							)

				# a special token for Canine can be defined as follows:
				UpperCAmelCase_       				=			0XE005
				UpperCAmelCase_       				=			chr(lowerCAmelCase							)

				tokenizer.add_special_tokens({"cls_token": special_token}							)
				UpperCAmelCase_       				=			tokenizer.encode(lowerCAmelCase		,	add_special_tokens=lowerCAmelCase							)
				self.assertEqual(len(lowerCAmelCase							)		,	1							)

				UpperCAmelCase_       				=			tokenizer.decode(ids + encoded_special_token		,	clean_up_tokenization_spaces=lowerCAmelCase							)
				UpperCAmelCase_       				=			tokenizer.encode(lowerCAmelCase		,	add_special_tokens=lowerCAmelCase							)

				UpperCAmelCase_       				=			tokenizer.encode(lowerCAmelCase		,	add_special_tokens=lowerCAmelCase							)
				UpperCAmelCase_       				=			tokenizer.encode(lowerCAmelCase		,	add_special_tokens=lowerCAmelCase							)
				self.assertEqual(lowerCAmelCase		,	input_encoded + special_token_id							)

				UpperCAmelCase_       				=			tokenizer.decode(lowerCAmelCase		,	skip_special_tokens=lowerCAmelCase							)
				self.assertTrue(special_token not in decoded							)




	def       __A					(		self	:						int							):


		'''simple docstring'''







		UpperCAmelCase_       				=			self.get_tokenizers(do_lower_case=lowerCAmelCase							)
		for tokenizer in tokenizers:
			with self.subTest(F"{tokenizer.__class__.__name__}"							):
				UpperCAmelCase_       				=			chr(0XE005							)
				UpperCAmelCase_       				=			chr(0XE006							)

				# `add_tokens` method stores special tokens only in `tokenizer.unique_no_split_tokens`. (in tokenization_utils.py)
				tokenizer.add_tokens([SPECIAL_TOKEN_1]		,	special_tokens=lowerCAmelCase							)
				# `add_special_tokens` method stores special tokens in `tokenizer.additional_special_tokens`,
				# which also occur in `tokenizer.all_special_tokens`. (in tokenization_utils_base.py)
				tokenizer.add_special_tokens({"additional_special_tokens": [SPECIAL_TOKEN_2]}							)

				UpperCAmelCase_       				=			tokenizer.tokenize(lowerCAmelCase							)
				UpperCAmelCase_       				=			tokenizer.tokenize(lowerCAmelCase							)

				self.assertEqual(len(lowerCAmelCase							)		,	1							)
				self.assertEqual(len(lowerCAmelCase							)		,	1							)
				self.assertEqual(token_a[0]		,	lowerCAmelCase							)
				self.assertEqual(token_a[0]		,	lowerCAmelCase							)




	@require_tokenizers
	def       __A					(		self	:						Dict							):


		'''simple docstring'''







		UpperCAmelCase_       				=			self.get_tokenizers(do_lower_case=lowerCAmelCase							)
		for tokenizer in tokenizers:
			with self.subTest(F"{tokenizer.__class__.__name__}"							):
				# a special token for Canine can be defined as follows:
				UpperCAmelCase_       				=			0XE006
				UpperCAmelCase_       				=			chr(lowerCAmelCase							)

				UpperCAmelCase_       				=			AddedToken(lowerCAmelCase		,	lstrip=lowerCAmelCase							)
				tokenizer.add_special_tokens({"additional_special_tokens": [new_token]}							)

				with tempfile.TemporaryDirectory() as tmp_dir_name:
					tokenizer.save_pretrained(lowerCAmelCase							)
					tokenizer.from_pretrained(lowerCAmelCase							)




	def       __A					(		self	:						str							):


		'''simple docstring'''







		UpperCAmelCase_       				=			[]
		if self.test_slow_tokenizer:
			tokenizer_list.append((self.tokenizer_class, self.get_tokenizer())							)

		if self.test_rust_tokenizer:
			tokenizer_list.append((self.rust_tokenizer_class, self.get_rust_tokenizer())							)

		for tokenizer_class, tokenizer_utils in tokenizer_list:
			with tempfile.TemporaryDirectory() as tmp_dir:
				tokenizer_utils.save_pretrained(lowerCAmelCase							)

				with open(os.path.join(lowerCAmelCase		,	"special_tokens_map.json"							)		,	encoding="utf-8"							) as json_file:
					UpperCAmelCase_       				=			json.load(lowerCAmelCase							)

				with open(os.path.join(lowerCAmelCase		,	"tokenizer_config.json"							)		,	encoding="utf-8"							) as json_file:
					UpperCAmelCase_       				=			json.load(lowerCAmelCase							)

				# a special token for Canine can be defined as follows:
				UpperCAmelCase_       				=			0XE006
				UpperCAmelCase_       				=			chr(lowerCAmelCase							)

				UpperCAmelCase_       				=			[new_token_a]
				UpperCAmelCase_       				=			[new_token_a]

				with open(os.path.join(lowerCAmelCase		,	"special_tokens_map.json"							)		,	"w"		,	encoding="utf-8"							) as outfile:
					json.dump(lowerCAmelCase		,	lowerCAmelCase							)
				with open(os.path.join(lowerCAmelCase		,	"tokenizer_config.json"							)		,	"w"		,	encoding="utf-8"							) as outfile:
					json.dump(lowerCAmelCase		,	lowerCAmelCase							)

				# the following checks allow us to verify that our test works as expected, i.e. that the tokenizer takes
				# into account the new value of additional_special_tokens given in the "tokenizer_config.json" and
				# "special_tokens_map.json" files
				UpperCAmelCase_       				=			tokenizer_class.from_pretrained(lowerCAmelCase		,	extra_ids=0							)
				self.assertIn(lowerCAmelCase		,	tokenizer_without_change_in_init.additional_special_tokens							)
				# self.assertIn("an_additional_special_token",tokenizer_without_change_in_init.get_vocab()) # ByT5Tokenization no vocab
				self.assertEqual(
				    [new_token_a]		,	tokenizer_without_change_in_init.convert_ids_to_tokens(
				        tokenizer_without_change_in_init.convert_tokens_to_ids([new_token_a]							)							)		,	)

				UpperCAmelCase_       				=			0XE007
				UpperCAmelCase_       				=			chr(lowerCAmelCase							)
				# Now we test that we can change the value of additional_special_tokens in the from_pretrained
				UpperCAmelCase_       				=			[AddedToken(lowerCAmelCase		,	lstrip=lowerCAmelCase							)]
				UpperCAmelCase_       				=			tokenizer_class.from_pretrained(
				    lowerCAmelCase		,	additional_special_tokens=lowerCAmelCase		,	extra_ids=0							)

				self.assertIn(lowerCAmelCase		,	tokenizer.additional_special_tokens							)
				# self.assertIn(new_token_2,tokenizer.get_vocab()) # ByT5Tokenization no vocab
				self.assertEqual(
				    [new_token_a]		,	tokenizer.convert_ids_to_tokens(tokenizer.convert_tokens_to_ids([new_token_a]							)							)							)




	@require_tokenizers
	def       __A					(		self	:						Any							):


		'''simple docstring'''







		UpperCAmelCase_       				=			self.get_tokenizers(do_lower_case=lowerCAmelCase							)
		for tokenizer in tokenizers:
			with self.subTest(F"{tokenizer.__class__.__name__}"							):
				UpperCAmelCase_       				=			"hello world"
				if self.space_between_special_tokens:
					UpperCAmelCase_       				=			"[CLS] hello world [SEP]"
				else:
					UpperCAmelCase_       				=			input
				UpperCAmelCase_       				=			tokenizer.encode(lowerCAmelCase		,	add_special_tokens=lowerCAmelCase							)
				UpperCAmelCase_       				=			tokenizer.decode(lowerCAmelCase		,	spaces_between_special_tokens=self.space_between_special_tokens							)
				self.assertIn(lowerCAmelCase		,	[output, output.lower()]							)




	def       __A					(		self	:						Optional[Any]							):


		'''simple docstring'''







		UpperCAmelCase_       				=			self.get_tokenizers()
		for tokenizer in tokenizers:
			with self.subTest(F"{tokenizer.__class__.__name__}"							):
				UpperCAmelCase_       				=			[
				    "bos_token",
				    "eos_token",
				    "unk_token",
				    "sep_token",
				    "pad_token",
				    "cls_token",
				    "mask_token",
				]

		UpperCAmelCase_       				=			"a"
		UpperCAmelCase_       				=			ord(lowerCAmelCase							)

		for attr in attributes_list:
			setattr(lowerCAmelCase		,	attr + "_id"		,	lowerCAmelCase							)
			self.assertEqual(getattr(lowerCAmelCase		,	lowerCAmelCase							)		,	lowerCAmelCase							)
			self.assertEqual(getattr(lowerCAmelCase		,	attr + "_id"							)		,	lowerCAmelCase							)

			setattr(lowerCAmelCase		,	attr + "_id"		,	lowerCAmelCase							)
			self.assertEqual(getattr(lowerCAmelCase		,	lowerCAmelCase							)		,	lowerCAmelCase							)
			self.assertEqual(getattr(lowerCAmelCase		,	attr + "_id"							)		,	lowerCAmelCase							)

		setattr(lowerCAmelCase		,	"additional_special_tokens_ids"		,	[]							)
		self.assertListEqual(getattr(lowerCAmelCase		,	"additional_special_tokens"							)		,	[]							)
		self.assertListEqual(getattr(lowerCAmelCase		,	"additional_special_tokens_ids"							)		,	[]							)

		UpperCAmelCase_       				=			0XE006
		UpperCAmelCase_       				=			chr(lowerCAmelCase							)
		setattr(lowerCAmelCase		,	"additional_special_tokens_ids"		,	[additional_special_token_id]							)
		self.assertListEqual(getattr(lowerCAmelCase		,	"additional_special_tokens"							)		,	[additional_special_token]							)
		self.assertListEqual(getattr(lowerCAmelCase		,	"additional_special_tokens_ids"							)		,	[additional_special_token_id]							)




	def       __A					(		self	:						int							):


		'''simple docstring'''







		pass




	def       __A					(		self	:						Dict							):


		'''simple docstring'''







		pass




	def       __A					(		self	:						Union[str, Any]							):


		'''simple docstring'''







		pass




	def       __A					(		self	:						Tuple							):


		'''simple docstring'''







		pass




	def       __A					(		self	:						Optional[Any]							):


		'''simple docstring'''







		pass




	def       __A					(		self	:						Tuple							):


		'''simple docstring'''







		pass




	def       __A					(		self	:						Union[str, Any]							):


		'''simple docstring'''







		pass




	def       __A					(		self	:						int							):


		'''simple docstring'''







		pass