code: 
  
  
  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
  
  
  UpperCAmelCase      :						Optional[int]    =		5_03_58
  UpperCAmelCase      :						List[str]    =		5_03_62
  
  
  
  
  
  
  
  @require_torch
  @require_torchaudio
  @require_sentencepiece
  class 					__lowercase					(       unittest.TestCase     ):
  
  
  
  		"""simple docstring"""
  
  		def 				__A      (   self  )     ->   Optional[int]:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					lowerCamelCase								=     """openai/whisper-small.en"""
  					lowerCamelCase								=     tempfile.mkdtemp()
  
  
  
  
  
  
  
  		def 				__A      (   self		,			**A  )     ->   List[Any]:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					return WhisperTokenizer.from_pretrained(self.checkpoint		,			**__SCREAMING_SNAKE_CASE  )
  
  
  
  
  
  
  
  		def 				__A      (   self		,			**A  )     ->   Any:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					return WhisperFeatureExtractor.from_pretrained(self.checkpoint		,			**__SCREAMING_SNAKE_CASE  )
  
  
  
  
  
  
  
  		def 				__A      (   self  )     ->   Any:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					shutil.rmtree(self.tmpdirname  )
  
  
  
  
  
  
  
  		def 				__A      (   self  )     ->   str:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					lowerCamelCase								=     self.get_tokenizer()
  					lowerCamelCase								=     self.get_feature_extractor()
  
  					lowerCamelCase								=     WhisperProcessor(tokenizer=__SCREAMING_SNAKE_CASE		,			feature_extractor=__SCREAMING_SNAKE_CASE  )
  
  					processor.save_pretrained(self.tmpdirname  )
  					lowerCamelCase								=     WhisperProcessor.from_pretrained(self.tmpdirname  )
  
  					self.assertEqual(processor.tokenizer.get_vocab()		,			tokenizer.get_vocab()  )
  					self.assertIsInstance(processor.tokenizer		,			__SCREAMING_SNAKE_CASE  )
  
  					self.assertEqual(processor.feature_extractor.to_json_string()		,			feature_extractor.to_json_string()  )
  					self.assertIsInstance(processor.feature_extractor		,			__SCREAMING_SNAKE_CASE  )
  
  
  
  
  
  
  
  		def 				__A      (   self  )     ->   Any:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					lowerCamelCase								=     WhisperProcessor(tokenizer=self.get_tokenizer()		,			feature_extractor=self.get_feature_extractor()  )
  					processor.save_pretrained(self.tmpdirname  )
  
  					lowerCamelCase								=     self.get_tokenizer(bos_token="""(BOS)"""		,			eos_token="""(EOS)"""  )
  					lowerCamelCase								=     self.get_feature_extractor(do_normalize=__SCREAMING_SNAKE_CASE		,			padding_value=1.0  )
  
  					lowerCamelCase								=     WhisperProcessor.from_pretrained(
  					    self.tmpdirname		,			bos_token="""(BOS)"""		,			eos_token="""(EOS)"""		,			do_normalize=__SCREAMING_SNAKE_CASE		,			padding_value=1.0  )
  
  					self.assertEqual(processor.tokenizer.get_vocab()		,			tokenizer_add_kwargs.get_vocab()  )
  					self.assertIsInstance(processor.tokenizer		,			__SCREAMING_SNAKE_CASE  )
  
  					self.assertEqual(processor.feature_extractor.to_json_string()		,			feature_extractor_add_kwargs.to_json_string()  )
  					self.assertIsInstance(processor.feature_extractor		,			__SCREAMING_SNAKE_CASE  )
  
  
  
  
  
  
  
  		def 				__A      (   self  )     ->   Tuple:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					lowerCamelCase								=     self.get_feature_extractor()
  					lowerCamelCase								=     self.get_tokenizer()
  
  					lowerCamelCase								=     WhisperProcessor(tokenizer=__SCREAMING_SNAKE_CASE		,			feature_extractor=__SCREAMING_SNAKE_CASE  )
  
  					lowerCamelCase								=     floats_list((3, 10_00)  )
  
  					lowerCamelCase								=     feature_extractor(__SCREAMING_SNAKE_CASE		,			return_tensors="""np"""  )
  					lowerCamelCase								=     processor(__SCREAMING_SNAKE_CASE		,			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 				__A      (   self  )     ->   Optional[int]:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					lowerCamelCase								=     self.get_feature_extractor()
  					lowerCamelCase								=     self.get_tokenizer()
  
  					lowerCamelCase								=     WhisperProcessor(tokenizer=__SCREAMING_SNAKE_CASE		,			feature_extractor=__SCREAMING_SNAKE_CASE  )
  
  					lowerCamelCase								=     """This is a test string"""
  
  					lowerCamelCase								=     processor(text=__SCREAMING_SNAKE_CASE  )
  
  					lowerCamelCase								=     tokenizer(__SCREAMING_SNAKE_CASE  )
  
  					for key in encoded_tok.keys():
  								self.assertListEqual(encoded_tok[key]		,			encoded_processor[key]  )
  
  
  
  
  
  
  
  		def 				__A      (   self  )     ->   Optional[int]:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					lowerCamelCase								=     self.get_feature_extractor()
  					lowerCamelCase								=     self.get_tokenizer()
  
  					lowerCamelCase								=     WhisperProcessor(tokenizer=__SCREAMING_SNAKE_CASE		,			feature_extractor=__SCREAMING_SNAKE_CASE  )
  
  					lowerCamelCase								=     [[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]
  
  					lowerCamelCase								=     processor.batch_decode(__SCREAMING_SNAKE_CASE  )
  					lowerCamelCase								=     tokenizer.batch_decode(__SCREAMING_SNAKE_CASE  )
  
  					self.assertListEqual(__SCREAMING_SNAKE_CASE		,			__SCREAMING_SNAKE_CASE  )
  
  
  
  
  
  
  
  		def 				__A      (   self  )     ->   Optional[Any]:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					lowerCamelCase								=     self.get_feature_extractor()
  					lowerCamelCase								=     self.get_tokenizer()
  
  					lowerCamelCase								=     WhisperProcessor(tokenizer=__SCREAMING_SNAKE_CASE		,			feature_extractor=__SCREAMING_SNAKE_CASE  )
  
  					self.assertListEqual(
  					    processor.model_input_names		,			feature_extractor.model_input_names		,			msg="""`processor` and `feature_extractor` model input names do not match"""		,			)
  
  
  
  
  
  
  
  		def 				__A      (   self  )     ->   int:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					lowerCamelCase								=     self.get_feature_extractor()
  					lowerCamelCase								=     self.get_tokenizer()
  
  					lowerCamelCase								=     WhisperProcessor(tokenizer=__SCREAMING_SNAKE_CASE		,			feature_extractor=__SCREAMING_SNAKE_CASE  )
  					lowerCamelCase								=     processor.get_decoder_prompt_ids(task="""transcribe"""		,			no_timestamps=__SCREAMING_SNAKE_CASE  )
  
  					self.assertIsInstance(__SCREAMING_SNAKE_CASE		,			__SCREAMING_SNAKE_CASE  )
  					for ids in forced_decoder_ids:
  								self.assertIsInstance(__SCREAMING_SNAKE_CASE		,			(list, tuple)  )
  
  					lowerCamelCase								=     [TRANSCRIBE, NOTIMESTAMPS]
  					self.assertListEqual([ids[-1] for ids in forced_decoder_ids]		,			__SCREAMING_SNAKE_CASE  )
  
  
  
  
  
  
  
  		def 				__A      (   self  )     ->   Optional[Any]:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					lowerCamelCase								=     WhisperProcessor(tokenizer=self.get_tokenizer()		,			feature_extractor=self.get_feature_extractor()  )
  					lowerCamelCase								=     processor.get_prompt_ids("""Mr. Quilter"""  )
  					lowerCamelCase								=     processor.tokenizer.decode(__SCREAMING_SNAKE_CASE  )
  
  					self.assertListEqual(prompt_ids.tolist()		,			[5_03_60, 17_70, 13, 22_64, 3_46, 3_53]  )
  					self.assertEqual(__SCREAMING_SNAKE_CASE		,			"""<|startofprev|> Mr. Quilter"""  )
  
  
  
  
  
  
  
  		def 				__A      (   self  )     ->   List[Any]:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					lowerCamelCase								=     WhisperProcessor(tokenizer=self.get_tokenizer()		,			feature_extractor=self.get_feature_extractor()  )
  					lowerCamelCase								=     processor.get_prompt_ids(""""""  )
  					lowerCamelCase								=     processor.tokenizer.decode(__SCREAMING_SNAKE_CASE  )
  
  					self.assertListEqual(prompt_ids.tolist()		,			[5_03_60, 2_20]  )
  					self.assertEqual(__SCREAMING_SNAKE_CASE		,			"""<|startofprev|> """  )
  
  
  
  
  
  
  
  		def 				__A      (   self  )     ->   List[str]:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					lowerCamelCase								=     WhisperProcessor(tokenizer=self.get_tokenizer()		,			feature_extractor=self.get_feature_extractor()  )
  
  					def _test_prompt_error_raised_helper(A		,			A  ):
  								with pytest.raises(__SCREAMING_SNAKE_CASE  ) as excinfo:
  											processor.get_prompt_ids(__SCREAMING_SNAKE_CASE  )
  								lowerCamelCase								=     F'Encountered text in the prompt corresponding to disallowed special token: {special_token}.'
  								self.assertEqual(__SCREAMING_SNAKE_CASE		,			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|>"""  )
  
  
style_context: 
  
  
  import unittest
  
  from cer import CER
  
  
  UpperCAmelCase      :						Union[str, Any]    =		CER()
  
  
  
  
  
  
  
  class 					__lowercase					(       unittest.TestCase     ):
  
  
  
  		"""simple docstring"""
  
  		def 				__A      (   self  )     ->   Optional[int]:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					lowerCamelCase								=     ["""White House"""]
  					lowerCamelCase								=     ["""white house"""]
  					# S = 2, D = 0, I = 0, N = 11, CER = 2 / 11
  					lowerCamelCase								=     cer.compute(predictions=A		,			references=A  )
  					self.assertTrue(abs(char_error_rate - 0.1818181818  ) < 1e-6  )
  
  
  
  
  
  
  
  		def 				__A      (   self  )     ->   List[str]:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					lowerCamelCase								=     ["""were wolf"""]
  					lowerCamelCase								=     ["""werewolf"""]
  					# S = 0, D = 0, I = 1, N = 9, CER = 1 / 9
  					lowerCamelCase								=     cer.compute(predictions=A		,			references=A  )
  					self.assertTrue(abs(char_error_rate - 0.1111111  ) < 1e-6  )
  
  					lowerCamelCase								=     ["""werewolf"""]
  					lowerCamelCase								=     ["""weae     wolf"""]
  					# S = 1, D = 1, I = 0, N = 8, CER = 0.25
  					lowerCamelCase								=     cer.compute(predictions=A		,			references=A  )
  					self.assertTrue(abs(char_error_rate - 0.25  ) < 1e-6  )
  
  					# consecutive whitespaces case 1
  					lowerCamelCase								=     ["""were wolf"""]
  					lowerCamelCase								=     ["""were               wolf"""]
  					# S = 0, D = 0, I = 0, N = 9, CER = 0
  					lowerCamelCase								=     cer.compute(predictions=A		,			references=A  )
  					self.assertTrue(abs(char_error_rate - 0.0  ) < 1e-6  )
  
  					# consecutive whitespaces case 2
  					lowerCamelCase								=     ["""were   wolf"""]
  					lowerCamelCase								=     ["""were               wolf"""]
  					# S = 0, D = 0, I = 0, N = 9, CER = 0
  					lowerCamelCase								=     cer.compute(predictions=A		,			references=A  )
  					self.assertTrue(abs(char_error_rate - 0.0  ) < 1e-6  )
  
  
  
  
  
  
  
  		def 				__A      (   self  )     ->   str:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					lowerCamelCase								=     ["""werewolf"""]
  					lowerCamelCase								=     ["""weaewolf"""]
  					# S = 1, D = 0, I = 0, N = 8, CER = 0.125
  					lowerCamelCase								=     cer.compute(predictions=A		,			references=A  )
  					self.assertTrue(abs(char_error_rate - 0.125  ) < 1e-6  )
  
  
  
  
  
  
  
  		def 				__A      (   self  )     ->   Tuple:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					lowerCamelCase								=     ["""werewolf"""]
  					lowerCamelCase								=     ["""wereawolf"""]
  					# S = 0, D = 1, I = 0, N = 8, CER = 0.125
  					lowerCamelCase								=     cer.compute(predictions=A		,			references=A  )
  					self.assertTrue(abs(char_error_rate - 0.125  ) < 1e-6  )
  
  
  
  
  
  
  
  		def 				__A      (   self  )     ->   List[Any]:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					lowerCamelCase								=     ["""werewolf"""]
  					lowerCamelCase								=     ["""wereolf"""]
  					# S = 0, D = 0, I = 1, N = 8, CER = 0.125
  					lowerCamelCase								=     cer.compute(predictions=A		,			references=A  )
  					self.assertTrue(abs(char_error_rate - 0.125  ) < 1e-6  )
  
  
  
  
  
  
  
  		def 				__A      (   self  )     ->   Tuple:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					lowerCamelCase								=     ["""werewolf"""]
  					lowerCamelCase								=     cer.compute(predictions=A		,			references=A  )
  					self.assertEqual(A		,			0.0  )
  
  
  
  
  
  
  
  		def 				__A      (   self  )     ->   List[str]:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					lowerCamelCase								=     ["""werewolf""", """I am your father"""]
  					lowerCamelCase								=     cer.compute(predictions=A		,			references=A  )
  					self.assertEqual(A		,			0.0  )
  
  					lowerCamelCase								=     ["""werewolf""", """I am your father""", """doge"""]
  					lowerCamelCase								=     ["""werxwolf""", """I       am your father""", """doge"""]
  					# S = 1, D = 0, I = 0, N = 28, CER = 1 / 28
  					lowerCamelCase								=     cer.compute(predictions=A		,			references=A  )
  					self.assertTrue(abs(char_error_rate - 0.03571428  ) < 1e-6  )
  
  
  
  
  
  
  
  		def 				__A      (   self  )     ->   List[Any]:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					lowerCamelCase								=     ["""My hovercraft""", """is full of eels"""]
  					lowerCamelCase								=     ["""My hovercraft is full""", """ of eels"""]
  					# S = 0, D = 0, I = 2, N = 28, CER = 2 / 28
  					# whitespace at the front of " of eels" will be strip during preporcessing
  					# so need to insert 2 whitespaces
  					lowerCamelCase								=     cer.compute(predictions=A		,			references=A		,			concatenate_texts=A  )
  					self.assertTrue(abs(char_error_rate - 0.071428  ) < 1e-6  )
  
  
  
  
  
  
  
  		def 				__A      (   self  )     ->   Optional[int]:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					lowerCamelCase								=     ["""我能吞下玻璃而不伤身体"""]
  					lowerCamelCase								=     [""" 能吞虾玻璃而 不霜身体啦"""]
  					# S = 3, D = 2, I = 0, N = 11, CER = 5 / 11
  					lowerCamelCase								=     cer.compute(predictions=A		,			references=A  )
  					self.assertTrue(abs(char_error_rate - 0.4545454545  ) < 1e-6  )
  
  					lowerCamelCase								=     ["""我能吞下玻璃""", """而不伤身体"""]
  					lowerCamelCase								=     ["""我    能 吞 下 玻 璃""", """而不伤身体"""]
  					# S = 0, D = 5, I = 0, N = 11, CER = 5 / 11
  					lowerCamelCase								=     cer.compute(predictions=A		,			references=A  )
  					self.assertTrue(abs(char_error_rate - 0.454545454545  ) < 1e-6  )
  
  					lowerCamelCase								=     ["""我能吞下玻璃而不伤身体"""]
  					lowerCamelCase								=     cer.compute(predictions=A		,			references=A  )
  					self.assertFalse(A		,			0.0  )
  
  
  
  
  
  
  
  		def 				__A      (   self  )     ->   Optional[int]:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  
  					lowerCamelCase								=     [""""""]
  					lowerCamelCase								=     ["""Hypothesis"""]
  					with self.assertRaises(A  ):
  								cer.compute(predictions=A		,			references=A  )
  
  
  if __name__ == "__main__":
  		unittest.main()
  
  