


import re
import string
from collections import Counter

import sacrebleu
import sacremoses
from packaging import version

import datasets


a_ :List[Any]  							=			'\n@inproceedings{xu-etal-2016-optimizing,\n    title = {Optimizing Statistical Machine Translation for Text Simplification},\n    authors={Xu, Wei and Napoles, Courtney and Pavlick, Ellie and Chen, Quanze and Callison-Burch, Chris},\n    journal = {Transactions of the Association for Computational Linguistics},\n    volume = {4},\n    year={2016},\n    url = {https://www.aclweb.org/anthology/Q16-1029},\n    pages = {401--415\n},\n@inproceedings{post-2018-call,\n    title = "A Call for Clarity in Reporting {BLEU} Scores",\n    author = "Post, Matt",\n    booktitle = "Proceedings of the Third Conference on Machine Translation: Research Papers",\n    month = oct,\n    year = "2018",\n    address = "Belgium, Brussels",\n    publisher = "Association for Computational Linguistics",\n    url = "https://www.aclweb.org/anthology/W18-6319",\n    pages = "186--191",\n}\n'

a_ :Union[str, Any]  							=			'\\nWIKI_SPLIT is the combination of three metrics SARI, EXACT and SACREBLEU\nIt can be used to evaluate the quality of machine-generated texts.\n'


a_ :Optional[int]  							=			'\nCalculates sari score (between 0 and 100) given a list of source and predicted\nsentences, and a list of lists of reference sentences. It also computes the BLEU score as well as the exact match score.\nArgs:\n    sources: list of source sentences where each sentence should be a string.\n    predictions: list of predicted sentences where each sentence should be a string.\n    references: list of lists of reference sentences where each sentence should be a string.\nReturns:\n    sari: sari score\n    sacrebleu: sacrebleu score\n    exact: exact score\n\nExamples:\n    >>> sources=["About 95 species are currently accepted ."]\n    >>> predictions=["About 95 you now get in ."]\n    >>> references=[["About 95 species are currently known ."]]\n    >>> wiki_split = datasets.load_metric("wiki_split")\n    >>> results = wiki_split.compute(sources=sources, predictions=predictions, references=references)\n    >>> print(results)\n    {\'sari\': 21.805555555555557, \'sacrebleu\': 14.535768424205482, \'exact\': 0.0}\n'




def    a   (							A__							)	-> Any:




      '''simple docstring'''

      def remove_articles(A__							):
            SCREAMING_SNAKE_CASE__       :  Optional[int]						     =		re.compile(r'''\b(a|an|the)\b'''      ,    re.UNICODE							)
            return re.sub(A__      ,    ''' '''      ,    A__							)

      def white_space_fix(A__							):
            return " ".join(text.split()							)

      def remove_punc(A__							):
            SCREAMING_SNAKE_CASE__       :  Dict						     =		set(string.punctuation							)
            return "".join(ch for ch in text if ch not in exclude							)

      def lower(A__							):
            return text.lower()

      return white_space_fix(remove_articles(remove_punc(lower(A__							)							)							)							)




def    a   (							A__      ,    A__							)	-> Tuple:




      '''simple docstring'''

      return int(normalize_answer(A__							) == normalize_answer(A__							)							)




def    a   (							A__      ,    A__							)	-> Optional[Any]:




      '''simple docstring'''

      SCREAMING_SNAKE_CASE__       :  int						     =		[any(compute_exact(A__      ,    A__							) for ref in refs							) for pred, refs in zip(A__      ,    A__							)]
      return (sum(A__							) / len(A__							)) * 1_0_0




