code: 
  
  
  '''simple docstring'''
  
  
  
  
  import functools
  from contextlib import contextmanager
  
  import bert_score
  from packaging import version
  
  import datasets
  
  
  
  
  @contextmanager
  def 	__lowerCamelCase (  )      ->int:
  
  
  
  	def filter_log(UpperCAmelCase_       ):
  		return False if "This IS expected if you are initializing" in record.msg else True
  
  	snake_case__  					=      datasets.utils.logging.get_logger('transformers.modeling_utils'       )
  	logger.addFilter(UpperCAmelCase_       )
  	try:
  		yield
  	finally:
  		logger.removeFilter(UpperCAmelCase_       )
  
  
  a__				: int									=    '''\\n@inproceedings{bert-score,\n  title={BERTScore: Evaluating Text Generation with BERT},\n  author={Tianyi Zhang* and Varsha Kishore* and Felix Wu* and Kilian Q. Weinberger and Yoav Artzi},\n  booktitle={International Conference on Learning Representations},\n  year={2020},\n  url={https://openreview.net/forum?id=SkeHuCVFDr}\n}\n'''
  
  a__				: List[str]									=    '''\\nBERTScore leverages the pre-trained contextual embeddings from BERT and matches words in candidate and reference\nsentences by cosine similarity.\nIt has been shown to correlate with human judgment on sentence-level and system-level evaluation.\nMoreover, BERTScore computes precision, recall, and F1 measure, which can be useful for evaluating different language\ngeneration tasks.\n\nSee the project\'s README at https://github.com/Tiiiger/bert_score#readme for more information.\n'''
  
  a__				: List[str]									=    '''\nBERTScore Metrics with the hashcode from a source against one or more references.\n\nArgs:\n    predictions (list of str): Prediction/candidate sentences.\n    references (list of str or list of list of str): Reference sentences.\n    lang (str): Language of the sentences; required (e.g. \'en\').\n    model_type (str): Bert specification, default using the suggested\n        model for the target language; has to specify at least one of\n        `model_type` or `lang`.\n    num_layers (int): The layer of representation to use,\n        default using the number of layers tuned on WMT16 correlation data.\n    verbose (bool): Turn on intermediate status update.\n    idf (bool or dict): Use idf weighting; can also be a precomputed idf_dict.\n    device (str): On which the contextual embedding model will be allocated on.\n        If this argument is None, the model lives on cuda:0 if cuda is available.\n    nthreads (int): Number of threads.\n    batch_size (int): Bert score processing batch size,\n        at least one of `model_type` or `lang`. `lang` needs to be\n        specified when `rescale_with_baseline` is True.\n    rescale_with_baseline (bool): Rescale bertscore with pre-computed baseline.\n    baseline_path (str): Customized baseline file.\n    use_fast_tokenizer (bool): `use_fast` parameter passed to HF tokenizer. New in version 0.3.10.\n\nReturns:\n    precision: Precision.\n    recall: Recall.\n    f1: F1 score.\n    hashcode: Hashcode of the library.\n\nExamples:\n\n    >>> predictions = [\"hello there\", \"general kenobi\"]\n    >>> references = [\"hello there\", \"general kenobi\"]\n    >>> bertscore = datasets.load_metric(\"bertscore\")\n    >>> results = bertscore.compute(predictions=predictions, references=references, lang=\"en\")\n    >>> print([round(v, 2) for v in results[\"f1\"]])\n    [1.0, 1.0]\n'''
  
  
  
  
  
  
  
  @datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION					,					_KWARGS_DESCRIPTION       )
  class 							__snake_case    (				datasets.Metric       ):
  
  
  
  
  
  	def      _snake_case      (		self		)			->		int:
  		return datasets.MetricInfo(
  		    description=_DESCRIPTION			,					citation=_CITATION			,					homepage='https://github.com/Tiiiger/bert_score'			,					inputs_description=_KWARGS_DESCRIPTION			,					features=datasets.Features(
  		        {
  		            'predictions': datasets.Value('string'			,					id='sequence'		),
  		            'references': datasets.Sequence(datasets.Value('string'			,					id='sequence'		)			,					id='references'		),
  		        }		)			,					codebase_urls=['https://github.com/Tiiiger/bert_score']			,					reference_urls=[
  		        'https://github.com/Tiiiger/bert_score',
  		        'https://arxiv.org/abs/1904.09675',
  		    ]			,					)
  
  
  
  
  
  	def      _snake_case      (		self			,					UpperCamelCase_			,					UpperCamelCase_			,					UpperCamelCase_=None			,					UpperCamelCase_=None			,					UpperCamelCase_=None			,					UpperCamelCase_=False			,					UpperCamelCase_=False			,					UpperCamelCase_=None			,					UpperCamelCase_=64			,					UpperCamelCase_=4			,					UpperCamelCase_=False			,					UpperCamelCase_=False			,					UpperCamelCase_=None			,					UpperCamelCase_=False			,					)			->		Dict:
  		snake_case__  					=      bert_score.utils.get_hash
  		snake_case__  					=      bert_score.BERTScorer
  
  		if version.parse(bert_score.__version__		) >= version.parse('0.3.10'		):
  			snake_case__  					=      functools.partial(lowerCAmelCase_			,					use_fast_tokenizer=lowerCAmelCase_		)
  			snake_case__  					=      functools.partial(lowerCAmelCase_			,					use_fast_tokenizer=lowerCAmelCase_		)
  		elif use_fast_tokenizer:
  			raise ImportWarning(
  			    'To use a fast tokenizer, the module `bert-score>=0.3.10` is required, and the current version of `bert-score` doesn\'t match this condition.\n'
  			    'You can install it with `pip install "bert-score>=0.3.10"`.'		)
  
  		if model_type is None:
  			assert lang is not None, "either lang or model_type should be specified"
  			snake_case__  					=      bert_score.utils.langamodel[lang.lower()]
  
  		if num_layers is None:
  			snake_case__  					=      bert_score.utils.modelalayers[model_type]
  
  		snake_case__  					=      get_hash(
  		    model=lowerCAmelCase_			,					num_layers=lowerCAmelCase_			,					idf=lowerCAmelCase_			,					rescale_with_baseline=lowerCAmelCase_			,					use_custom_baseline=baseline_path is not None			,					)
  
  		with filter_logging_context():
  			if not hasattr(self			,					'cached_bertscorer'		) or self.cached_bertscorer.hash != hashcode:
  				snake_case__  					=      scorer(
  				    model_type=lowerCAmelCase_			,					num_layers=lowerCAmelCase_			,					batch_size=lowerCAmelCase_			,					nthreads=lowerCAmelCase_			,					all_layers=lowerCAmelCase_			,					idf=lowerCAmelCase_			,					device=lowerCAmelCase_			,					lang=lowerCAmelCase_			,					rescale_with_baseline=lowerCAmelCase_			,					baseline_path=lowerCAmelCase_			,					)
  
  		((snake_case__)					,     (snake_case__)					,     (snake_case__))  					=      self.cached_bertscorer.score(
  		    cands=lowerCAmelCase_			,					refs=lowerCAmelCase_			,					verbose=lowerCAmelCase_			,					batch_size=lowerCAmelCase_			,					)
  		snake_case__  					=      {
  		    'precision': P.tolist(),
  		    'recall': R.tolist(),
  		    'f1': F.tolist(),
  		    'hashcode': hashcode,
  		}
  		return output_dict
  
  
  
  
  
  	def      _snake_case      (		self			,					UpperCamelCase_=None			,					UpperCamelCase_=None			,					**UpperCamelCase_		)			->		str:
  
  
  
  
  
  
  		if references is not None:
  			snake_case__  					=      [[ref] if isinstance(lowerCAmelCase_			,					lowerCAmelCase_		) else ref for ref in references]
  		super().add_batch(predictions=lowerCAmelCase_			,					references=lowerCAmelCase_			,					**lowerCAmelCase_		)
  
  
  
  
  
  	def      _snake_case      (		self			,					UpperCamelCase_=None			,					UpperCamelCase_=None			,					**UpperCamelCase_		)			->		List[str]:
  
  
  
  
  
  
  		if isinstance(lowerCAmelCase_			,					lowerCAmelCase_		):
  			snake_case__  					=      [reference]
  		super().add(prediction=lowerCAmelCase_			,					reference=lowerCAmelCase_			,					**lowerCAmelCase_		)
  
  
  
  
