





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 						lowerCamelCase       (__lowerCamelCase							,     unittest.TestCase      ):







							"""simple docstring"""




							UpperCAmelCase_      						=   ProphetNetTokenizer
							UpperCAmelCase_      						=   False






							def  A_     ( self     :					List[str]						)				->			Optional[Any]:





														"""simple docstring"""
														super().setUp()

														SCREAMING_SNAKE_CASE__       :      Any     =						[
														    "[UNK]",
														    "[CLS]",
														    "[SEP]",
														    "[PAD]",
														    "[MASK]",
														    "want",
														    "##want",
														    "##ed",
														    "wa",
														    "un",
														    "runn",
														    "##ing",
														    ",",
														    "low",
														    "lowest",
														]
														SCREAMING_SNAKE_CASE__       :      str     =						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  A_     ( self     :					int,			_UpperCAmelCase     :					List[str]						)				->			List[Any]:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      List[Any]     =						"UNwant\u00E9d,running"
														SCREAMING_SNAKE_CASE__       :      Dict     =						"unwanted, running"
														return input_text, output_text






							def  A_     ( self     :					str						)				->			List[str]:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						self.tokenizer_class(self.vocab_file						)

														SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						tokenizer.tokenize("UNwant\u00E9d,running"						)
														self.assertListEqual(_UpperCAmelCase,			["un", "##want", "##ed", ",", "runn", "##ing"]						)
														self.assertListEqual(tokenizer.convert_tokens_to_ids(_UpperCAmelCase						),			[9, 6, 7, 1_2, 1_0, 1_1]						)






							def  A_     ( self     :					int						)				->			Optional[Any]:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      Dict     =						BasicTokenizer()

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






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





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      int     =						BasicTokenizer(do_lower_case=_UpperCAmelCase						)

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






							def  A_     ( self     :					Any						)				->			int:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						BasicTokenizer(do_lower_case=_UpperCAmelCase,			strip_accents=_UpperCAmelCase						)

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






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





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      List[Any]     =						BasicTokenizer(do_lower_case=_UpperCAmelCase,			strip_accents=_UpperCAmelCase						)

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






							def  A_     ( self     :					List[Any]						)				->			List[str]:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      str     =						BasicTokenizer(do_lower_case=_UpperCAmelCase						)

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






							def  A_     ( self     :					Optional[int]						)				->			List[str]:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      Optional[int]     =						BasicTokenizer(do_lower_case=_UpperCAmelCase						)

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






							def  A_     ( self     :					Optional[int]						)				->			Tuple:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      Any     =						BasicTokenizer(do_lower_case=_UpperCAmelCase,			strip_accents=_UpperCAmelCase						)

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






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





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      int     =						BasicTokenizer(do_lower_case=_UpperCAmelCase,			strip_accents=_UpperCAmelCase						)

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






							def  A_     ( self     :					List[str]						)				->			Dict:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      Any     =						BasicTokenizer(do_lower_case=_UpperCAmelCase,			never_split=["[UNK]"]						)

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






							def  A_     ( self     :					Dict						)				->			Any:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      Optional[int]     =						["[UNK]", "[CLS]", "[SEP]", "want", "##want", "##ed", "wa", "un", "runn", "##ing"]

														SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						{}
														for i, token in enumerate(_UpperCAmelCase						):
																					SCREAMING_SNAKE_CASE__       :      Dict     =						i
														SCREAMING_SNAKE_CASE__       :      Dict     =						WordpieceTokenizer(vocab=_UpperCAmelCase,			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  A_     ( self     :					List[Any]						)				->			Tuple:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						self.tokenizer_class.from_pretrained("microsoft/prophetnet-large-uncased"						)

														SCREAMING_SNAKE_CASE__       :      str     =						["A long paragraph for summarization.", "Another paragraph for summarization."]
														SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						[1_0_3_7, 2_1_4_6, 2_0_4_2_3, 2_0_0_5, 7_6_8_0, 7_8_4_9, 3_9_8_9, 1_0_1_2, 1_0_2]
														SCREAMING_SNAKE_CASE__       :      int     =						tokenizer(_UpperCAmelCase,			padding=_UpperCAmelCase,			return_tensors="pt"						)
														self.assertIsInstance(_UpperCAmelCase,			_UpperCAmelCase						)
														SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						list(batch.input_ids.numpy()[0]						)
														self.assertListEqual(_UpperCAmelCase,			_UpperCAmelCase						)

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






							def  A_     ( self     :					List[Any]						)				->			Any:





														"""simple docstring"""
														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  A_     ( self     :					List[Any]						)				->			List[str]:





														"""simple docstring"""
														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  A_     ( self     :					Optional[int]						)				->			Optional[int]:





														"""simple docstring"""
														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  A_     ( self     :					Optional[Any]						)				->			List[Any]:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      str     =						self.tokenizer_class.from_pretrained("microsoft/prophetnet-large-uncased"						)

														SCREAMING_SNAKE_CASE__       :      Tuple     =						tokenizer.encode("sequence builders",			add_special_tokens=_UpperCAmelCase						)
														SCREAMING_SNAKE_CASE__       :      List[str]     =						tokenizer.encode("multi-sequence build",			add_special_tokens=_UpperCAmelCase						)

														SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						tokenizer.build_inputs_with_special_tokens(_UpperCAmelCase						)
														SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						tokenizer.build_inputs_with_special_tokens(_UpperCAmelCase,			_UpperCAmelCase						)

														assert encoded_sentence == text + [1_0_2]
														assert encoded_pair == text + [1_0_2] + text_a + [1_0_2]













from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


_lowerCamelCase :    Union[str, Any]  							= {
    '''configuration_bigbird_pegasus''': [
        '''BIGBIRD_PEGASUS_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''BigBirdPegasusConfig''',
        '''BigBirdPegasusOnnxConfig''',
    ],
}

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		_lowerCamelCase :    int  							= [
		    '''BIGBIRD_PEGASUS_PRETRAINED_MODEL_ARCHIVE_LIST''',
		    '''BigBirdPegasusForCausalLM''',
		    '''BigBirdPegasusForConditionalGeneration''',
		    '''BigBirdPegasusForQuestionAnswering''',
		    '''BigBirdPegasusForSequenceClassification''',
		    '''BigBirdPegasusModel''',
		    '''BigBirdPegasusPreTrainedModel''',
		]


if TYPE_CHECKING:
		from .configuration_bigbird_pegasus import (
		    BIGBIRD_PEGASUS_PRETRAINED_CONFIG_ARCHIVE_MAP,
		    BigBirdPegasusConfig,
		    BigBirdPegasusOnnxConfig,
		)

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_bigbird_pegasus import (
				    BIGBIRD_PEGASUS_PRETRAINED_MODEL_ARCHIVE_LIST,
				    BigBirdPegasusForCausalLM,
				    BigBirdPegasusForConditionalGeneration,
				    BigBirdPegasusForQuestionAnswering,
				    BigBirdPegasusForSequenceClassification,
				    BigBirdPegasusModel,
				    BigBirdPegasusPreTrainedModel,
				)


else:
		import sys

		_lowerCamelCase :    Optional[Any]  							= _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)