def    a   (							A__      ,    A__      ,    A__      ,    A__							)	-> str:




      '''simple docstring'''

      SCREAMING_SNAKE_CASE__       :  Optional[int]						     =		[rgram for rgrams in rgramslist for rgram in rgrams]
      SCREAMING_SNAKE_CASE__       :  Optional[int]						     =		Counter(A__							)

      SCREAMING_SNAKE_CASE__       :  str						     =		Counter(A__							)
      SCREAMING_SNAKE_CASE__       :  Any						     =		Counter()
      for sgram, scount in sgramcounter.items():
            SCREAMING_SNAKE_CASE__       :  Union[str, Any]						     =		scount * numref

      SCREAMING_SNAKE_CASE__       :  Tuple						     =		Counter(A__							)
      SCREAMING_SNAKE_CASE__       :  List[str]						     =		Counter()
      for cgram, ccount in cgramcounter.items():
            SCREAMING_SNAKE_CASE__       :  Tuple						     =		ccount * numref

      # KEEP
      SCREAMING_SNAKE_CASE__       :  int						     =		sgramcounter_rep & cgramcounter_rep
      SCREAMING_SNAKE_CASE__       :  Any						     =		keepgramcounter_rep & rgramcounter
      SCREAMING_SNAKE_CASE__       :  Tuple						     =		sgramcounter_rep & rgramcounter

      SCREAMING_SNAKE_CASE__       :  List[str]						     =		0
      SCREAMING_SNAKE_CASE__       :  int						     =		0
      for keepgram in keepgramcountergood_rep:
            keeptmpscorea += keepgramcountergood_rep[keepgram] / keepgramcounter_rep[keepgram]
            # Fix an alleged bug [2] in the keep score computation.
            # keeptmpscore2 += keepgramcountergood_rep[keepgram] / keepgramcounterall_rep[keepgram]
            keeptmpscorea += keepgramcountergood_rep[keepgram]
      # Define 0/0=1 instead of 0 to give higher scores for predictions that match
      #      a target exactly.
      SCREAMING_SNAKE_CASE__       :  Any						     =		1
      SCREAMING_SNAKE_CASE__       :  Dict						     =		1
      if len(A__							) > 0:
            SCREAMING_SNAKE_CASE__       :  Optional[int]						     =		keeptmpscorea / len(A__							)
      if len(A__							) > 0:
            # Fix an alleged bug [2] in the keep score computation.
            # keepscore_recall = keeptmpscore2 / len(keepgramcounterall_rep)
            SCREAMING_SNAKE_CASE__       :  Dict						     =		keeptmpscorea / sum(keepgramcounterall_rep.values()							)
      SCREAMING_SNAKE_CASE__       :  Dict						     =		0
      if keepscore_precision > 0 or keepscore_recall > 0:
            SCREAMING_SNAKE_CASE__       :  str						     =		2 * keepscore_precision * keepscore_recall / (keepscore_precision + keepscore_recall)

      # DELETION
      SCREAMING_SNAKE_CASE__       :  int						     =		sgramcounter_rep - cgramcounter_rep
      SCREAMING_SNAKE_CASE__       :  Any						     =		delgramcounter_rep - rgramcounter
      SCREAMING_SNAKE_CASE__       :  Optional[int]						     =		sgramcounter_rep - rgramcounter
      SCREAMING_SNAKE_CASE__       :  List[str]						     =		0
      SCREAMING_SNAKE_CASE__       :  Tuple						     =		0
      for delgram in delgramcountergood_rep:
            deltmpscorea += delgramcountergood_rep[delgram] / delgramcounter_rep[delgram]
            deltmpscorea += delgramcountergood_rep[delgram] / delgramcounterall_rep[delgram]
      # Define 0/0=1 instead of 0 to give higher scores for predictions that match
      # a target exactly.
      SCREAMING_SNAKE_CASE__       :  List[Any]						     =		1
      if len(A__							) > 0:
            SCREAMING_SNAKE_CASE__       :  List[str]						     =		deltmpscorea / len(A__							)

      # ADDITION
      SCREAMING_SNAKE_CASE__       :  List[Any]						     =		set(A__							) - set(A__							)
      SCREAMING_SNAKE_CASE__       :  str						     =		set(A__							) & set(A__							)
      SCREAMING_SNAKE_CASE__       :  Optional[int]						     =		set(A__							) - set(A__							)

      SCREAMING_SNAKE_CASE__       :  str						     =		0
      for addgram in addgramcountergood:
            addtmpscore += 1

      # Define 0/0=1 instead of 0 to give higher scores for predictions that match
      # a target exactly.
      SCREAMING_SNAKE_CASE__       :  Optional[int]						     =		1
      SCREAMING_SNAKE_CASE__       :  List[Any]						     =		1
      if len(A__							) > 0:
            SCREAMING_SNAKE_CASE__       :  str						     =		addtmpscore / len(A__							)
      if len(A__							) > 0:
            SCREAMING_SNAKE_CASE__       :  int						     =		addtmpscore / len(A__							)
      SCREAMING_SNAKE_CASE__       :  Optional[Any]						     =		0
      if addscore_precision > 0 or addscore_recall > 0:
            SCREAMING_SNAKE_CASE__       :  List[str]						     =		2 * addscore_precision * addscore_recall / (addscore_precision + addscore_recall)

      return (keepscore, delscore_precision, addscore)




