



'''simple docstring'''




import os
import unittest

from transformers import BatchEncoding
from transformers.models.bert.tokenization_bert import (
    BasicTokenizer,
    WordpieceTokenizer,
    _is_control,
    _is_punctuation,
    _is_whitespace,
)
from transformers.models.prophetnet.tokenization_prophetnet import VOCAB_FILES_NAMES, ProphetNetTokenizer
from transformers.testing_utils import require_torch, slow

from ...test_tokenization_common import TokenizerTesterMixin

class 			UpperCamelCase_ (							__magic_name__      ,     unittest.TestCase			):
	lowercase          = ProphetNetTokenizer
	lowercase          = False





	def  _lowercase(  self    )			->			Union[str, Any]:
								super().setUp()

								UpperCAmelCase     :		Any							     =		[
								    """[UNK]""",
								    """[CLS]""",
								    """[SEP]""",
								    """[PAD]""",
								    """[MASK]""",
								    """want""",
								    """##want""",
								    """##ed""",
								    """wa""",
								    """un""",
								    """runn""",
								    """##ing""",
								    """,""",
								    """low""",
								    """lowest""",
								]
								UpperCAmelCase     :		int							     =		os.path.join(self.tmpdirname		,		VOCAB_FILES_NAMES["""vocab_file"""]    )
								with open(self.vocab_file		,		"""w"""		,		encoding="""utf-8"""    ) as vocab_writer:
															vocab_writer.write("""""".join([x + """\n""" for x in vocab_tokens]    )    )





	def  _lowercase(  self		,		A    )			->			Optional[Any]:
								UpperCAmelCase     :		Optional[int]							     =		"""UNwant\u00E9d,running"""
								UpperCAmelCase     :		str							     =		"""unwanted, running"""
								return input_text, output_text





	def  _lowercase(  self    )			->			Any:
								UpperCAmelCase     :		Dict							     =		self.tokenizer_class(self.vocab_file    )

								UpperCAmelCase     :		Dict							     =		tokenizer.tokenize("""UNwant\u00E9d,running"""    )
								self.assertListEqual(A		,		["""un""", """##want""", """##ed""", """,""", """runn""", """##ing"""]    )
								self.assertListEqual(tokenizer.convert_tokens_to_ids(A    )		,		[9, 6, 7, 12, 10, 11]    )





	def  _lowercase(  self    )			->			Optional[Any]:
								UpperCAmelCase     :		int							     =		BasicTokenizer()

								self.assertListEqual(tokenizer.tokenize("""ah\u535A\u63A8zz"""    )		,		["""ah""", """\u535A""", """\u63A8""", """zz"""]    )





	def  _lowercase(  self    )			->			Any:
								UpperCAmelCase     :		Dict							     =		BasicTokenizer(do_lower_case=A    )

								self.assertListEqual(
								    tokenizer.tokenize(""" \tHeLLo!how  \n Are yoU?  """    )		,		["""hello""", """!""", """how""", """are""", """you""", """?"""]    )
								self.assertListEqual(tokenizer.tokenize("""H\u00E9llo"""    )		,		["""hello"""]    )





	def  _lowercase(  self    )			->			Tuple:
								UpperCAmelCase     :		Optional[Any]							     =		BasicTokenizer(do_lower_case=A		,		strip_accents=A    )

								self.assertListEqual(
								    tokenizer.tokenize(""" \tHäLLo!how  \n Are yoU?  """    )		,		["""hällo""", """!""", """how""", """are""", """you""", """?"""]    )
								self.assertListEqual(tokenizer.tokenize("""H\u00E9llo"""    )		,		["""h\u00E9llo"""]    )





	def  _lowercase(  self    )			->			Dict:
								UpperCAmelCase     :		Any							     =		BasicTokenizer(do_lower_case=A		,		strip_accents=A    )

								self.assertListEqual(
								    tokenizer.tokenize(""" \tHäLLo!how  \n Are yoU?  """    )		,		["""hallo""", """!""", """how""", """are""", """you""", """?"""]    )
								self.assertListEqual(tokenizer.tokenize("""H\u00E9llo"""    )		,		["""hello"""]    )





	def  _lowercase(  self    )			->			Any:
								UpperCAmelCase     :		Dict							     =		BasicTokenizer(do_lower_case=A    )

								self.assertListEqual(
								    tokenizer.tokenize(""" \tHäLLo!how  \n Are yoU?  """    )		,		["""hallo""", """!""", """how""", """are""", """you""", """?"""]    )
								self.assertListEqual(tokenizer.tokenize("""H\u00E9llo"""    )		,		["""hello"""]    )





	def  _lowercase(  self    )			->			Optional[Any]:
								UpperCAmelCase     :		Any							     =		BasicTokenizer(do_lower_case=A    )

								self.assertListEqual(
								    tokenizer.tokenize(""" \tHeLLo!how  \n Are yoU?  """    )		,		["""HeLLo""", """!""", """how""", """Are""", """yoU""", """?"""]    )





	def  _lowercase(  self    )			->			str:
								UpperCAmelCase     :		str							     =		BasicTokenizer(do_lower_case=A		,		strip_accents=A    )

								self.assertListEqual(
								    tokenizer.tokenize(""" \tHäLLo!how  \n Are yoU?  """    )		,		["""HäLLo""", """!""", """how""", """Are""", """yoU""", """?"""]    )





	def  _lowercase(  self    )			->			Dict:
								UpperCAmelCase     :		Optional[int]							     =		BasicTokenizer(do_lower_case=A		,		strip_accents=A    )

								self.assertListEqual(
								    tokenizer.tokenize(""" \tHäLLo!how  \n Are yoU?  """    )		,		["""HaLLo""", """!""", """how""", """Are""", """yoU""", """?"""]    )





	def  _lowercase(  self    )			->			List[str]:
								UpperCAmelCase     :		Optional[int]							     =		BasicTokenizer(do_lower_case=A		,		never_split=["""[UNK]"""]    )

								self.assertListEqual(
								    tokenizer.tokenize(""" \tHeLLo!how  \n Are yoU? [UNK]"""    )		,		["""HeLLo""", """!""", """how""", """Are""", """yoU""", """?""", """[UNK]"""]    )





	def  _lowercase(  self    )			->			List[str]:
								UpperCAmelCase     :		Any							     =		["""[UNK]""", """[CLS]""", """[SEP]""", """want""", """##want""", """##ed""", """wa""", """un""", """runn""", """##ing"""]

								UpperCAmelCase     :		List[Any]							     =		{}
								for i, token in enumerate(A    ):
															UpperCAmelCase     :		Tuple							     =		i
								UpperCAmelCase     :		Dict							     =		WordpieceTokenizer(vocab=A		,		unk_token="""[UNK]"""    )

								self.assertListEqual(tokenizer.tokenize(""""""    )		,		[]    )

								self.assertListEqual(tokenizer.tokenize("""unwanted running"""    )		,		["""un""", """##want""", """##ed""", """runn""", """##ing"""]    )

								self.assertListEqual(tokenizer.tokenize("""unwantedX running"""    )		,		["""[UNK]""", """runn""", """##ing"""]    )





	@require_torch
	def  _lowercase(  self    )			->			Optional[int]:
								UpperCAmelCase     :		List[str]							     =		self.tokenizer_class.from_pretrained("""microsoft/prophetnet-large-uncased"""    )

								UpperCAmelCase     :		List[str]							     =		["""A long paragraph for summarization.""", """Another paragraph for summarization."""]
								UpperCAmelCase     :		Any							     =		[1037, 2146, 20423, 2005, 7680, 7849, 3989, 1012, 102]
								UpperCAmelCase     :		Dict							     =		tokenizer(A		,		padding=A		,		return_tensors="""pt"""    )
								self.assertIsInstance(A		,		A    )
								UpperCAmelCase     :		Dict							     =		list(batch.input_ids.numpy()[0]    )
								self.assertListEqual(A		,		A    )

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





	def  _lowercase(  self    )			->			Tuple:
								self.assertTrue(_is_whitespace(""" """    )    )
								self.assertTrue(_is_whitespace("""\t"""    )    )
								self.assertTrue(_is_whitespace("""\r"""    )    )
								self.assertTrue(_is_whitespace("""\n"""    )    )
								self.assertTrue(_is_whitespace("""\u00A0"""    )    )

								self.assertFalse(_is_whitespace("""A"""    )    )
								self.assertFalse(_is_whitespace("""-"""    )    )





	def  _lowercase(  self    )			->			Tuple:
								self.assertTrue(_is_control("""\u0005"""    )    )

								self.assertFalse(_is_control("""A"""    )    )
								self.assertFalse(_is_control(""" """    )    )
								self.assertFalse(_is_control("""\t"""    )    )
								self.assertFalse(_is_control("""\r"""    )    )





	def  _lowercase(  self    )			->			Any:
								self.assertTrue(_is_punctuation("""-"""    )    )
								self.assertTrue(_is_punctuation("""$"""    )    )
								self.assertTrue(_is_punctuation("""`"""    )    )
								self.assertTrue(_is_punctuation("""."""    )    )

								self.assertFalse(_is_punctuation("""A"""    )    )
								self.assertFalse(_is_punctuation(""" """    )    )






	@slow
	def  _lowercase(  self    )			->			Optional[Any]:
								UpperCAmelCase     :		Optional[Any]							     =		self.tokenizer_class.from_pretrained("""microsoft/prophetnet-large-uncased"""    )

								UpperCAmelCase     :		Any							     =		tokenizer.encode("""sequence builders"""		,		add_special_tokens=A    )
								UpperCAmelCase     :		Optional[Any]							     =		tokenizer.encode("""multi-sequence build"""		,		add_special_tokens=A    )

								UpperCAmelCase     :		Tuple							     =		tokenizer.build_inputs_with_special_tokens(A    )
								UpperCAmelCase     :		List[str]							     =		tokenizer.build_inputs_with_special_tokens(A		,		A    )

								assert encoded_sentence == text + [102]
								assert encoded_pair == text + [102] + text_a + [102]






