


import unittest

from transformers import DebertaVaTokenizer, DebertaVaTokenizerFast
from transformers.testing_utils import get_tests_dir, require_sentencepiece, require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin


SCREAMING_SNAKE_CASE						:Optional[Any]			=  get_tests_dir('''fixtures/spiece.model''')


@require_sentencepiece
@require_tokenizers
class      __lowerCAmelCase  (			a			,	unittest.TestCase       ):






  """simple docstring"""





  _SCREAMING_SNAKE_CASE		     =							DebertaVaTokenizer
  _SCREAMING_SNAKE_CASE		     =							DebertaVaTokenizerFast
  _SCREAMING_SNAKE_CASE		     =							True
  _SCREAMING_SNAKE_CASE		     =							True



  def        lowerCAmelCase__	(  self							:							Union[str, Any]	) ->			List[Any]:




     """simple docstring"""
     super().setUp()

     # We have a SentencePiece fixture for testing
     snake_case_            =       DebertaVaTokenizer(_lowerCAmelCase     ,					unk_token="<unk>"	)
     tokenizer.save_pretrained(self.tmpdirname	)



  def        lowerCAmelCase__	(  self							:							Union[str, Any]     ,					_lowerCAmelCase							:							Optional[int]	) ->			Any:




     """simple docstring"""
     snake_case_            =       "this is a test"
     snake_case_            =       "this is a test"
     return input_text, output_text



  def        lowerCAmelCase__	(  self							:							List[str]	) ->			Optional[int]:




     """simple docstring"""
     snake_case_            =       "<pad>"
     snake_case_            =       0

     self.assertEqual(self.get_tokenizer()._convert_token_to_id(_lowerCAmelCase	)     ,					_lowerCAmelCase	)
     self.assertEqual(self.get_tokenizer()._convert_id_to_token(_lowerCAmelCase	)     ,					_lowerCAmelCase	)



  def        lowerCAmelCase__	(  self							:							str	) ->			Any:




     """simple docstring"""
     snake_case_            =       list(self.get_tokenizer().get_vocab().keys()	)
     self.assertEqual(vocab_keys[0]     ,					"<pad>"	)
     self.assertEqual(vocab_keys[1]     ,					"<unk>"	)
     self.assertEqual(vocab_keys[-1]     ,					"[PAD]"	)
     self.assertEqual(len(_lowerCAmelCase	)     ,					3_0_0_0_1	)



  def        lowerCAmelCase__	(  self							:							List[Any]	) ->			Optional[Any]:




     """simple docstring"""
     self.assertEqual(self.get_tokenizer().vocab_size     ,					3_0_0_0_0	)



  def        lowerCAmelCase__	(  self							:							Any	) ->			str:




     """simple docstring"""
     # fmt: off
     snake_case_            =       " \tHeLLo!how  \n Are yoU?  "
     snake_case_            =       ["▁hello", "!", "how", "▁are", "▁you", "?"]
     # fmt: on

     snake_case_            =       DebertaVaTokenizer(_lowerCAmelCase     ,					do_lower_case=_lowerCAmelCase	)
     snake_case_            =       tokenizer.convert_ids_to_tokens(tokenizer.encode(_lowerCAmelCase     ,					add_special_tokens=_lowerCAmelCase	)	)

     self.assertListEqual(_lowerCAmelCase     ,					_lowerCAmelCase	)

     snake_case_            =       DebertaVaTokenizerFast(_lowerCAmelCase     ,					do_lower_case=_lowerCAmelCase	)
     snake_case_            =       rust_tokenizer.convert_ids_to_tokens(rust_tokenizer.encode(_lowerCAmelCase     ,					add_special_tokens=_lowerCAmelCase	)	)

     self.assertListEqual(_lowerCAmelCase     ,					_lowerCAmelCase	)



  @unittest.skip("There is an inconsistency between slow and fast tokenizer due to a bug in the fast one."	)
  def        lowerCAmelCase__	(  self							:							List[Any]	) ->			Union[str, Any]:




     """simple docstring"""
     pass



  @unittest.skip("There is an inconsistency between slow and fast tokenizer due to a bug in the fast one."	)
  def        lowerCAmelCase__	(  self							:							List[Any]	) ->			Any:




     """simple docstring"""
     pass



  def        lowerCAmelCase__	(  self							:							int	) ->			List[Any]:




     """simple docstring"""
     # fmt: off
     snake_case_            =       "I was born in 92000, and this is falsé."
     snake_case_            =       ["▁", "<unk>", "▁was", "▁born", "▁in", "▁9", "2000", "▁", ",", "▁and", "▁this", "▁is", "▁fal", "s", "<unk>", "▁", ".", ]
     # fmt: on

     snake_case_            =       DebertaVaTokenizer(_lowerCAmelCase     ,					split_by_punct=_lowerCAmelCase	)
     snake_case_            =       tokenizer.convert_ids_to_tokens(tokenizer.encode(_lowerCAmelCase     ,					add_special_tokens=_lowerCAmelCase	)	)

     self.assertListEqual(_lowerCAmelCase     ,					_lowerCAmelCase	)

     snake_case_            =       DebertaVaTokenizerFast(_lowerCAmelCase     ,					split_by_punct=_lowerCAmelCase	)
     snake_case_            =       rust_tokenizer.convert_ids_to_tokens(rust_tokenizer.encode(_lowerCAmelCase     ,					add_special_tokens=_lowerCAmelCase	)	)

     self.assertListEqual(_lowerCAmelCase     ,					_lowerCAmelCase	)



  def        lowerCAmelCase__	(  self							:							Union[str, Any]	) ->			List[str]:




     """simple docstring"""
     # fmt: off
     snake_case_            =       "I was born in 92000, and this is falsé."
     snake_case_            =       ["▁i", "▁was", "▁born", "▁in", "▁9", "2000", "▁", ",", "▁and", "▁this", "▁is", "▁fal", "s", "<unk>", "▁", ".", ]
     # fmt: on

     snake_case_            =       DebertaVaTokenizer(_lowerCAmelCase     ,					do_lower_case=_lowerCAmelCase     ,					split_by_punct=_lowerCAmelCase	)
     snake_case_            =       tokenizer.convert_ids_to_tokens(tokenizer.encode(_lowerCAmelCase     ,					add_special_tokens=_lowerCAmelCase	)	)
     self.assertListEqual(_lowerCAmelCase     ,					_lowerCAmelCase	)

     snake_case_            =       DebertaVaTokenizerFast(_lowerCAmelCase     ,					do_lower_case=_lowerCAmelCase     ,					split_by_punct=_lowerCAmelCase	)
     snake_case_            =       rust_tokenizer.convert_ids_to_tokens(rust_tokenizer.encode(_lowerCAmelCase     ,					add_special_tokens=_lowerCAmelCase	)	)
     self.assertListEqual(_lowerCAmelCase     ,					_lowerCAmelCase	)



  def        lowerCAmelCase__	(  self							:							Any	) ->			str:




     """simple docstring"""
     # fmt: off
     snake_case_            =       "I was born in 92000, and this is falsé."
     snake_case_            =       ["▁i", "▁was", "▁born", "▁in", "▁9", "2000", ",", "▁and", "▁this", "▁is", "▁fal", "s", "<unk>", ".", ]
     # fmt: on

     snake_case_            =       DebertaVaTokenizer(_lowerCAmelCase     ,					do_lower_case=_lowerCAmelCase     ,					split_by_punct=_lowerCAmelCase	)
     snake_case_            =       tokenizer.convert_ids_to_tokens(tokenizer.encode(_lowerCAmelCase     ,					add_special_tokens=_lowerCAmelCase	)	)

     self.assertListEqual(_lowerCAmelCase     ,					_lowerCAmelCase	)

     snake_case_            =       DebertaVaTokenizerFast(_lowerCAmelCase     ,					do_lower_case=_lowerCAmelCase     ,					split_by_punct=_lowerCAmelCase	)
     snake_case_            =       rust_tokenizer.convert_ids_to_tokens(rust_tokenizer.encode(_lowerCAmelCase     ,					add_special_tokens=_lowerCAmelCase	)	)

     self.assertListEqual(_lowerCAmelCase     ,					_lowerCAmelCase	)



  def        lowerCAmelCase__	(  self							:							Union[str, Any]	) ->			int:




     """simple docstring"""
     # fmt: off
     snake_case_            =       "I was born in 92000, and this is falsé."
     snake_case_            =       ["▁", "<unk>", "▁was", "▁born", "▁in", "▁9", "2000", "▁", ",", "▁and", "▁this", "▁is", "▁fal", "s", "<unk>", "▁", ".", ]
     # fmt: on

     snake_case_            =       DebertaVaTokenizer(_lowerCAmelCase     ,					do_lower_case=_lowerCAmelCase     ,					split_by_punct=_lowerCAmelCase	)
     snake_case_            =       tokenizer.convert_ids_to_tokens(tokenizer.encode(_lowerCAmelCase     ,					add_special_tokens=_lowerCAmelCase	)	)

     self.assertListEqual(_lowerCAmelCase     ,					_lowerCAmelCase	)

     snake_case_            =       DebertaVaTokenizerFast(_lowerCAmelCase     ,					do_lower_case=_lowerCAmelCase     ,					split_by_punct=_lowerCAmelCase	)
     snake_case_            =       rust_tokenizer.convert_ids_to_tokens(rust_tokenizer.encode(_lowerCAmelCase     ,					add_special_tokens=_lowerCAmelCase	)	)

     self.assertListEqual(_lowerCAmelCase     ,					_lowerCAmelCase	)



  def        lowerCAmelCase__	(  self							:							Any	) ->			Optional[Any]:




     """simple docstring"""
     # fmt: off
     snake_case_            =       " \tHeLLo!how  \n Are yoU?  "
     snake_case_            =       ["▁", "<unk>", "e", "<unk>", "o", "!", "how", "▁", "<unk>", "re", "▁yo", "<unk>", "?"]
     # fmt: on

     snake_case_            =       DebertaVaTokenizer(_lowerCAmelCase     ,					do_lower_case=_lowerCAmelCase     ,					split_by_punct=_lowerCAmelCase	)
     snake_case_            =       tokenizer.convert_ids_to_tokens(tokenizer.encode(_lowerCAmelCase     ,					add_special_tokens=_lowerCAmelCase	)	)

     self.assertListEqual(_lowerCAmelCase     ,					_lowerCAmelCase	)

     snake_case_            =       DebertaVaTokenizerFast(_lowerCAmelCase     ,					do_lower_case=_lowerCAmelCase     ,					split_by_punct=_lowerCAmelCase	)
     snake_case_            =       rust_tokenizer.convert_ids_to_tokens(rust_tokenizer.encode(_lowerCAmelCase     ,					add_special_tokens=_lowerCAmelCase	)	)

     self.assertListEqual(_lowerCAmelCase     ,					_lowerCAmelCase	)



  def        lowerCAmelCase__	(  self							:							Optional[Any]	) ->			Tuple:




     """simple docstring"""
     snake_case_            =       self.get_tokenizer()
     snake_case_            =       self.get_rust_tokenizer()

     snake_case_            =       "I was born in 92000, and this is falsé."

     snake_case_            =       tokenizer.convert_ids_to_tokens(tokenizer.encode(_lowerCAmelCase     ,					add_special_tokens=_lowerCAmelCase	)	)
     snake_case_            =       rust_tokenizer.convert_ids_to_tokens(rust_tokenizer.encode(_lowerCAmelCase     ,					add_special_tokens=_lowerCAmelCase	)	)
     self.assertListEqual(_lowerCAmelCase     ,					_lowerCAmelCase	)

     snake_case_            =       tokenizer.encode(_lowerCAmelCase     ,					add_special_tokens=_lowerCAmelCase	)
     snake_case_            =       rust_tokenizer.encode(_lowerCAmelCase     ,					add_special_tokens=_lowerCAmelCase	)
     self.assertListEqual(_lowerCAmelCase     ,					_lowerCAmelCase	)

     snake_case_            =       self.get_rust_tokenizer()
     snake_case_            =       tokenizer.encode(_lowerCAmelCase	)
     snake_case_            =       rust_tokenizer.encode(_lowerCAmelCase	)
     self.assertListEqual(_lowerCAmelCase     ,					_lowerCAmelCase	)



  def        lowerCAmelCase__	(  self							:							List[str]	) ->			Tuple:




     """simple docstring"""
     snake_case_            =       "This is a test"
     snake_case_            =       [1_3, 1, 4_3_9_8, 2_5, 2_1, 1_2_8_9]
     snake_case_            =       ["▁", "T", "his", "▁is", "▁a", "▁test"]
     snake_case_            =       ["▁", "<unk>", "his", "▁is", "▁a", "▁test"]

     snake_case_            =       DebertaVaTokenizer(_lowerCAmelCase     ,					keep_accents=_lowerCAmelCase	)
     snake_case_            =       DebertaVaTokenizerFast(_lowerCAmelCase     ,					keep_accents=_lowerCAmelCase	)

     snake_case_            =       tokenizer.encode(_lowerCAmelCase     ,					add_special_tokens=_lowerCAmelCase	)
     self.assertListEqual(_lowerCAmelCase     ,					_lowerCAmelCase	)
     snake_case_            =       tokenizer.tokenize(_lowerCAmelCase	)
     self.assertListEqual(_lowerCAmelCase     ,					_lowerCAmelCase	)
     snake_case_            =       tokenizer.convert_ids_to_tokens(_lowerCAmelCase	)
     self.assertListEqual(_lowerCAmelCase     ,					_lowerCAmelCase	)

     snake_case_            =       rust_tokenizer.encode(_lowerCAmelCase     ,					add_special_tokens=_lowerCAmelCase	)
     self.assertListEqual(_lowerCAmelCase     ,					_lowerCAmelCase	)
     snake_case_            =       rust_tokenizer.tokenize(_lowerCAmelCase	)
     self.assertListEqual(_lowerCAmelCase     ,					_lowerCAmelCase	)
     snake_case_            =       rust_tokenizer.convert_ids_to_tokens(_lowerCAmelCase	)
     self.assertListEqual(_lowerCAmelCase     ,					_lowerCAmelCase	)

     # fmt: off
     snake_case_            =       "I was born in 92000, and this is falsé."
     snake_case_            =       [1_3, 1, 2_3, 3_8_6, 1_9, 5_6_1, 3_0_5_0, 1_5, 1_7, 4_8, 2_5, 8_2_5_6, 1_8, 1, 9]
     snake_case_            =       ["▁", "I", "▁was", "▁born", "▁in", "▁9", "2000", ",", "▁and", "▁this", "▁is", "▁fal", "s", "é", ".", ]
     snake_case_            =       ["▁", "<unk>", "▁was", "▁born", "▁in", "▁9", "2000", ",", "▁and", "▁this", "▁is", "▁fal", "s", "<unk>", ".", ]
     # fmt: on

     snake_case_            =       tokenizer.encode(_lowerCAmelCase     ,					add_special_tokens=_lowerCAmelCase	)
     self.assertListEqual(_lowerCAmelCase     ,					_lowerCAmelCase	)
     snake_case_            =       tokenizer.tokenize(_lowerCAmelCase	)
     self.assertListEqual(_lowerCAmelCase     ,					_lowerCAmelCase	)
     snake_case_            =       tokenizer.convert_ids_to_tokens(_lowerCAmelCase	)
     self.assertListEqual(_lowerCAmelCase     ,					_lowerCAmelCase	)

     snake_case_            =       rust_tokenizer.encode(_lowerCAmelCase     ,					add_special_tokens=_lowerCAmelCase	)
     self.assertListEqual(_lowerCAmelCase     ,					_lowerCAmelCase	)
     snake_case_            =       rust_tokenizer.tokenize(_lowerCAmelCase	)
     self.assertListEqual(_lowerCAmelCase     ,					_lowerCAmelCase	)
     snake_case_            =       rust_tokenizer.convert_ids_to_tokens(_lowerCAmelCase	)
     self.assertListEqual(_lowerCAmelCase     ,					_lowerCAmelCase	)



  def        lowerCAmelCase__	(  self							:							str	) ->			Dict:




     """simple docstring"""
     snake_case_            =       DebertaVaTokenizer(_lowerCAmelCase	)

     snake_case_            =       tokenizer.encode("sequence builders"	)
     snake_case_            =       tokenizer.encode("multi-sequence build"	)

     snake_case_            =       tokenizer.build_inputs_with_special_tokens(_lowerCAmelCase	)
     snake_case_            =       tokenizer.build_inputs_with_special_tokens(_lowerCAmelCase     ,					_lowerCAmelCase	)

     self.assertEqual([tokenizer.cls_token_id] + text + [tokenizer.sep_token_id]     ,					_lowerCAmelCase	)
     self.assertEqual(
         [tokenizer.cls_token_id] + text + [tokenizer.sep_token_id] + text_a + [tokenizer.sep_token_id]     ,					_lowerCAmelCase     ,					)



  @slow
  def        lowerCAmelCase__	(  self							:							Union[str, Any]	) ->			int:




     """simple docstring"""
     # fmt: off
     snake_case_            =       {"input_ids": [[1, 3_9_8_6_7, 3_6, 1_9_3_9_0, 4_8_6, 2_7, 3_5_0_5_2, 8_1_4_3_6, 1_8, 6_0_6_8_5, 1_2_2_5, 7, 3_5_0_5_2, 8_1_4_3_6, 1_8, 9_3_6_7, 1_6_8_9_9, 1_8, 1_5_9_3_7, 5_3, 5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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]}  # noqa: E501
     # fmt: on

     self.tokenizer_integration_test_util(
         expected_encoding=_lowerCAmelCase     ,					model_name="microsoft/deberta-v2-xlarge"     ,					revision="ad6e42c1532ddf3a15c39246b63f5559d558b670"     ,					)








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

SCREAMING_SNAKE_CASE						:Optional[int]			=  random.Random()



def       _lowerCAmelCase    (				lowerCAmelCase_				:List[str]		,    lowerCAmelCase_				:Tuple=1.0		,    lowerCAmelCase_				:Optional[int]=None		,    lowerCAmelCase_				:List[Any]=None				)->Dict:
   '''simple docstring'''






   if rng is None:
      snake_case_            =       global_rng

   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
@require_torchaudio
class      __lowerCAmelCase  (			unittest.TestCase       ):






  """simple docstring"""





  def __init__(  self							:							Optional[int]     ,					_lowerCAmelCase							:							Any     ,					_lowerCAmelCase							:							List[str]=7     ,					_lowerCAmelCase							:							List[Any]=4_0_0     ,					_lowerCAmelCase							:							Optional[Any]=2_0_0_0     ,					_lowerCAmelCase							:							Tuple=1_0     ,					_lowerCAmelCase							:							Optional[int]=1_6_0     ,					_lowerCAmelCase							:							List[Any]=8     ,					_lowerCAmelCase							:							List[Any]=0.0     ,					_lowerCAmelCase							:							Dict=4_0_0_0     ,					_lowerCAmelCase							:							str=False     ,					_lowerCAmelCase							:							List[str]=True     ,					) ->			str:




     """simple docstring"""
     snake_case_            =       parent
     snake_case_            =       batch_size
     snake_case_            =       min_seq_length
     snake_case_            =       max_seq_length
     snake_case_            =       (self.max_seq_length - self.min_seq_length) // (self.batch_size - 1)
     snake_case_            =       padding_value
     snake_case_            =       sampling_rate
     snake_case_            =       return_attention_mask
     snake_case_            =       do_normalize
     snake_case_            =       feature_size
     snake_case_            =       chunk_length
     snake_case_            =       hop_length



  def        lowerCAmelCase__	(  self							:							int	) ->			str:




     """simple docstring"""
     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        lowerCAmelCase__	(  self							:							int     ,					_lowerCAmelCase							:							Optional[Any]=False     ,					_lowerCAmelCase							:							List[Any]=False	) ->			int:




     """simple docstring"""
     def _flatten(_lowerCAmelCase							:							Union[str, Any]	):
        return list(itertools.chain(*_lowerCAmelCase	)	)

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






@require_torch
@require_torchaudio
class      __lowerCAmelCase  (			a			,	unittest.TestCase       ):






  """simple docstring"""





  _SCREAMING_SNAKE_CASE		     =							WhisperFeatureExtractor if is_speech_available() else None



  def        lowerCAmelCase__	(  self							:							str	) ->			Union[str, Any]:




     """simple docstring"""
     snake_case_            =       WhisperFeatureExtractionTester(self	)



  def        lowerCAmelCase__	(  self							:							Tuple	) ->			Union[str, Any]:




     """simple docstring"""
     snake_case_            =       self.feature_extraction_class(**self.feat_extract_dict	)

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

     snake_case_            =       feat_extract_first.to_dict()
     snake_case_            =       feat_extract_second.to_dict()
     snake_case_            =       feat_extract_first.mel_filters
     snake_case_            =       feat_extract_second.mel_filters
     self.assertTrue(np.allclose(_lowerCAmelCase     ,					_lowerCAmelCase	)	)
     self.assertEqual(_lowerCAmelCase     ,					_lowerCAmelCase	)



  def        lowerCAmelCase__	(  self							:							List[Any]	) ->			str:




     """simple docstring"""
     snake_case_            =       self.feature_extraction_class(**self.feat_extract_dict	)

     with tempfile.TemporaryDirectory() as tmpdirname:
        snake_case_            =       os.path.join(_lowerCAmelCase     ,					"feat_extract.json"	)
        feat_extract_first.to_json_file(_lowerCAmelCase	)
        snake_case_            =       self.feature_extraction_class.from_json_file(_lowerCAmelCase	)

     snake_case_            =       feat_extract_first.to_dict()
     snake_case_            =       feat_extract_second.to_dict()
     snake_case_            =       feat_extract_first.mel_filters
     snake_case_            =       feat_extract_second.mel_filters
     self.assertTrue(np.allclose(_lowerCAmelCase     ,					_lowerCAmelCase	)	)
     self.assertEqual(_lowerCAmelCase     ,					_lowerCAmelCase	)



  def        lowerCAmelCase__	(  self							:							Any	) ->			Optional[int]:




     """simple docstring"""
     # Tests that all call wrap to encode_plus and batch_encode_plus
     snake_case_            =       self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()	)
     # create three inputs of length 800, 1000, and 1200
     snake_case_            =       [floats_list((1, x)	)[0] for x in range(8_0_0     ,					1_4_0_0     ,					2_0_0	)]
     snake_case_            =       [np.asarray(_lowerCAmelCase	) for speech_input in speech_inputs]

     # Test feature size
     snake_case_            =       feature_extractor(_lowerCAmelCase     ,					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
     snake_case_            =       feature_extractor(speech_inputs[0]     ,					return_tensors="np"	).input_features
     snake_case_            =       feature_extractor(np_speech_inputs[0]     ,					return_tensors="np"	).input_features
     self.assertTrue(np.allclose(_lowerCAmelCase     ,					_lowerCAmelCase     ,					atol=1e-3	)	)

     # Test batched
     snake_case_            =       feature_extractor(_lowerCAmelCase     ,					return_tensors="np"	).input_features
     snake_case_            =       feature_extractor(_lowerCAmelCase     ,					return_tensors="np"	).input_features
     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.
     snake_case_            =       [floats_list((1, x)	)[0] for x in (8_0_0, 8_0_0, 8_0_0)]
     snake_case_            =       np.asarray(_lowerCAmelCase	)
     snake_case_            =       feature_extractor(_lowerCAmelCase     ,					return_tensors="np"	).input_features
     snake_case_            =       feature_extractor(_lowerCAmelCase     ,					return_tensors="np"	).input_features
     for enc_seq_a, enc_seq_a in zip(_lowerCAmelCase     ,					_lowerCAmelCase	):
        self.assertTrue(np.allclose(_lowerCAmelCase     ,					_lowerCAmelCase     ,					atol=1e-3	)	)

     # Test truncation required
     snake_case_            =       [floats_list((1, x)	)[0] for x in range(2_0_0     ,					(feature_extractor.n_samples + 5_0_0)     ,					2_0_0	)]
     snake_case_            =       [np.asarray(_lowerCAmelCase	) for speech_input in speech_inputs]

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

     snake_case_            =       feature_extractor(_lowerCAmelCase     ,					return_tensors="np"	).input_features
     snake_case_            =       feature_extractor(_lowerCAmelCase     ,					return_tensors="np"	).input_features
     for enc_seq_a, enc_seq_a in zip(_lowerCAmelCase     ,					_lowerCAmelCase	):
        self.assertTrue(np.allclose(_lowerCAmelCase     ,					_lowerCAmelCase     ,					atol=1e-3	)	)



  def        lowerCAmelCase__	(  self							:							Optional[int]	) ->			Tuple:




     """simple docstring"""
     import torch

     snake_case_            =       self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()	)
     snake_case_            =       np.random.rand(1_0_0     ,					3_2	).astype(np.floataa	)
     snake_case_            =       np_speech_inputs.tolist()

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



  def        lowerCAmelCase__	(  self							:							List[Any]     ,					_lowerCAmelCase							:							Dict	) ->			int:




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

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



  def        lowerCAmelCase__	(  self							:							Optional[Any]	) ->			Optional[Any]:




     """simple docstring"""
     # fmt: off
     snake_case_            =       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

     snake_case_            =       self._load_datasamples(1	)
     snake_case_            =       WhisperFeatureExtractor()
     snake_case_            =       feature_extractor(_lowerCAmelCase     ,					return_tensors="pt"	).input_features
     self.assertEqual(input_features.shape     ,					(1, 8_0, 3_0_0_0)	)
     self.assertTrue(torch.allclose(input_features[0, 0, :3_0]     ,					_lowerCAmelCase     ,					atol=1e-4	)	)



  def        lowerCAmelCase__	(  self							:							Union[str, Any]	) ->			List[str]:




     """simple docstring"""
     snake_case_            =       self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()	)
     snake_case_            =       self._load_datasamples(1	)[0]
     snake_case_            =       ((audio - audio.min()) / (audio.max() - audio.min())) * 6_5_5_3_5  # Rescale to [0, 65535] to show issue
     snake_case_            =       feat_extract.zero_mean_unit_var_norm([audio]     ,					attention_mask=_lowerCAmelCase	)[0]

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