def    a   (							A__      ,    A__      ,    A__							)	-> Tuple:




      '''simple docstring'''

      SCREAMING_SNAKE_CASE__       :  Optional[int]						     =		len(A__							)

      SCREAMING_SNAKE_CASE__       :  Dict						     =		ssent.split(''' '''							)
      SCREAMING_SNAKE_CASE__       :  Dict						     =		csent.split(''' '''							)
      SCREAMING_SNAKE_CASE__       :  Optional[Any]						     =		[]
      SCREAMING_SNAKE_CASE__       :  Optional[int]						     =		[]
      SCREAMING_SNAKE_CASE__       :  str						     =		[]
      SCREAMING_SNAKE_CASE__       :  Optional[Any]						     =		[]
      SCREAMING_SNAKE_CASE__       :  Any						     =		[]
      SCREAMING_SNAKE_CASE__       :  int						     =		[]

      SCREAMING_SNAKE_CASE__       :  str						     =		[]
      SCREAMING_SNAKE_CASE__       :  Dict						     =		[]
      SCREAMING_SNAKE_CASE__       :  Tuple						     =		[]
      SCREAMING_SNAKE_CASE__       :  str						     =		[]
      for rsent in rsents:
            SCREAMING_SNAKE_CASE__       :  Dict						     =		rsent.split(''' '''							)
            SCREAMING_SNAKE_CASE__       :  List[Any]						     =		[]
            SCREAMING_SNAKE_CASE__       :  Union[str, Any]						     =		[]
            SCREAMING_SNAKE_CASE__       :  Optional[Any]						     =		[]
            ragramslist.append(A__							)
            for i in range(0      ,    len(A__							) - 1							):
                  if i < len(A__							) - 1:
                        SCREAMING_SNAKE_CASE__       :  Tuple						     =		ragrams[i] + ''' ''' + ragrams[i + 1]
                        ragrams.append(A__							)
                  if i < len(A__							) - 2:
                        SCREAMING_SNAKE_CASE__       :  Optional[Any]						     =		ragrams[i] + ''' ''' + ragrams[i + 1] + ''' ''' + ragrams[i + 2]
                        ragrams.append(A__							)
                  if i < len(A__							) - 3:
                        SCREAMING_SNAKE_CASE__       :  List[Any]						     =		ragrams[i] + ''' ''' + ragrams[i + 1] + ''' ''' + ragrams[i + 2] + ''' ''' + ragrams[i + 3]
                        ragrams.append(A__							)
            ragramslist.append(A__							)
            ragramslist.append(A__							)
            ragramslist.append(A__							)

      for i in range(0      ,    len(A__							) - 1							):
            if i < len(A__							) - 1:
                  SCREAMING_SNAKE_CASE__       :  Optional[Any]						     =		sagrams[i] + ''' ''' + sagrams[i + 1]
                  sagrams.append(A__							)
            if i < len(A__							) - 2:
                  SCREAMING_SNAKE_CASE__       :  Union[str, Any]						     =		sagrams[i] + ''' ''' + sagrams[i + 1] + ''' ''' + sagrams[i + 2]
                  sagrams.append(A__							)
            if i < len(A__							) - 3:
                  SCREAMING_SNAKE_CASE__       :  List[Any]						     =		sagrams[i] + ''' ''' + sagrams[i + 1] + ''' ''' + sagrams[i + 2] + ''' ''' + sagrams[i + 3]
                  sagrams.append(A__							)

      for i in range(0      ,    len(A__							) - 1							):
            if i < len(A__							) - 1:
                  SCREAMING_SNAKE_CASE__       :  List[str]						     =		cagrams[i] + ''' ''' + cagrams[i + 1]
                  cagrams.append(A__							)
            if i < len(A__							) - 2:
                  SCREAMING_SNAKE_CASE__       :  List[Any]						     =		cagrams[i] + ''' ''' + cagrams[i + 1] + ''' ''' + cagrams[i + 2]
                  cagrams.append(A__							)
            if i < len(A__							) - 3:
                  SCREAMING_SNAKE_CASE__       :  Dict						     =		cagrams[i] + ''' ''' + cagrams[i + 1] + ''' ''' + cagrams[i + 2] + ''' ''' + cagrams[i + 3]
                  cagrams.append(A__							)

      ((SCREAMING_SNAKE_CASE__)     ,       (SCREAMING_SNAKE_CASE__)     ,       (SCREAMING_SNAKE_CASE__))       :  Tuple						     =		SARIngram(A__      ,    A__      ,    A__      ,    A__							)
      ((SCREAMING_SNAKE_CASE__)     ,       (SCREAMING_SNAKE_CASE__)     ,       (SCREAMING_SNAKE_CASE__))       :  Union[str, Any]						     =		SARIngram(A__      ,    A__      ,    A__      ,    A__							)
      ((SCREAMING_SNAKE_CASE__)     ,       (SCREAMING_SNAKE_CASE__)     ,       (SCREAMING_SNAKE_CASE__))       :  str						     =		SARIngram(A__      ,    A__      ,    A__      ,    A__							)
      ((SCREAMING_SNAKE_CASE__)     ,       (SCREAMING_SNAKE_CASE__)     ,       (SCREAMING_SNAKE_CASE__))       :  Optional[int]						     =		SARIngram(A__      ,    A__      ,    A__      ,    A__							)
      SCREAMING_SNAKE_CASE__       :  Optional[Any]						     =		sum([keepascore, keepascore, keepascore, keepascore]							) / 4
      SCREAMING_SNAKE_CASE__       :  Optional[int]						     =		sum([delascore, delascore, delascore, delascore]							) / 4
      SCREAMING_SNAKE_CASE__       :  List[str]						     =		sum([addascore, addascore, addascore, addascore]							) / 4
      SCREAMING_SNAKE_CASE__       :  int						     =		(avgkeepscore + avgdelscore + avgaddscore) / 3
      return finalscore