'''simple docstring'''




import unittest

from transformers import AlbertTokenizer, AlbertTokenizerFast
from transformers.testing_utils import get_tests_dir, require_sentencepiece, require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin


a   :			Any					  =    get_tests_dir("""fixtures/spiece.model""")

@require_sentencepiece
@require_tokenizers
class 			UpperCamelCase_ (							__magic_name__      ,     unittest.TestCase			):
	lowercase          = AlbertTokenizer
	lowercase          = AlbertTokenizerFast
	lowercase          = True
	lowercase          = True
	lowercase          = True





	def  _lowercase(  self    )			->			str:
								super().setUp()

								# We have a SentencePiece fixture for testing
								UpperCAmelCase     :		Optional[int]							     =		AlbertTokenizer(A    )
								tokenizer.save_pretrained(self.tmpdirname    )





	def  _lowercase(  self		,		A    )			->			int:
								UpperCAmelCase     :		Optional[int]							     =		"""this is a test"""
								UpperCAmelCase     :		Dict							     =		"""this is a test"""
								return input_text, output_text





	def  _lowercase(  self    )			->			int:
								UpperCAmelCase     :		Tuple							     =		"""<pad>"""
								UpperCAmelCase     :		Optional[int]							     =		0

								self.assertEqual(self.get_tokenizer()._convert_token_to_id(A    )		,		A    )
								self.assertEqual(self.get_tokenizer()._convert_id_to_token(A    )		,		A    )





	def  _lowercase(  self    )			->			Any:
								UpperCAmelCase     :		str							     =		list(self.get_tokenizer().get_vocab().keys()    )

								self.assertEqual(vocab_keys[0]		,		"""<pad>"""    )
								self.assertEqual(vocab_keys[1]		,		"""<unk>"""    )
								self.assertEqual(vocab_keys[-1]		,		"""▁eloquent"""    )
								self.assertEqual(len(A    )		,		30000    )





	def  _lowercase(  self    )			->			Tuple:
								self.assertEqual(self.get_tokenizer().vocab_size		,		30000    )





	def  _lowercase(  self    )			->			Union[str, Any]:
								if not self.test_rust_tokenizer:
															return

								UpperCAmelCase     :		int							     =		self.get_tokenizer()
								UpperCAmelCase     :		List[str]							     =		self.get_rust_tokenizer()

								UpperCAmelCase     :		Optional[Any]							     =		"""I was born in 92000, and this is falsé."""

								UpperCAmelCase     :		str							     =		tokenizer.tokenize(A    )
								UpperCAmelCase     :		Optional[int]							     =		rust_tokenizer.tokenize(A    )
								self.assertListEqual(A		,		A    )

								UpperCAmelCase     :		Any							     =		tokenizer.encode(A		,		add_special_tokens=A    )
								UpperCAmelCase     :		Optional[int]							     =		rust_tokenizer.encode(A		,		add_special_tokens=A    )
								self.assertListEqual(A		,		A    )

								UpperCAmelCase     :		Optional[Any]							     =		self.get_rust_tokenizer()
								UpperCAmelCase     :		Union[str, Any]							     =		tokenizer.encode(A    )
								UpperCAmelCase     :		Optional[int]							     =		rust_tokenizer.encode(A    )
								self.assertListEqual(A		,		A    )





	def  _lowercase(  self    )			->			Any:
								UpperCAmelCase     :		List[Any]							     =		AlbertTokenizer(A		,		keep_accents=A    )

								UpperCAmelCase     :		Optional[int]							     =		tokenizer.tokenize("""This is a test"""    )
								self.assertListEqual(A		,		["""▁this""", """▁is""", """▁a""", """▁test"""]    )

								self.assertListEqual(tokenizer.convert_tokens_to_ids(A    )		,		[48, 25, 21, 1289]    )

								UpperCAmelCase     :		Optional[Any]							     =		tokenizer.tokenize("""I was born in 92000, and this is falsé."""    )
								self.assertListEqual(
								    A		,		["""▁i""", """▁was""", """▁born""", """▁in""", """▁9""", """2000""", """,""", """▁and""", """▁this""", """▁is""", """▁fal""", """s""", """é""", """."""]    )
								UpperCAmelCase     :		str							     =		tokenizer.convert_tokens_to_ids(A    )
								self.assertListEqual(A		,		[31, 23, 386, 19, 561, 3050, 15, 17, 48, 25, 8256, 18, 1, 9]    )

								UpperCAmelCase     :		List[str]							     =		tokenizer.convert_ids_to_tokens(A    )
								self.assertListEqual(
								    A		,		["""▁i""", """▁was""", """▁born""", """▁in""", """▁9""", """2000""", """,""", """▁and""", """▁this""", """▁is""", """▁fal""", """s""", """<unk>""", """."""]		,		)





	def  _lowercase(  self    )			->			Optional[Any]:
								UpperCAmelCase     :		str							     =		AlbertTokenizer(A    )

								UpperCAmelCase     :		Optional[int]							     =		tokenizer.encode("""sequence builders"""    )
								UpperCAmelCase     :		Any							     =		tokenizer.encode("""multi-sequence build"""    )

								UpperCAmelCase     :		Optional[Any]							     =		tokenizer.build_inputs_with_special_tokens(A    )
								UpperCAmelCase     :		List[str]							     =		tokenizer.build_inputs_with_special_tokens(A		,		A    )

								assert encoded_sentence == [tokenizer.cls_token_id] + text + [tokenizer.sep_token_id]
								assert encoded_pair == [tokenizer.cls_token_id] + text + [tokenizer.sep_token_id] + text_a + [
								    tokenizer.sep_token_id
								]






	@slow
	def  _lowercase(  self    )			->			Dict:
								# fmt: off
								UpperCAmelCase     :		Tuple							     =		{"""attention_mask""": [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], """input_ids""": [[2, 21970, 13, 5, 6092, 167, 28, 7103, 2153, 673, 8, 7028, 12051, 18, 17, 7103, 2153, 673, 8, 3515, 18684, 8, 4461, 6, 1927, 297, 8, 12060, 2607, 18, 13, 5, 4461, 15, 10538, 38, 8, 135, 15, 822, 58, 15, 993, 10363, 15, 1460, 8005, 4461, 15, 993, 255, 2328, 9, 9, 9, 6, 26, 1112, 816, 3260, 13, 5, 103, 2377, 6, 17, 1112, 816, 2782, 13, 5, 103, 10641, 6, 29, 84, 2512, 2430, 782, 18684, 2761, 19, 808, 2430, 2556, 17, 855, 1480, 9477, 4091, 128, 11712, 15, 7103, 2153, 673, 17, 24883, 9990, 9, 3], [2, 11502, 25, 1006, 20, 782, 8, 11809, 855, 1732, 19393, 18667, 37, 367, 21018, 69, 1854, 34, 11860, 19124, 27, 156, 225, 17, 193, 4141, 19, 65, 9124, 9, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [2, 14, 2231, 886, 2385, 17659, 84, 14, 16792, 1952, 9, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]}  # noqa: E501
								# fmt: on

								self.tokenizer_integration_test_util(
								    expected_encoding=A		,		model_name="""albert-base-v2"""		,		revision="""6b6560eaf5ff2e250b00c50f380c5389a9c2d82e"""		,		)

