




from scipy.stats import pearsonr

import datasets


lowerCamelCase__					:  Any      							=				'\nPearson correlation coefficient and p-value for testing non-correlation.\nThe Pearson correlation coefficient measures the linear relationship between two datasets. The calculation of the p-value relies on the assumption that each dataset is normally distributed. Like other correlation coefficients, this one varies between -1 and +1 with 0 implying no correlation. Correlations of -1 or +1 imply an exact linear relationship. Positive correlations imply that as x increases, so does y. Negative correlations imply that as x increases, y decreases.\nThe p-value roughly indicates the probability of an uncorrelated system producing datasets that have a Pearson correlation at least as extreme as the one computed from these datasets.\n'


lowerCamelCase__					:  Any      							=				'\nArgs:\n    predictions (`list` of `int`): Predicted class labels, as returned by a model.\n    references (`list` of `int`): Ground truth labels.\n    return_pvalue (`boolean`): If `True`, returns the p-value, along with the correlation coefficient. If `False`, returns only the correlation coefficient. Defaults to `False`.\n\nReturns:\n    pearsonr (`float`): Pearson correlation coefficient. Minimum possible value is -1. Maximum possible value is 1. Values of 1 and -1 indicate exact linear positive and negative relationships, respectively. A value of 0 implies no correlation.\n    p-value (`float`): P-value, which roughly indicates the probability of an The p-value roughly indicates the probability of an uncorrelated system producing datasets that have a Pearson correlation at least as extreme as the one computed from these datasets. Minimum possible value is 0. Maximum possible value is 1. Higher values indicate higher probabilities.\n\nExamples:\n\n    Example 1-A simple example using only predictions and references.\n        >>> pearsonr_metric = datasets.load_metric("pearsonr")\n        >>> results = pearsonr_metric.compute(predictions=[10, 9, 2.5, 6, 4], references=[1, 2, 3, 4, 5])\n        >>> print(round(results[\'pearsonr\'], 2))\n        -0.74\n\n    Example 2-The same as Example 1, but that also returns the `p-value`.\n        >>> pearsonr_metric = datasets.load_metric("pearsonr")\n        >>> results = pearsonr_metric.compute(predictions=[10, 9, 2.5, 6, 4], references=[1, 2, 3, 4, 5], return_pvalue=True)\n        >>> print(sorted(list(results.keys())))\n        [\'p-value\', \'pearsonr\']\n        >>> print(round(results[\'pearsonr\'], 2))\n        -0.74\n        >>> print(round(results[\'p-value\'], 2))\n        0.15\n'


lowerCamelCase__					:  Union[str, Any]      							=				'\n@article{2020SciPy-NMeth,\nauthor  = {Virtanen, Pauli and Gommers, Ralf and Oliphant, Travis E. and\n      Haberland, Matt and Reddy, Tyler and Cournapeau, David and\n      Burovski, Evgeni and Peterson, Pearu and Weckesser, Warren and\n      Bright, Jonathan and {van der Walt}, St{\'e}fan J. and\n      Brett, Matthew and Wilson, Joshua and Millman, K. Jarrod and\n      Mayorov, Nikolay and Nelson, Andrew R. J. and Jones, Eric and\n      Kern, Robert and Larson, Eric and Carey, C J and\n      Polat, Ilhan and Feng, Yu and Moore, Eric W. and\n      {VanderPlas}, Jake and Laxalde, Denis and Perktold, Josef and\n      Cimrman, Robert and Henriksen, Ian and Quintero, E. A. and\n      Harris, Charles R. and Archibald, Anne M. and\n      Ribeiro, Antonio H. and Pedregosa, Fabian and\n      {van Mulbregt}, Paul and {SciPy 1.0 Contributors}},\ntitle   = {{{SciPy} 1.0: Fundamental Algorithms for Scientific\n      Computing in Python}},\njournal = {Nature Methods},\nyear    = {2020},\nvolume  = {17},\npages   = {261--272},\nadsurl  = {https://rdcu.be/b08Wh},\ndoi = {10.1038/s41592-019-0686-2},\n}\n'





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


 '''simple docstring'''







 def  lowerCAmelCase_    (				self    :						List[Any]		):
       return datasets.MetricInfo(
           description=_DESCRIPTION							,							citation=_CITATION							,							inputs_description=_KWARGS_DESCRIPTION							,							features=datasets.Features(
               {
                   'predictions': datasets.Value('float'		),
                   'references': datasets.Value('float'		),
               }		)							,							reference_urls=['https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.pearsonr.html']							,							)




 def  lowerCAmelCase_    (				self    :						Any							,							_lowerCAmelCase    :						List[Any]							,							_lowerCAmelCase    :						Tuple							,							_lowerCAmelCase    :						List[str]=False		):
       if return_pvalue:
             SCREAMING_SNAKE_CASE_      		=     pearsonr(_lowerCAmelCase							,							_lowerCAmelCase		)
             return {"pearsonr": results[0], "p-value": results[1]}
       else:
             return {"pearsonr": float(pearsonr(_lowerCAmelCase							,							_lowerCAmelCase		)[0]		)}