def    a   (							A__      ,    A__ = True      ,    A__ = "13a"      ,    A__ = True							)	-> Optional[int]:




      '''simple docstring'''

      if lowercase:
            SCREAMING_SNAKE_CASE__       :  List[str]						     =		sentence.lower()

      if tokenizer in ["13a", "intl"]:
            if version.parse(sacrebleu.__version__							).major >= 2:
                  SCREAMING_SNAKE_CASE__       :  str						     =		sacrebleu.metrics.bleu._get_tokenizer(A__							)()(A__							)
            else:
                  SCREAMING_SNAKE_CASE__       :  Optional[Any]						     =		sacrebleu.TOKENIZERS[tokenizer]()(A__							)
      elif tokenizer == "moses":
            SCREAMING_SNAKE_CASE__       :  str						     =		sacremoses.MosesTokenizer().tokenize(A__      ,    return_str=A__      ,    escape=A__							)
      elif tokenizer == "penn":
            SCREAMING_SNAKE_CASE__       :  int						     =		sacremoses.MosesTokenizer().penn_tokenize(A__      ,    return_str=A__							)
      else:
            SCREAMING_SNAKE_CASE__       :  Tuple						     =		sentence

      if not return_str:
            SCREAMING_SNAKE_CASE__       :  List[str]						     =		normalized_sent.split()

      return normalized_sent




def    a   (							A__      ,    A__      ,    A__							)	-> int:




      '''simple docstring'''

      if not (len(A__							) == len(A__							) == len(A__							)):
            raise ValueError('''Sources length must match predictions and references lengths.'''							)
      SCREAMING_SNAKE_CASE__       :  str						     =		0
      for src, pred, refs in zip(A__      ,    A__      ,    A__							):
            sari_score += SARIsent(normalize(A__							)      ,    normalize(A__							)      ,    [normalize(A__							) for sent in refs]							)
      SCREAMING_SNAKE_CASE__       :  Optional[Any]						     =		sari_score / len(A__							)
      return 1_0_0 * sari_score




def    a   (							A__      ,    A__      ,    A__="exp"      ,    A__=None      ,    A__=False      ,    A__=False      ,    A__=False      ,    )	-> str:




      '''simple docstring'''

      SCREAMING_SNAKE_CASE__       :  List[str]						     =		len(references[0]							)
      if any(len(A__							) != references_per_prediction for refs in references							):
            raise ValueError('''Sacrebleu requires the same number of references for each prediction'''							)
      SCREAMING_SNAKE_CASE__       :  Tuple						     =		[[refs[i] for refs in references] for i in range(A__							)]
      SCREAMING_SNAKE_CASE__       :  Optional[int]						     =		sacrebleu.corpus_bleu(
          A__      ,    A__      ,    smooth_method=A__      ,    smooth_value=A__      ,    force=A__      ,    lowercase=A__      ,    use_effective_order=A__      ,    )
      return output.score





