






'''simple docstring'''







import shutil
import tempfile
import unittest

import pytest

from transformers import WhisperTokenizer, is_speech_available
from transformers.testing_utils import require_sentencepiece, require_torch, require_torchaudio

from .test_feature_extraction_whisper import floats_list


if is_speech_available():
			from transformers import WhisperFeatureExtractor, WhisperProcessor


_A      :     Union[str, Any]       	=50_358
_A      :     List[Any]       	=50_362

@require_torch
@require_torchaudio
@require_sentencepiece
class _lowercase      (							unittest.TestCase						):




							def 						lowerCamelCase_							(				self:							Optional[Any]	):
														lowerCamelCase__   :      Tuple			    =			"""openai/whisper-small.en"""
														lowerCamelCase__   :      Any			    =			tempfile.mkdtemp()




							def 						lowerCamelCase_							(				self:							Union[str, Any]     ,				**UpperCamelCase__:							Optional[int]	):
														return WhisperTokenizer.from_pretrained(self.checkpoint     ,				**UpperCamelCase__	)




							def 						lowerCamelCase_							(				self:							int     ,				**UpperCamelCase__:							Optional[int]	):
														return WhisperFeatureExtractor.from_pretrained(self.checkpoint     ,				**UpperCamelCase__	)




							def 						lowerCamelCase_							(				self:							Any	):
														shutil.rmtree(self.tmpdirname	)




							def 						lowerCamelCase_							(				self:							int	):
														lowerCamelCase__   :      Union[str, Any]			    =			self.get_tokenizer()
														lowerCamelCase__   :      Optional[Any]			    =			self.get_feature_extractor()

														lowerCamelCase__   :      Any			    =			WhisperProcessor(tokenizer=UpperCamelCase__     ,				feature_extractor=UpperCamelCase__	)

														processor.save_pretrained(self.tmpdirname	)
														lowerCamelCase__   :      str			    =			WhisperProcessor.from_pretrained(self.tmpdirname	)

														self.assertEqual(processor.tokenizer.get_vocab()     ,				tokenizer.get_vocab()	)
														self.assertIsInstance(processor.tokenizer     ,				UpperCamelCase__	)

														self.assertEqual(processor.feature_extractor.to_json_string()     ,				feature_extractor.to_json_string()	)
														self.assertIsInstance(processor.feature_extractor     ,				UpperCamelCase__	)




							def 						lowerCamelCase_							(				self:							Optional[Any]	):
														lowerCamelCase__   :      Any			    =			WhisperProcessor(tokenizer=self.get_tokenizer()     ,				feature_extractor=self.get_feature_extractor()	)
														processor.save_pretrained(self.tmpdirname	)

														lowerCamelCase__   :      Any			    =			self.get_tokenizer(bos_token="""(BOS)"""     ,				eos_token="""(EOS)"""	)
														lowerCamelCase__   :      int			    =			self.get_feature_extractor(do_normalize=UpperCamelCase__     ,				padding_value=1.0	)

														lowerCamelCase__   :      Optional[Any]			    =			WhisperProcessor.from_pretrained(
														    self.tmpdirname     ,				bos_token="""(BOS)"""     ,				eos_token="""(EOS)"""     ,				do_normalize=UpperCamelCase__     ,				padding_value=1.0	)

														self.assertEqual(processor.tokenizer.get_vocab()     ,				tokenizer_add_kwargs.get_vocab()	)
														self.assertIsInstance(processor.tokenizer     ,				UpperCamelCase__	)

														self.assertEqual(processor.feature_extractor.to_json_string()     ,				feature_extractor_add_kwargs.to_json_string()	)
														self.assertIsInstance(processor.feature_extractor     ,				UpperCamelCase__	)




							def 						lowerCamelCase_							(				self:							Optional[int]	):
														lowerCamelCase__   :      List[str]			    =			self.get_feature_extractor()
														lowerCamelCase__   :      Optional[Any]			    =			self.get_tokenizer()

														lowerCamelCase__   :      Dict			    =			WhisperProcessor(tokenizer=UpperCamelCase__     ,				feature_extractor=UpperCamelCase__	)

														lowerCamelCase__   :      List[Any]			    =			floats_list((3, 1_000)	)

														lowerCamelCase__   :      List[Any]			    =			feature_extractor(UpperCamelCase__     ,				return_tensors="""np"""	)
														lowerCamelCase__   :      Tuple			    =			processor(UpperCamelCase__     ,				return_tensors="""np"""	)

														for key in input_feat_extract.keys():
																					self.assertAlmostEqual(input_feat_extract[key].sum()     ,				input_processor[key].sum()     ,				delta=1e-2	)




							def 						lowerCamelCase_							(				self:							Optional[int]	):
														lowerCamelCase__   :      Optional[Any]			    =			self.get_feature_extractor()
														lowerCamelCase__   :      Tuple			    =			self.get_tokenizer()

														lowerCamelCase__   :      Any			    =			WhisperProcessor(tokenizer=UpperCamelCase__     ,				feature_extractor=UpperCamelCase__	)

														lowerCamelCase__   :      List[str]			    =			"""This is a test string"""

														lowerCamelCase__   :      Optional[int]			    =			processor(text=UpperCamelCase__	)

														lowerCamelCase__   :      Optional[Any]			    =			tokenizer(UpperCamelCase__	)

														for key in encoded_tok.keys():
																					self.assertListEqual(encoded_tok[key]     ,				encoded_processor[key]	)




							def 						lowerCamelCase_							(				self:							Dict	):
														lowerCamelCase__   :      Optional[int]			    =			self.get_feature_extractor()
														lowerCamelCase__   :      List[Any]			    =			self.get_tokenizer()

														lowerCamelCase__   :      List[Any]			    =			WhisperProcessor(tokenizer=UpperCamelCase__     ,				feature_extractor=UpperCamelCase__	)

														lowerCamelCase__   :      Tuple			    =			[[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

														lowerCamelCase__   :      Tuple			    =			processor.batch_decode(UpperCamelCase__	)
														lowerCamelCase__   :      List[str]			    =			tokenizer.batch_decode(UpperCamelCase__	)

														self.assertListEqual(UpperCamelCase__     ,				UpperCamelCase__	)




							def 						lowerCamelCase_							(				self:							List[Any]	):
														lowerCamelCase__   :      Dict			    =			self.get_feature_extractor()
														lowerCamelCase__   :      Tuple			    =			self.get_tokenizer()

														lowerCamelCase__   :      Dict			    =			WhisperProcessor(tokenizer=UpperCamelCase__     ,				feature_extractor=UpperCamelCase__	)

														self.assertListEqual(
														    processor.model_input_names     ,				feature_extractor.model_input_names     ,				msg="""`processor` and `feature_extractor` model input names do not match"""     ,				)




							def 						lowerCamelCase_							(				self:							Optional[int]	):
														lowerCamelCase__   :      Union[str, Any]			    =			self.get_feature_extractor()
														lowerCamelCase__   :      int			    =			self.get_tokenizer()

														lowerCamelCase__   :      List[Any]			    =			WhisperProcessor(tokenizer=UpperCamelCase__     ,				feature_extractor=UpperCamelCase__	)
														lowerCamelCase__   :      List[Any]			    =			processor.get_decoder_prompt_ids(task="""transcribe"""     ,				no_timestamps=UpperCamelCase__	)

														self.assertIsInstance(UpperCamelCase__     ,				UpperCamelCase__	)
														for ids in forced_decoder_ids:
																					self.assertIsInstance(UpperCamelCase__     ,				(list, tuple)	)

														lowerCamelCase__   :      Any			    =			[TRANSCRIBE, NOTIMESTAMPS]
														self.assertListEqual([ids[-1] for ids in forced_decoder_ids]     ,				UpperCamelCase__	)




							def 						lowerCamelCase_							(				self:							Dict	):
														lowerCamelCase__   :      Any			    =			WhisperProcessor(tokenizer=self.get_tokenizer()     ,				feature_extractor=self.get_feature_extractor()	)
														lowerCamelCase__   :      Tuple			    =			processor.get_prompt_ids("""Mr. Quilter"""	)
														lowerCamelCase__   :      Tuple			    =			processor.tokenizer.decode(UpperCamelCase__	)

														self.assertListEqual(prompt_ids.tolist()     ,				[50_360, 1_770, 13, 2_264, 346, 353]	)
														self.assertEqual(UpperCamelCase__     ,				"""<|startofprev|> Mr. Quilter"""	)




							def 						lowerCamelCase_							(				self:							Any	):
														lowerCamelCase__   :      Dict			    =			WhisperProcessor(tokenizer=self.get_tokenizer()     ,				feature_extractor=self.get_feature_extractor()	)
														lowerCamelCase__   :      Optional[int]			    =			processor.get_prompt_ids(""""""	)
														lowerCamelCase__   :      str			    =			processor.tokenizer.decode(UpperCamelCase__	)

														self.assertListEqual(prompt_ids.tolist()     ,				[50_360, 220]	)
														self.assertEqual(UpperCamelCase__     ,				"""<|startofprev|> """	)




							def 						lowerCamelCase_							(				self:							Optional[int]	):
														lowerCamelCase__   :      List[Any]			    =			WhisperProcessor(tokenizer=self.get_tokenizer()     ,				feature_extractor=self.get_feature_extractor()	)

														def _test_prompt_error_raised_helper(UpperCamelCase__:							Optional[Any]     ,				UpperCamelCase__:							Any	):
																					with pytest.raises(UpperCamelCase__	) as excinfo:
																												processor.get_prompt_ids(UpperCamelCase__	)
																					lowerCamelCase__   :      Union[str, Any]			    =			F'''Encountered text in the prompt corresponding to disallowed special token: {special_token}.'''
																					self.assertEqual(UpperCamelCase__     ,				str(excinfo.value	)	)

														_test_prompt_error_raised_helper("""<|startofprev|> test"""     ,				"""<|startofprev|>"""	)
														_test_prompt_error_raised_helper("""test <|notimestamps|>"""     ,				"""<|notimestamps|>"""	)
														_test_prompt_error_raised_helper("""test <|zh|> test <|transcribe|>"""     ,				"""<|zh|>"""	)









'''simple docstring'''







from ...configuration_utils import PretrainedConfig
from ...utils import logging


_A      :     Union[str, Any]       	=logging.get_logger(__name__)

_A      :     Tuple       	={
    '''tau/splinter-base''': '''https://huggingface.co/tau/splinter-base/resolve/main/config.json''',
    '''tau/splinter-base-qass''': '''https://huggingface.co/tau/splinter-base-qass/resolve/main/config.json''',
    '''tau/splinter-large''': '''https://huggingface.co/tau/splinter-large/resolve/main/config.json''',
    '''tau/splinter-large-qass''': '''https://huggingface.co/tau/splinter-large-qass/resolve/main/config.json''',
    # See all Splinter models at https://huggingface.co/models?filter=splinter
}

class _lowercase      (							_lowercase						):
							a							 =			"""splinter"""




							def __init__(				self:							List[str]     ,				UpperCamelCase__:							List[Any]=30_522     ,				UpperCamelCase__:							Union[str, Any]=768     ,				UpperCamelCase__:							str=12     ,				UpperCamelCase__:							Dict=12     ,				UpperCamelCase__:							Tuple=3_072     ,				UpperCamelCase__:							Optional[int]="gelu"     ,				UpperCamelCase__:							Optional[int]=0.1     ,				UpperCamelCase__:							str=0.1     ,				UpperCamelCase__:							List[Any]=512     ,				UpperCamelCase__:							List[str]=2     ,				UpperCamelCase__:							Any=0.02     ,				UpperCamelCase__:							Optional[Any]=1e-12     ,				UpperCamelCase__:							Dict=True     ,				UpperCamelCase__:							str=0     ,				UpperCamelCase__:							int=104     ,				**UpperCamelCase__:							Any     ,				):
														super().__init__(pad_token_id=UpperCamelCase__     ,				**UpperCamelCase__	)

														lowerCamelCase__   :      Union[str, Any]			    =			vocab_size
														lowerCamelCase__   :      str			    =			max_position_embeddings
														lowerCamelCase__   :      Tuple			    =			hidden_size
														lowerCamelCase__   :      Dict			    =			num_hidden_layers
														lowerCamelCase__   :      Tuple			    =			num_attention_heads
														lowerCamelCase__   :      Tuple			    =			intermediate_size
														lowerCamelCase__   :      Any			    =			hidden_act
														lowerCamelCase__   :      int			    =			hidden_dropout_prob
														lowerCamelCase__   :      List[str]			    =			attention_probs_dropout_prob
														lowerCamelCase__   :      Dict			    =			initializer_range
														lowerCamelCase__   :      List[Any]			    =			type_vocab_size
														lowerCamelCase__   :      Tuple			    =			layer_norm_eps
														lowerCamelCase__   :      Optional[Any]			    =			use_cache
														lowerCamelCase__   :      Optional[Any]			    =			question_token_id

