




import itertools
from dataclasses import dataclass
from typing import Any, Callable, Dict, List, Optional, Union

import pandas as pd
import pyarrow as pa

import datasets
import datasets.config
from datasets.features.features import require_storage_cast
from datasets.table import table_cast
from datasets.utils.py_utils import Literal


lowerCamelCase__					:  int      							=				datasets.utils.logging.get_logger(__name__)

lowerCamelCase__					:  str      							=				['names', 'prefix']
lowerCamelCase__					:  List[Any]      							=				['warn_bad_lines', 'error_bad_lines', 'mangle_dupe_cols']
lowerCamelCase__					:  Optional[int]      							=				['encoding_errors', 'on_bad_lines']
lowerCamelCase__					:  str      							=				['date_format']





@dataclass
class 			lowerCamelCase_				( datasets.BuilderConfig   ):


 '''simple docstring'''







 lowercase_							       =       ","
 lowercase_							       =       None
 lowercase_							       =       "infer"
 lowercase_							       =       None
 lowercase_							       =       None
 lowercase_							       =       None
 lowercase_							       =       None
 lowercase_							       =       None
 lowercase_							       =       True
 lowercase_							       =       None
 lowercase_							       =       None
 lowercase_							       =       None
 lowercase_							       =       None
 lowercase_							       =       False
 lowercase_							       =       None
 lowercase_							       =       None
 lowercase_							       =       None
 lowercase_							       =       True
 lowercase_							       =       True
 lowercase_							       =       False
 lowercase_							       =       True
 lowercase_							       =       None
 lowercase_							       =       "."
 lowercase_							       =       None
 lowercase_							       =       '"'
 lowercase_							       =       0
 lowercase_							       =       None
 lowercase_							       =       None
 lowercase_							       =       None
 lowercase_							       =       None
 lowercase_							       =       True
 lowercase_							       =       True
 lowercase_							       =       0
 lowercase_							       =       True
 lowercase_							       =       False
 lowercase_							       =       None
 lowercase_							       =       10_000
 lowercase_							       =       None
 lowercase_							       =       "strict"
 lowercase_							       =       "error"
 lowercase_							       =       None



 def  lowerCAmelCase_    (				self    :						Any		):
       if self.delimiter is not None:
             SCREAMING_SNAKE_CASE_      		=     self.delimiter
       if self.column_names is not None:
             SCREAMING_SNAKE_CASE_      		=     self.column_names




 @property
 def  lowerCAmelCase_    (				self    :						Dict		):
       SCREAMING_SNAKE_CASE_      		=     {
           'sep': self.sep,
           'header': self.header,
           'names': self.names,
           'index_col': self.index_col,
           'usecols': self.usecols,
           'prefix': self.prefix,
           'mangle_dupe_cols': self.mangle_dupe_cols,
           'engine': self.engine,
           'converters': self.converters,
           'true_values': self.true_values,
           'false_values': self.false_values,
           'skipinitialspace': self.skipinitialspace,
           'skiprows': self.skiprows,
           'nrows': self.nrows,
           'na_values': self.na_values,
           'keep_default_na': self.keep_default_na,
           'na_filter': self.na_filter,
           'verbose': self.verbose,
           'skip_blank_lines': self.skip_blank_lines,
           'thousands': self.thousands,
           'decimal': self.decimal,
           'lineterminator': self.lineterminator,
           'quotechar': self.quotechar,
           'quoting': self.quoting,
           'escapechar': self.escapechar,
           'comment': self.comment,
           'encoding': self.encoding,
           'dialect': self.dialect,
           'error_bad_lines': self.error_bad_lines,
           'warn_bad_lines': self.warn_bad_lines,
           'skipfooter': self.skipfooter,
           'doublequote': self.doublequote,
           'memory_map': self.memory_map,
           'float_precision': self.float_precision,
           'chunksize': self.chunksize,
           'encoding_errors': self.encoding_errors,
           'on_bad_lines': self.on_bad_lines,
           'date_format': self.date_format,
       }

       # some kwargs must not be passed if they don't have a default value
       # some others are deprecated and we can also not pass them if they are the default value
       for pd_read_csv_parameter in _PANDAS_READ_CSV_NO_DEFAULT_PARAMETERS + _PANDAS_READ_CSV_DEPRECATED_PARAMETERS:
             if pd_read_csv_kwargs[pd_read_csv_parameter] == getattr(CsvConfig()							,							_lowerCAmelCase		):
                   del pd_read_csv_kwargs[pd_read_csv_parameter]

        # Remove 2.0 new arguments
       if not (datasets.config.PANDAS_VERSION.major >= 2):
             for pd_read_csv_parameter in _PANDAS_READ_CSV_NEW_2_0_0_PARAMETERS:
                   del pd_read_csv_kwargs[pd_read_csv_parameter]

        # Remove 1.3 new arguments
       if not (datasets.config.PANDAS_VERSION.major >= 1 and datasets.config.PANDAS_VERSION.minor >= 3):
             for pd_read_csv_parameter in _PANDAS_READ_CSV_NEW_1_3_0_PARAMETERS:
                   del pd_read_csv_kwargs[pd_read_csv_parameter]

       return pd_read_csv_kwargs