@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION    ,       _KWARGS_DESCRIPTION			)
class 							lowercase  (						datasets.Metric			):







     def 							lowercase__       (						self :						List[Any]      ):
           return datasets.MetricInfo(
               description=_DESCRIPTION   ,   citation=_CITATION   ,   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/huggingface/transformers/blob/master/src/transformers/data/metrics/squad_metrics.py''',
                   '''https://github.com/cocoxu/simplification/blob/master/SARI.py''',
                   '''https://github.com/tensorflow/tensor2tensor/blob/master/tensor2tensor/utils/sari_hook.py''',
                   '''https://github.com/mjpost/sacreBLEU''',
               ]   ,   reference_urls=[
                   '''https://www.aclweb.org/anthology/Q16-1029.pdf''',
                   '''https://github.com/mjpost/sacreBLEU''',
                   '''https://en.wikipedia.org/wiki/BLEU''',
                   '''https://towardsdatascience.com/evaluating-text-output-in-nlp-bleu-at-your-own-risk-e8609665a213''',
               ]   ,   )







     def 							lowercase__       (						self :						Optional[Any]   ,   _lowercase :						Union[str, Any]   ,   _lowercase :						Dict   ,   _lowercase :						str      ):
           SCREAMING_SNAKE_CASE__       :  Union[str, Any]						     =		{}
           result.update({'''sari''': compute_sari(sources=_lowercase   ,   predictions=_lowercase   ,   references=_lowercase      )}      )
           result.update({'''sacrebleu''': compute_sacrebleu(predictions=_lowercase   ,   references=_lowercase      )}      )
           result.update({'''exact''': compute_em(predictions=_lowercase   ,   references=_lowercase      )}      )
           return result












'''simple docstring'''


import itertools
import os
import random
import tempfile
import unittest

import numpy as np
from datasets import load_dataset

from transformers import is_speech_available
from transformers.testing_utils import check_json_file_has_correct_format, require_torch, require_torchaudio
from transformers.utils.import_utils import is_torch_available

from ...test_sequence_feature_extraction_common import SequenceFeatureExtractionTestMixin


if is_speech_available():
  from transformers import WhisperFeatureExtractor

if is_torch_available():
  import torch

UpperCAmelCase_					=   random.Random()


def     SCREAMING_SNAKE_CASE							(   a_						:				Optional[Any]					,       a_						:				Any=1.0					,       a_						:				Optional[Any]=None					,       a_						:				Union[str, Any]=None      ):
  if rng is None:
    __a								=       global_rng

  __a								=       []
  for batch_idx in range(shape[0]      ):
    values.append([]      )
    for _ in range(shape[1]      ):
      values[-1].append(rng.random() * scale      )

  return values





@require_torch
@require_torchaudio
class  __lowercase    (	unittest.TestCase			):







   def __init__(						self   ,				UpperCamelCase   ,				UpperCamelCase=7   ,				UpperCamelCase=400   ,				UpperCamelCase=2000   ,				UpperCamelCase=10   ,				UpperCamelCase=160   ,				UpperCamelCase=8   ,				UpperCamelCase=0.0   ,				UpperCamelCase=4000   ,				UpperCamelCase=False   ,				UpperCamelCase=True   ,				)					->     Optional[Any]:
     __a								=       parent
     __a								=       batch_size
     __a								=       min_seq_length
     __a								=       max_seq_length
     __a								=       (self.max_seq_length - self.min_seq_length) // (self.batch_size - 1)
     __a								=       padding_value
     __a								=       sampling_rate
     __a								=       return_attention_mask
     __a								=       do_normalize
     __a								=       feature_size
     __a								=       chunk_length
     __a								=       hop_length







   def 		UpperCamelCase__      (						self   )					->     Tuple:
     return {
         "feature_size": self.feature_size,
         "hop_length": self.hop_length,
         "chunk_length": self.chunk_length,
         "padding_value": self.padding_value,
         "sampling_rate": self.sampling_rate,
         "return_attention_mask": self.return_attention_mask,
         "do_normalize": self.do_normalize,
     }







   def 		UpperCamelCase__      (						self   ,				UpperCamelCase=False   ,				UpperCamelCase=False   )					->     int:
     def _flatten(UpperCamelCase   ):
       return list(itertools.chain(*UpperCamelCase   )   )

     if equal_length:
       __a								=       [floats_list((self.max_seq_length, self.feature_size)   ) for _ in range(self.batch_size   )]
     else:
       # make sure that inputs increase in size
       __a								=       [
           floats_list((x, self.feature_size)   )
           for x in range(self.min_seq_length   ,				self.max_seq_length   ,				self.seq_length_diff   )
       ]
     if numpify:
       __a								=       [np.asarray(UpperCamelCase   ) for x in speech_inputs]
     return speech_inputs