style_context: 
  
  
  
  
  
  '''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__				: Tuple									=    5_0358
  a__				: str									=    5_0362
  
  
  
  
  
  
  @require_torch
  @require_torchaudio
  @require_sentencepiece
  class 							__snake_case    (				unittest.TestCase       ):
  
  
  
  
  
  	def      _snake_case      (		self		)			->		Dict:
  		snake_case__  					=      'openai/whisper-small.en'
  		snake_case__  					=      tempfile.mkdtemp()
  
  
  
  
  
  	def      _snake_case      (		self			,					**UpperCamelCase_		)			->		Optional[int]:
  		return WhisperTokenizer.from_pretrained(self.checkpoint			,					**UpperCamelCase_		)
  
  
  
  
  
  	def      _snake_case      (		self			,					**UpperCamelCase_		)			->		Any:
  		return WhisperFeatureExtractor.from_pretrained(self.checkpoint			,					**UpperCamelCase_		)
  
  
  
  
  
  	def      _snake_case      (		self		)			->		Tuple:
  		shutil.rmtree(self.tmpdirname		)
  
  
  
  
  
  	def      _snake_case      (		self		)			->		Any:
  		snake_case__  					=      self.get_tokenizer()
  		snake_case__  					=      self.get_feature_extractor()
  
  		snake_case__  					=      WhisperProcessor(tokenizer=UpperCamelCase_			,					feature_extractor=UpperCamelCase_		)
  
  		processor.save_pretrained(self.tmpdirname		)
  		snake_case__  					=      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      _snake_case      (		self		)			->		Dict:
  		snake_case__  					=      WhisperProcessor(tokenizer=self.get_tokenizer()			,					feature_extractor=self.get_feature_extractor()		)
  		processor.save_pretrained(self.tmpdirname		)
  
  		snake_case__  					=      self.get_tokenizer(bos_token='(BOS)'			,					eos_token='(EOS)'		)
  		snake_case__  					=      self.get_feature_extractor(do_normalize=UpperCamelCase_			,					padding_value=1.0		)
  
  		snake_case__  					=      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      _snake_case      (		self		)			->		List[str]:
  		snake_case__  					=      self.get_feature_extractor()
  		snake_case__  					=      self.get_tokenizer()
  
  		snake_case__  					=      WhisperProcessor(tokenizer=UpperCamelCase_			,					feature_extractor=UpperCamelCase_		)
  
  		snake_case__  					=      floats_list((3, 1000)		)
  
  		snake_case__  					=      feature_extractor(UpperCamelCase_			,					return_tensors='np'		)
  		snake_case__  					=      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      _snake_case      (		self		)			->		Union[str, Any]:
  		snake_case__  					=      self.get_feature_extractor()
  		snake_case__  					=      self.get_tokenizer()
  
  		snake_case__  					=      WhisperProcessor(tokenizer=UpperCamelCase_			,					feature_extractor=UpperCamelCase_		)
  
  		snake_case__  					=      'This is a test string'
  
  		snake_case__  					=      processor(text=UpperCamelCase_		)
  
  		snake_case__  					=      tokenizer(UpperCamelCase_		)
  
  		for key in encoded_tok.keys():
  			self.assertListEqual(encoded_tok[key]			,					encoded_processor[key]		)
  
  
  
  
  
  	def      _snake_case      (		self		)			->		Tuple:
  		snake_case__  					=      self.get_feature_extractor()
  		snake_case__  					=      self.get_tokenizer()
  
  		snake_case__  					=      WhisperProcessor(tokenizer=UpperCamelCase_			,					feature_extractor=UpperCamelCase_		)
  
  		snake_case__  					=      [[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]
  
  		snake_case__  					=      processor.batch_decode(UpperCamelCase_		)
  		snake_case__  					=      tokenizer.batch_decode(UpperCamelCase_		)
  
  		self.assertListEqual(UpperCamelCase_			,					UpperCamelCase_		)
  
  
  
  
  
  	def      _snake_case      (		self		)			->		List[str]:
  		snake_case__  					=      self.get_feature_extractor()
  		snake_case__  					=      self.get_tokenizer()
  
  		snake_case__  					=      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      _snake_case      (		self		)			->		Dict:
  		snake_case__  					=      self.get_feature_extractor()
  		snake_case__  					=      self.get_tokenizer()
  
  		snake_case__  					=      WhisperProcessor(tokenizer=UpperCamelCase_			,					feature_extractor=UpperCamelCase_		)
  		snake_case__  					=      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)		)
  
  		snake_case__  					=      [TRANSCRIBE, NOTIMESTAMPS]
  		self.assertListEqual([ids[-1] for ids in forced_decoder_ids]			,					UpperCamelCase_		)
  
  
  
  
  
  	def      _snake_case      (		self		)			->		List[str]:
  		snake_case__  					=      WhisperProcessor(tokenizer=self.get_tokenizer()			,					feature_extractor=self.get_feature_extractor()		)
  		snake_case__  					=      processor.get_prompt_ids('Mr. Quilter'		)
  		snake_case__  					=      processor.tokenizer.decode(UpperCamelCase_		)
  
  		self.assertListEqual(prompt_ids.tolist()			,					[5_0360, 1770, 13, 2264, 346, 353]		)
  		self.assertEqual(UpperCamelCase_			,					'<|startofprev|> Mr. Quilter'		)
  
  
  
  
  
  	def      _snake_case      (		self		)			->		Dict:
  		snake_case__  					=      WhisperProcessor(tokenizer=self.get_tokenizer()			,					feature_extractor=self.get_feature_extractor()		)
  		snake_case__  					=      processor.get_prompt_ids(''		)
  		snake_case__  					=      processor.tokenizer.decode(UpperCamelCase_		)
  
  		self.assertListEqual(prompt_ids.tolist()			,					[5_0360, 220]		)
  		self.assertEqual(UpperCamelCase_			,					'<|startofprev|> '		)
  
  
  
  
  
  	def      _snake_case      (		self		)			->		int:
  		snake_case__  					=      WhisperProcessor(tokenizer=self.get_tokenizer()			,					feature_extractor=self.get_feature_extractor()		)
  
  		def _test_prompt_error_raised_helper(UpperCamelCase_			,					UpperCamelCase_		):
  			with pytest.raises(UpperCamelCase_		) as excinfo:
  				processor.get_prompt_ids(UpperCamelCase_		)
  			snake_case__  					=      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|>'		)
  
  
  
  