class 			lowerCamelCase_				( datasets.ArrowBasedBuilder   ):


 '''simple docstring'''







 lowercase_							       =       CsvConfig



 def  lowerCAmelCase_    (				self    :						Tuple		):
       return datasets.DatasetInfo(features=self.config.features		)



 def  lowerCAmelCase_    (				self    :						str							,							_lowerCAmelCase    :						Optional[int]		):
       if not self.config.data_files:
             raise ValueError(F"At least one data file must be specified, but got data_files={self.config.data_files}"		)
       SCREAMING_SNAKE_CASE_      		=     dl_manager.download_and_extract(self.config.data_files		)
       if isinstance(_lowerCAmelCase							,							(str, list, tuple)		):
             SCREAMING_SNAKE_CASE_      		=     data_files
             if isinstance(_lowerCAmelCase							,							_lowerCAmelCase		):
                   SCREAMING_SNAKE_CASE_      		=     [files]
             SCREAMING_SNAKE_CASE_      		=     [dl_manager.iter_files(_lowerCAmelCase		) for file in files]
             return [datasets.SplitGenerator(name=datasets.Split.TRAIN							,							gen_kwargs={'files': files}		)]
       SCREAMING_SNAKE_CASE_      		=     []
       for split_name, files in data_files.items():
             if isinstance(_lowerCAmelCase							,							_lowerCAmelCase		):
                   SCREAMING_SNAKE_CASE_      		=     [files]
             SCREAMING_SNAKE_CASE_      		=     [dl_manager.iter_files(_lowerCAmelCase		) for file in files]
             splits.append(datasets.SplitGenerator(name=_lowerCAmelCase							,							gen_kwargs={'files': files}		)		)
       return splits



 def  lowerCAmelCase_    (				self    :						List[Any]							,							_lowerCAmelCase    :						pa.Table		):
       if self.config.features is not None:
             SCREAMING_SNAKE_CASE_      		=     self.config.features.arrow_schema
             if all(not require_storage_cast(_lowerCAmelCase		) for feature in self.config.features.values()		):
                   # cheaper cast
                   SCREAMING_SNAKE_CASE_      		=     pa.Table.from_arrays([pa_table[field.name] for field in schema]							,							schema=_lowerCAmelCase		)
             else:
                   # more expensive cast; allows str <-> int/float or str to Audio for example
                   SCREAMING_SNAKE_CASE_      		=     table_cast(_lowerCAmelCase							,							_lowerCAmelCase		)
       return pa_table




 def  lowerCAmelCase_    (				self    :						List[str]							,							_lowerCAmelCase    :						Optional[Any]		):
       SCREAMING_SNAKE_CASE_      		=     self.config.features.arrow_schema if self.config.features else None
       # dtype allows reading an int column as str
       SCREAMING_SNAKE_CASE_      		=     (
           {
               name: dtype.to_pandas_dtype() if not require_storage_cast(_lowerCAmelCase		) else object
               for name, dtype, feature in zip(schema.names							,							schema.types							,							self.config.features.values()		)
           }
           if schema is not None
           else None
       )
       for file_idx, file in enumerate(itertools.chain.from_iterable(_lowerCAmelCase		)		):
             SCREAMING_SNAKE_CASE_      		=     pd.read_csv(_lowerCAmelCase							,							iterator=_lowerCAmelCase							,							dtype=_lowerCAmelCase							,							**self.config.pd_read_csv_kwargs		)
             try:
                   for batch_idx, df in enumerate(_lowerCAmelCase		):
                         SCREAMING_SNAKE_CASE_      		=     pa.Table.from_pandas(_lowerCAmelCase		)
                         # Uncomment for debugging (will print the Arrow table size and elements)
                         # logger.warning(f"pa_table: {pa_table} num rows: {pa_table.num_rows}")
                         # logger.warning('\n'.join(str(pa_table.slice(i, 1).to_pydict()) for i in range(pa_table.num_rows)))
                         yield (file_idx, batch_idx), self._cast_table(_lowerCAmelCase		)
             except ValueError as e:
                   logger.error(F"Failed to read file '{file}' with error {type(_lowerCAmelCase		)}: {e}"		)
                   raise





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		)		)