





import unittest

from datasets import load_dataset

from transformers import BloomTokenizerFast
from transformers.testing_utils import require_tokenizers

from ...test_tokenization_common import TokenizerTesterMixin



@require_tokenizers
class    _a     (				lowercase__					,							unittest.TestCase							):






							"""simple docstring"""

							snake_case_							 =						None
							snake_case_							 =						BloomTokenizerFast
							snake_case_							 =						BloomTokenizerFast
							snake_case_							 =						True
							snake_case_							 =						False
							snake_case_							 =						"tokenizer_file"
							snake_case_							 =						{"bos_token": "<s>", "eos_token": "</s>", "unk_token": "<unk>", "pad_token": "<pad>"}

							def      A_  (      self				:     Tuple    )	->List[str]:
													super().setUp()
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					BloomTokenizerFast.from_pretrained("bigscience/tokenizer"    )
													tokenizer.save_pretrained(self.tmpdirname    )

							def      A_  (      self				:     str							,	**a				:     Dict    )	->int:
													kwargs.update(self.special_tokens_map    )
													return BloomTokenizerFast.from_pretrained(self.tmpdirname							,	**a    )

							def      A_  (      self				:     int    )	->Union[str, Any]:
													SCREAMING_SNAKE_CASE__     :				int   =					self.get_rust_tokenizer()

													SCREAMING_SNAKE_CASE__     :				List[str]   =					["The quick brown fox</s>", "jumps over the lazy dog</s>"]
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					[[21_75, 2_37_14, 7_31_73, 14_42_52, 2], [77, 13_26_19, 34_78, 3_68, 10_95_86, 3_54_33, 2]]

													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					tokenizer.batch_encode_plus(a    )["input_ids"]
													self.assertListEqual(a							,	a    )

													SCREAMING_SNAKE_CASE__     :				List[Any]   =					tokenizer.batch_decode(a    )
													self.assertListEqual(a							,	a    )

							def      A_  (      self				:     Dict							,	a				:     List[str]=6    )	->str:
													for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
																			with self.subTest(f"""{tokenizer.__class__.__name__} ({pretrained_name})"""    ):
																									SCREAMING_SNAKE_CASE__     :				List[Any]   =					self.rust_tokenizer_class.from_pretrained(a							,	**a    )
																									# tokenizer_r.pad_token = None # Hotfixing padding = None
																									# Simple input
																									SCREAMING_SNAKE_CASE__     :				Dict   =					"This is a simple input"
																									SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					["This is a simple input 1", "This is a simple input 2"]
																									SCREAMING_SNAKE_CASE__     :				List[str]   =					("This is a simple input", "This is a pair")
																									SCREAMING_SNAKE_CASE__     :				Any   =					[
																									    ("This is a simple input 1", "This is a simple input 2"),
																									    ("This is a simple pair 1", "This is a simple pair 2"),
																									]

																									# Simple input tests
																									try:
																															tokenizer_r.encode(a							,	max_length=a    )
																															tokenizer_r.encode_plus(a							,	max_length=a    )

																															tokenizer_r.batch_encode_plus(a							,	max_length=a    )
																															tokenizer_r.encode(a							,	max_length=a    )
																															tokenizer_r.batch_encode_plus(a							,	max_length=a    )
																									except ValueError:
																															self.fail("Bloom Tokenizer should be able to deal with padding"    )

																									SCREAMING_SNAKE_CASE__     :				str   =					None  # Hotfixing padding = None
																									self.assertRaises(a							,	tokenizer_r.encode							,	a							,	max_length=a							,	padding="max_length"    )

																									# Simple input
																									self.assertRaises(a							,	tokenizer_r.encode_plus							,	a							,	max_length=a							,	padding="max_length"    )

																									# Simple input
																									self.assertRaises(
																									    a							,	tokenizer_r.batch_encode_plus							,	a							,	max_length=a							,	padding="max_length"							,	)

																									# Pair input
																									self.assertRaises(a							,	tokenizer_r.encode							,	a							,	max_length=a							,	padding="max_length"    )

																									# Pair input
																									self.assertRaises(a							,	tokenizer_r.encode_plus							,	a							,	max_length=a							,	padding="max_length"    )

																									# Pair input
																									self.assertRaises(
																									    a							,	tokenizer_r.batch_encode_plus							,	a							,	max_length=a							,	padding="max_length"							,	)

							def      A_  (      self				:     Any    )	->List[str]:
													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					self.get_rust_tokenizer()
													SCREAMING_SNAKE_CASE__     :				List[str]   =					load_dataset("xnli"							,	"all_languages"							,	split="test"							,	streaming=a    )

													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					next(iter(a    )    )["premise"]  # pick up one data
													SCREAMING_SNAKE_CASE__     :				Any   =					list(sample_data.values()    )

													SCREAMING_SNAKE_CASE__     :				List[str]   =					list(map(tokenizer.encode							,	a    )    )
													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					[tokenizer.decode(a							,	clean_up_tokenization_spaces=a    ) for x in output_tokens]
													self.assertListEqual(a							,	a    )






							def      A_  (      self				:     Union[str, Any]    )	->str:
													# The test has to be overriden because BLOOM uses ALiBi positional embeddings that does not have
													# any sequence length constraints. This test of the parent class will fail since it relies on the
													# maximum sequence length of the positoonal embeddings.
													self.assertGreaterEqual(len(self.tokenizer_class.pretrained_vocab_files_map    )							,	1    )
													self.assertGreaterEqual(len(list(self.tokenizer_class.pretrained_vocab_files_map.values()    )[0]    )							,	1    )