@require_torch
@require_torchaudio
class  __lowercase    (	__magic_name__							,				unittest.TestCase			):
   _a    						=   WhisperFeatureExtractor if is_speech_available() else None







   def 		UpperCamelCase__      (						self   )					->     str:
     __a								=       WhisperFeatureExtractionTester(self   )







   def 		UpperCamelCase__      (						self   )					->     Union[str, Any]:
     __a								=       self.feature_extraction_class(**self.feat_extract_dict   )

     with tempfile.TemporaryDirectory() as tmpdirname:
       __a								=       feat_extract_first.save_pretrained(UpperCamelCase   )[0]
       check_json_file_has_correct_format(UpperCamelCase   )
       __a								=       self.feature_extraction_class.from_pretrained(UpperCamelCase   )

     __a								=       feat_extract_first.to_dict()
     __a								=       feat_extract_second.to_dict()
     __a								=       feat_extract_first.mel_filters
     __a								=       feat_extract_second.mel_filters
     self.assertTrue(np.allclose(UpperCamelCase   ,				UpperCamelCase   )   )
     self.assertEqual(UpperCamelCase   ,				UpperCamelCase   )







   def 		UpperCamelCase__      (						self   )					->     Dict:
     __a								=       self.feature_extraction_class(**self.feat_extract_dict   )

     with tempfile.TemporaryDirectory() as tmpdirname:
       __a								=       os.path.join(UpperCamelCase   ,				'feat_extract.json'   )
       feat_extract_first.to_json_file(UpperCamelCase   )
       __a								=       self.feature_extraction_class.from_json_file(UpperCamelCase   )

     __a								=       feat_extract_first.to_dict()
     __a								=       feat_extract_second.to_dict()
     __a								=       feat_extract_first.mel_filters
     __a								=       feat_extract_second.mel_filters
     self.assertTrue(np.allclose(UpperCamelCase   ,				UpperCamelCase   )   )
     self.assertEqual(UpperCamelCase   ,				UpperCamelCase   )







   def 		UpperCamelCase__      (						self   )					->     Optional[Any]:
     # Tests that all call wrap to encode_plus and batch_encode_plus
     __a								=       self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()   )
     # create three inputs of length 800, 1000, and 1200
     __a								=       [floats_list((1, x)   )[0] for x in range(800   ,				1400   ,				200   )]
     __a								=       [np.asarray(UpperCamelCase   ) for speech_input in speech_inputs]

     # Test feature size
     __a								=       feature_extractor(UpperCamelCase   ,				padding='max_length'   ,				return_tensors='np'   ).input_features
     self.assertTrue(input_features.ndim == 3   )
     self.assertTrue(input_features.shape[-1] == feature_extractor.nb_max_frames   )
     self.assertTrue(input_features.shape[-2] == feature_extractor.feature_size   )

     # Test not batched input
     __a								=       feature_extractor(speech_inputs[0]   ,				return_tensors='np'   ).input_features
     __a								=       feature_extractor(np_speech_inputs[0]   ,				return_tensors='np'   ).input_features
     self.assertTrue(np.allclose(UpperCamelCase   ,				UpperCamelCase   ,				atol=1e-3   )   )

     # Test batched
     __a								=       feature_extractor(UpperCamelCase   ,				return_tensors='np'   ).input_features
     __a								=       feature_extractor(UpperCamelCase   ,				return_tensors='np'   ).input_features
     for enc_seq_a, enc_seq_a in zip(UpperCamelCase   ,				UpperCamelCase   ):
       self.assertTrue(np.allclose(UpperCamelCase   ,				UpperCamelCase   ,				atol=1e-3   )   )

     # Test 2-D numpy arrays are batched.
     __a								=       [floats_list((1, x)   )[0] for x in (800, 800, 800)]
     __a								=       np.asarray(UpperCamelCase   )
     __a								=       feature_extractor(UpperCamelCase   ,				return_tensors='np'   ).input_features
     __a								=       feature_extractor(UpperCamelCase   ,				return_tensors='np'   ).input_features
     for enc_seq_a, enc_seq_a in zip(UpperCamelCase   ,				UpperCamelCase   ):
       self.assertTrue(np.allclose(UpperCamelCase   ,				UpperCamelCase   ,				atol=1e-3   )   )

     # Test truncation required
     __a								=       [floats_list((1, x)   )[0] for x in range(200   ,				(feature_extractor.n_samples + 500)   ,				200   )]
     __a								=       [np.asarray(UpperCamelCase   ) for speech_input in speech_inputs]

     __a								=       [x[: feature_extractor.n_samples] for x in speech_inputs]
     __a								=       [np.asarray(UpperCamelCase   ) for speech_input in speech_inputs_truncated]

     __a								=       feature_extractor(UpperCamelCase   ,				return_tensors='np'   ).input_features
     __a								=       feature_extractor(UpperCamelCase   ,				return_tensors='np'   ).input_features
     for enc_seq_a, enc_seq_a in zip(UpperCamelCase   ,				UpperCamelCase   ):
       self.assertTrue(np.allclose(UpperCamelCase   ,				UpperCamelCase   ,				atol=1e-3   )   )







   def 		UpperCamelCase__      (						self   )					->     int:
     import torch

     __a								=       self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()   )
     __a								=       np.random.rand(100   ,				32   ).astype(np.floataa   )
     __a								=       np_speech_inputs.tolist()

     for inputs in [py_speech_inputs, np_speech_inputs]:
       __a								=       feature_extractor.pad([{'input_features': inputs}]   ,				return_tensors='np'   )
       self.assertTrue(np_processed.input_features.dtype == np.floataa   )
       __a								=       feature_extractor.pad([{'input_features': inputs}]   ,				return_tensors='pt'   )
       self.assertTrue(pt_processed.input_features.dtype == torch.floataa   )







   def 		UpperCamelCase__      (						self   ,				UpperCamelCase   )					->     Tuple:
     __a								=       load_dataset('hf-internal-testing/librispeech_asr_dummy'   ,				'clean'   ,				split='validation'   )
     # automatic decoding with librispeech
     __a								=       ds.sort('id'   ).select(range(UpperCamelCase   )   )[:num_samples]['audio']

     return [x["array"] for x in speech_samples]







   def 		UpperCamelCase__      (						self   )					->     int:
     # fmt: off
     __a								=       torch.tensor(
         [
             0.1_193, -0.0_946, -0.1_098, -0.0_196, 0.0_225, -0.0_690, -0.1_736, 0.0_951,
             0.0_971, -0.0_817, -0.0_702, 0.0_162, 0.0_260, 0.0_017, -0.0_192, -0.1_678,
             0.0_709, -0.1_867, -0.0_655, -0.0_274, -0.0_234, -0.1_884, -0.0_516, -0.0_554,
             -0.0_274, -0.1_425, -0.1_423, 0.0_837, 0.0_377, -0.0_854
         ]   )
     # fmt: on

     __a								=       self._load_datasamples(1   )
     __a								=       WhisperFeatureExtractor()
     __a								=       feature_extractor(UpperCamelCase   ,				return_tensors='pt'   ).input_features
     self.assertEqual(input_features.shape   ,				(1, 80, 3000)   )
     self.assertTrue(torch.allclose(input_features[0, 0, :30]   ,				UpperCamelCase   ,				atol=1e-4   )   )







   def 		UpperCamelCase__      (						self   )					->     List[Any]:
     __a								=       self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()   )
     __a								=       self._load_datasamples(1   )[0]
     __a								=       ((audio - audio.min()) / (audio.max() - audio.min())) * 6_5535  # Rescale to [0, 65535] to show issue
     __a								=       feat_extract.zero_mean_unit_var_norm([audio]   ,				attention_mask=UpperCamelCase   )[0]

     self.assertTrue(np.all(np.mean(UpperCamelCase   ) < 1e-3   )   )
     self.assertTrue(np.all(np.abs(np.var(UpperCamelCase   ) - 1   ) < 1e-3   )   )