import itertools
import random
import unittest

import numpy as np

from transformers import BatchFeature, SpeechTaFeatureExtractor
from transformers.testing_utils import require_torch
from transformers.utils.import_utils import is_torch_available

from ...test_sequence_feature_extraction_common import SequenceFeatureExtractionTestMixin


if is_torch_available():
   import torch


lowerCamelCase__					:  Dict      							=				random.Random()

def    UpperCAmelCase_				( __UpperCAmelCase		:      int     ,     __UpperCAmelCase		:      Tuple=1.0     ,     __UpperCAmelCase		:      Dict=None     ,     __UpperCAmelCase		:      Dict=None				)   ->					Tuple:
      if rng is None:
            SCREAMING_SNAKE_CASE_      		=     global_rng

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

      return values





@require_torch
class 			lowerCamelCase_				( unittest.TestCase   ):


 '''simple docstring'''







 def __init__(				self    :						List[str]							,							_lowerCAmelCase    :						int							,							_lowerCAmelCase    :						Optional[Any]=7							,							_lowerCAmelCase    :						Union[str, Any]=400							,							_lowerCAmelCase    :						Tuple=2_000							,							_lowerCAmelCase    :						str=1							,							_lowerCAmelCase    :						int=0.0							,							_lowerCAmelCase    :						Optional[Any]=16_000							,							_lowerCAmelCase    :						Optional[Any]=True							,							_lowerCAmelCase    :						Any=80							,							_lowerCAmelCase    :						Union[str, Any]=16							,							_lowerCAmelCase    :						List[str]=64							,							_lowerCAmelCase    :						List[Any]="hann_window"							,							_lowerCAmelCase    :						Any=80							,							_lowerCAmelCase    :						List[Any]=7_600							,							_lowerCAmelCase    :						List[Any]=1E-10							,							_lowerCAmelCase    :						Optional[Any]=True							,							):
       SCREAMING_SNAKE_CASE_      		=     parent
       SCREAMING_SNAKE_CASE_      		=     batch_size
       SCREAMING_SNAKE_CASE_      		=     min_seq_length
       SCREAMING_SNAKE_CASE_      		=     max_seq_length
       SCREAMING_SNAKE_CASE_      		=     (self.max_seq_length - self.min_seq_length) // (self.batch_size - 1)
       SCREAMING_SNAKE_CASE_      		=     feature_size
       SCREAMING_SNAKE_CASE_      		=     padding_value
       SCREAMING_SNAKE_CASE_      		=     sampling_rate
       SCREAMING_SNAKE_CASE_      		=     do_normalize
       SCREAMING_SNAKE_CASE_      		=     num_mel_bins
       SCREAMING_SNAKE_CASE_      		=     hop_length
       SCREAMING_SNAKE_CASE_      		=     win_length
       SCREAMING_SNAKE_CASE_      		=     win_function
       SCREAMING_SNAKE_CASE_      		=     fmin
       SCREAMING_SNAKE_CASE_      		=     fmax
       SCREAMING_SNAKE_CASE_      		=     mel_floor
       SCREAMING_SNAKE_CASE_      		=     return_attention_mask



 def  lowerCAmelCase_    (				self    :						Union[str, Any]		):
       return {
           "feature_size": self.feature_size,
           "padding_value": self.padding_value,
           "sampling_rate": self.sampling_rate,
           "do_normalize": self.do_normalize,
           "num_mel_bins": self.num_mel_bins,
           "hop_length": self.hop_length,
           "win_length": self.win_length,
           "win_function": self.win_function,
           "fmin": self.fmin,
           "fmax": self.fmax,
           "mel_floor": self.mel_floor,
           "return_attention_mask": self.return_attention_mask,
       }



 def  lowerCAmelCase_    (				self    :						Dict							,							_lowerCAmelCase    :						Optional[int]=False							,							_lowerCAmelCase    :						str=False		):
       def _flatten(_lowerCAmelCase    :						Dict		):
             return list(itertools.chain(*_lowerCAmelCase		)		)

       if equal_length:
             SCREAMING_SNAKE_CASE_      		=     floats_list((self.batch_size, self.max_seq_length)		)
       else:
             # make sure that inputs increase in size
             SCREAMING_SNAKE_CASE_      		=     [
                 _flatten(floats_list((x, self.feature_size)		)		)
                 for x in range(self.min_seq_length							,							self.max_seq_length							,							self.seq_length_diff		)
             ]

       if numpify:
             SCREAMING_SNAKE_CASE_      		=     [np.asarray(_lowerCAmelCase		) for x in speech_inputs]

       return speech_inputs




 def  lowerCAmelCase_    (				self    :						List[Any]							,							_lowerCAmelCase    :						Union[str, Any]=False							,							_lowerCAmelCase    :						Optional[int]=False		):
       if equal_length:
             SCREAMING_SNAKE_CASE_      		=     [floats_list((self.max_seq_length, self.num_mel_bins)		) for _ in range(self.batch_size		)]
       else:
             # make sure that inputs increase in size
             SCREAMING_SNAKE_CASE_      		=     [
                 floats_list((x, self.num_mel_bins)		)
                 for x in range(self.min_seq_length							,							self.max_seq_length							,							self.seq_length_diff		)
             ]

       if numpify:
             SCREAMING_SNAKE_CASE_      		=     [np.asarray(_lowerCAmelCase		) for x in speech_inputs]

       return speech_inputs