import unittest

from datasets import load_dataset

from transformers.pipelines import pipeline
from transformers.testing_utils import is_pipeline_test, nested_simplify, require_torch, slow



@is_pipeline_test
@require_torch
class    _a     (				unittest.TestCase							):






							"""simple docstring"""

							@require_torch
							def      A_  (      self				:     Dict    )	->str:
													SCREAMING_SNAKE_CASE__     :				Any   =					pipeline(
													    task="zero-shot-audio-classification"							,	model="hf-internal-testing/tiny-clap-htsat-unfused"    )
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					load_dataset("ashraq/esc50"    )
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					dataset["train"]["audio"][-1]["array"]
													SCREAMING_SNAKE_CASE__     :				int   =					audio_classifier(a							,	candidate_labels=["Sound of a dog", "Sound of vaccum cleaner"]    )
													self.assertEqual(
													    nested_simplify(a    )							,	[{"score": 0.501, "label": "Sound of a dog"}, {"score": 0.499, "label": "Sound of vaccum cleaner"}]							,	)

							@unittest.skip("No models are available in TF"    )
							def      A_  (      self				:     int    )	->Union[str, Any]:
													pass

							@slow
							@require_torch
							def      A_  (      self				:     int    )	->str:
													SCREAMING_SNAKE_CASE__     :				List[str]   =					pipeline(
													    task="zero-shot-audio-classification"							,	model="laion/clap-htsat-unfused"							,	)
													# This is an audio of a dog
													SCREAMING_SNAKE_CASE__     :				int   =					load_dataset("ashraq/esc50"    )
													SCREAMING_SNAKE_CASE__     :				str   =					dataset["train"]["audio"][-1]["array"]
													SCREAMING_SNAKE_CASE__     :				List[Any]   =					audio_classifier(a							,	candidate_labels=["Sound of a dog", "Sound of vaccum cleaner"]    )

													self.assertEqual(
													    nested_simplify(a    )							,	[
													        {"score": 0.999, "label": "Sound of a dog"},
													        {"score": 0.001, "label": "Sound of vaccum cleaner"},
													    ]							,	)

													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					audio_classifier([audio] * 5							,	candidate_labels=["Sound of a dog", "Sound of vaccum cleaner"]    )
													self.assertEqual(
													    nested_simplify(a    )							,	[
													        [
													            {"score": 0.999, "label": "Sound of a dog"},
													            {"score": 0.001, "label": "Sound of vaccum cleaner"},
													        ],
													    ]
													    * 5							,	)
													SCREAMING_SNAKE_CASE__     :				int   =					audio_classifier(
													    [audio] * 5							,	candidate_labels=["Sound of a dog", "Sound of vaccum cleaner"]							,	batch_size=5    )
													self.assertEqual(
													    nested_simplify(a    )							,	[
													        [
													            {"score": 0.999, "label": "Sound of a dog"},
													            {"score": 0.001, "label": "Sound of vaccum cleaner"},
													        ],
													    ]
													    * 5							,	)






							@unittest.skip("No models are available in TF"    )
							def      A_  (      self				:     Optional[int]    )	->Union[str, Any]:
													pass