@require_torch
class 			lowerCamelCase_				( _SCREAMING_SNAKE_CASE			,  unittest.TestCase   ):


 '''simple docstring'''







 lowercase_							       =       SpeechTaFeatureExtractor



 def  lowerCAmelCase_    (				self    :						Any		):
       SCREAMING_SNAKE_CASE_      		=     SpeechTaFeatureExtractionTester(self		)



 def  lowerCAmelCase_    (				self    :						Any							,							_lowerCAmelCase    :						int		):
       self.assertTrue(np.all(np.mean(_lowerCAmelCase							,							axis=0		) < 1E-3		)		)
       self.assertTrue(np.all(np.abs(np.var(_lowerCAmelCase							,							axis=0		) - 1		) < 1E-3		)		)



 def  lowerCAmelCase_    (				self    :						List[Any]		):
       # Tests that all call wrap to encode_plus and batch_encode_plus
       SCREAMING_SNAKE_CASE_      		=     self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()		)
       # create three inputs of length 800, 1000, and 1200
       SCREAMING_SNAKE_CASE_      		=     [floats_list((1, x)		)[0] for x in range(800							,							1_400							,							200		)]
       SCREAMING_SNAKE_CASE_      		=     [np.asarray(_lowerCAmelCase		) for speech_input in speech_inputs]

       # Test not batched input
       SCREAMING_SNAKE_CASE_      		=     feat_extract(speech_inputs[0]							,							return_tensors='np'		).input_values
       SCREAMING_SNAKE_CASE_      		=     feat_extract(np_speech_inputs[0]							,							return_tensors='np'		).input_values
       self.assertTrue(np.allclose(_lowerCAmelCase							,							_lowerCAmelCase							,							atol=1E-3		)		)

       # Test batched
       SCREAMING_SNAKE_CASE_      		=     feat_extract(_lowerCAmelCase							,							return_tensors='np'		).input_values
       SCREAMING_SNAKE_CASE_      		=     feat_extract(_lowerCAmelCase							,							return_tensors='np'		).input_values
       for enc_seq_a, enc_seq_a in zip(_lowerCAmelCase							,							_lowerCAmelCase		):
             self.assertTrue(np.allclose(_lowerCAmelCase							,							_lowerCAmelCase							,							atol=1E-3		)		)



 def  lowerCAmelCase_    (				self    :						Union[str, Any]		):
       SCREAMING_SNAKE_CASE_      		=     self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()		)
       SCREAMING_SNAKE_CASE_      		=     [floats_list((1, x)		)[0] for x in range(800							,							1_400							,							200		)]

       SCREAMING_SNAKE_CASE_      		=     ['longest', 'max_length', 'do_not_pad']
       SCREAMING_SNAKE_CASE_      		=     [None, 1_600, None]
       for max_length, padding in zip(_lowerCAmelCase							,							_lowerCAmelCase		):
             SCREAMING_SNAKE_CASE_      		=     feat_extract(_lowerCAmelCase							,							padding=_lowerCAmelCase							,							max_length=_lowerCAmelCase							,							return_tensors='np'		)
             SCREAMING_SNAKE_CASE_      		=     processed.input_values

             self._check_zero_mean_unit_variance(input_values[0][:800]		)
             self.assertTrue(input_values[0][800:].sum() < 1E-6		)
             self._check_zero_mean_unit_variance(input_values[1][:1_000]		)
             self.assertTrue(input_values[0][1_000:].sum() < 1E-6		)
             self._check_zero_mean_unit_variance(input_values[2][:1_200]		)



 def  lowerCAmelCase_    (				self    :						Optional[Any]		):
       SCREAMING_SNAKE_CASE_      		=     self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()		)
       SCREAMING_SNAKE_CASE_      		=     range(800							,							1_400							,							200		)
       SCREAMING_SNAKE_CASE_      		=     [floats_list((1, x)		)[0] for x in lengths]

       SCREAMING_SNAKE_CASE_      		=     ['longest', 'max_length', 'do_not_pad']
       SCREAMING_SNAKE_CASE_      		=     [None, 1_600, None]

       for max_length, padding in zip(_lowerCAmelCase							,							_lowerCAmelCase		):
             SCREAMING_SNAKE_CASE_      		=     feat_extract(_lowerCAmelCase							,							max_length=_lowerCAmelCase							,							padding=_lowerCAmelCase		)
             SCREAMING_SNAKE_CASE_      		=     processed.input_values

             self._check_zero_mean_unit_variance(input_values[0][:800]		)
             self._check_zero_mean_unit_variance(input_values[1][:1_000]		)
             self._check_zero_mean_unit_variance(input_values[2][:1_200]		)



 def  lowerCAmelCase_    (				self    :						Dict		):
       SCREAMING_SNAKE_CASE_      		=     self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()		)
       SCREAMING_SNAKE_CASE_      		=     [floats_list((1, x)		)[0] for x in range(800							,							1_400							,							200		)]
       SCREAMING_SNAKE_CASE_      		=     feat_extract(
           _lowerCAmelCase							,							truncation=_lowerCAmelCase							,							max_length=1_000							,							padding='max_length'							,							return_tensors='np'		)
       SCREAMING_SNAKE_CASE_      		=     processed.input_values

       self._check_zero_mean_unit_variance(input_values[0, :800]		)
       self._check_zero_mean_unit_variance(input_values[1]		)
       self._check_zero_mean_unit_variance(input_values[2]		)



 def  lowerCAmelCase_    (				self    :						Dict		):
       SCREAMING_SNAKE_CASE_      		=     self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()		)
       SCREAMING_SNAKE_CASE_      		=     [floats_list((1, x)		)[0] for x in range(800							,							1_400							,							200		)]
       SCREAMING_SNAKE_CASE_      		=     feat_extract(
           _lowerCAmelCase							,							truncation=_lowerCAmelCase							,							max_length=1_000							,							padding='longest'							,							return_tensors='np'		)
       SCREAMING_SNAKE_CASE_      		=     processed.input_values

       self._check_zero_mean_unit_variance(input_values[0, :800]		)
       self._check_zero_mean_unit_variance(input_values[1, :1_000]		)
       self._check_zero_mean_unit_variance(input_values[2]		)

       # make sure that if max_length < longest -> then pad to max_length
       self.assertTrue(input_values.shape == (3, 1_000)		)

       SCREAMING_SNAKE_CASE_      		=     [floats_list((1, x)		)[0] for x in range(800							,							1_400							,							200		)]
       SCREAMING_SNAKE_CASE_      		=     feat_extract(
           _lowerCAmelCase							,							truncation=_lowerCAmelCase							,							max_length=2_000							,							padding='longest'							,							return_tensors='np'		)
       SCREAMING_SNAKE_CASE_      		=     processed.input_values

       self._check_zero_mean_unit_variance(input_values[0, :800]		)
       self._check_zero_mean_unit_variance(input_values[1, :1_000]		)
       self._check_zero_mean_unit_variance(input_values[2]		)

       # make sure that if max_length > longest -> then pad to longest
       self.assertTrue(input_values.shape == (3, 1_200)		)



 def  lowerCAmelCase_    (				self    :						Optional[int]		):
       SCREAMING_SNAKE_CASE_      		=     self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()		)
       SCREAMING_SNAKE_CASE_      		=     np.random.rand(100		).astype(np.floataa		)
       SCREAMING_SNAKE_CASE_      		=     np_speech_inputs.tolist()

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



 def  lowerCAmelCase_    (				self    :						Tuple		):
       # Tests that all call wrap to encode_plus and batch_encode_plus
       SCREAMING_SNAKE_CASE_      		=     self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()		)
       # create three inputs of length 800, 1000, and 1200
       SCREAMING_SNAKE_CASE_      		=     [floats_list((1, x)		)[0] for x in range(800							,							1_400							,							200		)]
       SCREAMING_SNAKE_CASE_      		=     [np.asarray(_lowerCAmelCase		) for speech_input in speech_inputs]

       # Test feature size
       SCREAMING_SNAKE_CASE_      		=     feature_extractor(audio_target=_lowerCAmelCase							,							padding=_lowerCAmelCase							,							return_tensors='np'		).input_values
       self.assertTrue(input_values.ndim == 3		)
       self.assertTrue(input_values.shape[-1] == feature_extractor.num_mel_bins		)

       # Test not batched input
       SCREAMING_SNAKE_CASE_      		=     feature_extractor(speech_inputs[0]							,							return_tensors='np'		).input_values
       SCREAMING_SNAKE_CASE_      		=     feature_extractor(np_speech_inputs[0]							,							return_tensors='np'		).input_values
       self.assertTrue(np.allclose(_lowerCAmelCase							,							_lowerCAmelCase							,							atol=1E-3		)		)

       # Test batched
       SCREAMING_SNAKE_CASE_      		=     feature_extractor(_lowerCAmelCase							,							return_tensors='np'		).input_values
       SCREAMING_SNAKE_CASE_      		=     feature_extractor(_lowerCAmelCase							,							return_tensors='np'		).input_values
       for enc_seq_a, enc_seq_a in zip(_lowerCAmelCase							,							_lowerCAmelCase		):
             self.assertTrue(np.allclose(_lowerCAmelCase							,							_lowerCAmelCase							,							atol=1E-3		)		)

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



 def  lowerCAmelCase_    (				self    :						str		):
       SCREAMING_SNAKE_CASE_      		=     self.feat_extract_tester.prepare_inputs_for_target()
       SCREAMING_SNAKE_CASE_      		=     self.feature_extraction_class(**self.feat_extract_dict		)
       SCREAMING_SNAKE_CASE_      		=     feat_extract.model_input_names[0]

       SCREAMING_SNAKE_CASE_      		=     BatchFeature({input_name: speech_inputs}		)

       self.assertTrue(all(len(_lowerCAmelCase		) == len(_lowerCAmelCase		) for x, y in zip(_lowerCAmelCase							,							processed_features[input_name]		)		)		)

       SCREAMING_SNAKE_CASE_      		=     self.feat_extract_tester.prepare_inputs_for_target(equal_length=_lowerCAmelCase		)
       SCREAMING_SNAKE_CASE_      		=     BatchFeature({input_name: speech_inputs}							,							tensor_type='np'		)

       SCREAMING_SNAKE_CASE_      		=     processed_features[input_name]

       if len(batch_features_input.shape		) < 3:
             SCREAMING_SNAKE_CASE_      		=     batch_features_input[:, :, None]

       self.assertTrue(
           batch_features_input.shape
           == (self.feat_extract_tester.batch_size, len(speech_inputs[0]		), self.feat_extract_tester.num_mel_bins)		)



 @require_torch
 def  lowerCAmelCase_    (				self    :						Dict		):
       SCREAMING_SNAKE_CASE_      		=     self.feat_extract_tester.prepare_inputs_for_target(equal_length=_lowerCAmelCase		)
       SCREAMING_SNAKE_CASE_      		=     self.feature_extraction_class(**self.feat_extract_dict		)
       SCREAMING_SNAKE_CASE_      		=     feat_extract.model_input_names[0]

       SCREAMING_SNAKE_CASE_      		=     BatchFeature({input_name: speech_inputs}							,							tensor_type='pt'		)

       SCREAMING_SNAKE_CASE_      		=     processed_features[input_name]

       if len(batch_features_input.shape		) < 3:
             SCREAMING_SNAKE_CASE_      		=     batch_features_input[:, :, None]

       self.assertTrue(
           batch_features_input.shape
           == (self.feat_extract_tester.batch_size, len(speech_inputs[0]		), self.feat_extract_tester.num_mel_bins)		)



 @require_torch
 def  lowerCAmelCase_    (				self    :						Dict		):
       SCREAMING_SNAKE_CASE_      		=     self.feature_extraction_class(**self.feat_extract_dict		)
       SCREAMING_SNAKE_CASE_      		=     self.feat_extract_tester.prepare_inputs_for_target()
       SCREAMING_SNAKE_CASE_      		=     feat_extract.model_input_names[0]

       SCREAMING_SNAKE_CASE_      		=     BatchFeature({input_name: speech_inputs}		)

       SCREAMING_SNAKE_CASE_      		=     feat_extract.num_mel_bins  # hack!

       SCREAMING_SNAKE_CASE_      		=     feat_extract.pad(_lowerCAmelCase							,							padding='longest'							,							return_tensors='np'		)[input_name]
       SCREAMING_SNAKE_CASE_      		=     feat_extract.pad(_lowerCAmelCase							,							padding='longest'							,							return_tensors='pt'		)[input_name]

       self.assertTrue(abs(input_np.astype(np.floataa		).sum() - input_pt.numpy().astype(np.floataa		).sum()		) < 1E-2		)



 def  lowerCAmelCase_    (				self    :						str		):
       SCREAMING_SNAKE_CASE_      		=     self.feat_extract_dict
       SCREAMING_SNAKE_CASE_      		=     True
       SCREAMING_SNAKE_CASE_      		=     self.feature_extraction_class(**_lowerCAmelCase		)
       SCREAMING_SNAKE_CASE_      		=     self.feat_extract_tester.prepare_inputs_for_target()
       SCREAMING_SNAKE_CASE_      		=     [len(_lowerCAmelCase		) for x in speech_inputs]
       SCREAMING_SNAKE_CASE_      		=     feat_extract.model_input_names[0]

       SCREAMING_SNAKE_CASE_      		=     BatchFeature({input_name: speech_inputs}		)

       SCREAMING_SNAKE_CASE_      		=     feat_extract.num_mel_bins  # hack!

       SCREAMING_SNAKE_CASE_      		=     feat_extract.pad(_lowerCAmelCase							,							padding='longest'							,							return_tensors='np'		)
       self.assertIn('attention_mask'							,							_lowerCAmelCase		)
       self.assertListEqual(list(processed.attention_mask.shape		)							,							list(processed[input_name].shape[:2]		)		)
       self.assertListEqual(processed.attention_mask.sum(-1		).tolist()							,							_lowerCAmelCase		)



 def  lowerCAmelCase_    (				self    :						Any		):
       SCREAMING_SNAKE_CASE_      		=     self.feat_extract_dict
       SCREAMING_SNAKE_CASE_      		=     True
       SCREAMING_SNAKE_CASE_      		=     self.feature_extraction_class(**_lowerCAmelCase		)
       SCREAMING_SNAKE_CASE_      		=     self.feat_extract_tester.prepare_inputs_for_target()
       SCREAMING_SNAKE_CASE_      		=     [len(_lowerCAmelCase		) for x in speech_inputs]
       SCREAMING_SNAKE_CASE_      		=     feat_extract.model_input_names[0]

       SCREAMING_SNAKE_CASE_      		=     BatchFeature({input_name: speech_inputs}		)
       SCREAMING_SNAKE_CASE_      		=     min(_lowerCAmelCase		)

       SCREAMING_SNAKE_CASE_      		=     feat_extract.num_mel_bins  # hack!

       SCREAMING_SNAKE_CASE_      		=     feat_extract.pad(
           _lowerCAmelCase							,							padding='max_length'							,							max_length=_lowerCAmelCase							,							truncation=_lowerCAmelCase							,							return_tensors='np'		)
       self.assertIn('attention_mask'							,							_lowerCAmelCase		)
       self.assertListEqual(
           list(processed_pad.attention_mask.shape		)							,							[processed_pad[input_name].shape[0], max_length]		)
       self.assertListEqual(
           processed_pad.attention_mask[:, :max_length].sum(-1		).tolist()							,							[max_length for x in speech_inputs]		)



 def  lowerCAmelCase_    (				self    :						List[Any]							,							_lowerCAmelCase    :						Tuple		):
       from datasets import load_dataset

       SCREAMING_SNAKE_CASE_      		=     load_dataset('hf-internal-testing/librispeech_asr_dummy'							,							'clean'							,							split='validation'		)
       # automatic decoding with librispeech
       SCREAMING_SNAKE_CASE_      		=     ds.sort('id'		).select(range(_lowerCAmelCase		)		)[:num_samples]['audio']

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



 def  lowerCAmelCase_    (				self    :						Any		):
       # fmt: off
       SCREAMING_SNAKE_CASE_      		=     torch.tensor(
           [2.3_804E-03, 2.0_752E-03, 1.9_836E-03, 2.1_057E-03, 1.6_174E-03,
            3.0_518E-04, 9.1_553E-05, 3.3_569E-04, 9.7_656E-04, 1.8_311E-03,
            2.0_142E-03, 2.1_057E-03, 1.7_395E-03, 4.5_776E-04, -3.9_673E-04,
            4.5_776E-04, 1.0_071E-03, 9.1_553E-05, 4.8_828E-04, 1.1_597E-03,
            7.3_242E-04, 9.4_604E-04, 1.8_005E-03, 1.8_311E-03, 8.8_501E-04,
            4.2_725E-04, 4.8_828E-04, 7.3_242E-04, 1.0_986E-03, 2.1_057E-03]		)
       # fmt: on

       SCREAMING_SNAKE_CASE_      		=     self._load_datasamples(1		)
       SCREAMING_SNAKE_CASE_      		=     SpeechTaFeatureExtractor()
       SCREAMING_SNAKE_CASE_      		=     feature_extractor(_lowerCAmelCase							,							return_tensors='pt'		).input_values
       self.assertEquals(input_values.shape							,							(1, 93_680)		)
       self.assertTrue(torch.allclose(input_values[0, :30]							,							_lowerCAmelCase							,							atol=1E-6		)		)




 def  lowerCAmelCase_    (				self    :						Optional[int]		):
       # fmt: off
       SCREAMING_SNAKE_CASE_      		=     torch.tensor(
           [-2.6870, -3.0104, -3.1356, -3.5352, -3.0044, -3.0353, -3.4719, -3.6777,
            -3.1520, -2.9435, -2.6553, -2.8795, -2.9944, -2.5921, -3.0279, -3.0386,
            -3.0864, -3.1291, -3.2353, -2.7444, -2.6831, -2.7287, -3.1761, -3.1571,
            -3.2726, -3.0582, -3.1007, -3.4533, -3.4695, -3.0998]		)
       # fmt: on

       SCREAMING_SNAKE_CASE_      		=     self._load_datasamples(1		)
       SCREAMING_SNAKE_CASE_      		=     SpeechTaFeatureExtractor()
       SCREAMING_SNAKE_CASE_      		=     feature_extractor(audio_target=_lowerCAmelCase							,							return_tensors='pt'		).input_values
       self.assertEquals(input_values.shape							,							(1, 366, 80)		)
       self.assertTrue(torch.allclose(input_values[0, 0, :30]							,							_lowerCAmelCase							,							atol=1E-4		)		)