

import shutil
import tempfile
import unittest

from transformers import SPIECE_UNDERLINE, BatchEncoding, MBartTokenizer, MBartTokenizerFast, is_torch_available
from transformers.testing_utils import (
    get_tests_dir,
    nested_simplify,
    require_sentencepiece,
    require_tokenizers,
    require_torch,
)

from ...test_tokenization_common import TokenizerTesterMixin


_UpperCamelCase 			=		get_tests_dir("fixtures/test_sentencepiece.model")


if is_torch_available():
 from transformers.models.mbart.modeling_mbart import shift_tokens_right

_UpperCamelCase 			=		25_0004
_UpperCamelCase 			=		25_0020







@require_sentencepiece
@require_tokenizers
class   __lowercase      (_UpperCAmelCase		,   unittest.TestCase ):
 _UpperCamelCase			  =  MBartTokenizer
 _UpperCamelCase			  =  MBartTokenizerFast
 _UpperCamelCase			  =  True
 _UpperCamelCase			  =  True
 def 	UpperCamelCase__  (							self					)					->str:



       '''simple docstring'''





       super().setUp()

       # We have a SentencePiece fixture for testing
       __lowerCAmelCase					:						List[Any]					=					MBartTokenizer(A_      ,							keep_accents=A_					)
       tokenizer.save_pretrained(self.tmpdirname					)
 def 	UpperCamelCase__  (							self					)					->Optional[Any]:



       '''simple docstring'''





       __lowerCAmelCase					:						str					=					MBartTokenizer(A_      ,							keep_accents=A_					)

       __lowerCAmelCase					:						Optional[int]					=					tokenizer.tokenize('''This is a test'''					)
       self.assertListEqual(A_      ,							['''▁This''', '''▁is''', '''▁a''', '''▁t''', '''est''']					)

       self.assertListEqual(
           tokenizer.convert_tokens_to_ids(A_					)      ,							[value + tokenizer.fairseq_offset for value in [285, 46, 10, 170, 382]]      ,							)

       __lowerCAmelCase					:						str					=					tokenizer.tokenize('''I was born in 92000, and this is falsé.'''					)
       self.assertListEqual(
           A_      ,							[
               SPIECE_UNDERLINE + '''I''',
               SPIECE_UNDERLINE + '''was''',
               SPIECE_UNDERLINE + '''b''',
               '''or''',
               '''n''',
               SPIECE_UNDERLINE + '''in''',
               SPIECE_UNDERLINE + '''''',
               '''9''',
               '''2''',
               '''0''',
               '''0''',
               '''0''',
               ''',''',
               SPIECE_UNDERLINE + '''and''',
               SPIECE_UNDERLINE + '''this''',
               SPIECE_UNDERLINE + '''is''',
               SPIECE_UNDERLINE + '''f''',
               '''al''',
               '''s''',
               '''é''',
               '''.''',
           ]      ,							)
       __lowerCAmelCase					:						str					=					tokenizer.convert_tokens_to_ids(A_					)
       self.assertListEqual(
           A_      ,							[
               value + tokenizer.fairseq_offset
               for value in [8, 21, 84, 55, 24, 19, 7, 2, 602, 347, 347, 347, 3, 12, 66, 46, 72, 80, 6, 2, 4]
               #                                       ^ unk: 2 + 1 = 3                  unk: 2 + 1 = 3 ^
           ]      ,							)

       __lowerCAmelCase					:						Union[str, Any]					=					tokenizer.convert_ids_to_tokens(A_					)
       self.assertListEqual(
           A_      ,							[
               SPIECE_UNDERLINE + '''I''',
               SPIECE_UNDERLINE + '''was''',
               SPIECE_UNDERLINE + '''b''',
               '''or''',
               '''n''',
               SPIECE_UNDERLINE + '''in''',
               SPIECE_UNDERLINE + '''''',
               '''<unk>''',
               '''2''',
               '''0''',
               '''0''',
               '''0''',
               ''',''',
               SPIECE_UNDERLINE + '''and''',
               SPIECE_UNDERLINE + '''this''',
               SPIECE_UNDERLINE + '''is''',
               SPIECE_UNDERLINE + '''f''',
               '''al''',
               '''s''',
               '''<unk>''',
               '''.''',
           ]      ,							)





 def 	UpperCamelCase__  (							self					)					->Dict:



       '''simple docstring'''





       if not self.test_slow_tokenizer:
             # as we don't have a slow version, we can't compare the outputs between slow and fast versions
             return

       __lowerCAmelCase					:						Optional[Any]					=					(self.rust_tokenizer_class, '''hf-internal-testing/tiny-random-mbart''', {})
       for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
             with self.subTest(f"""{tokenizer.__class__.__name__} ({pretrained_name})"""					):
                   __lowerCAmelCase					:						Tuple					=					self.rust_tokenizer_class.from_pretrained(A_      ,							**A_					)
                   __lowerCAmelCase					:						Dict					=					self.tokenizer_class.from_pretrained(A_      ,							**A_					)

                   __lowerCAmelCase					:						List[str]					=					tempfile.mkdtemp()

                   __lowerCAmelCase					:						int					=					tokenizer_r.save_pretrained(A_					)
                   __lowerCAmelCase					:						Optional[Any]					=					tokenizer_p.save_pretrained(A_					)

                   # Checks it save with the same files + the tokenizer.json file for the fast one
                   self.assertTrue(any('''tokenizer.json''' in f for f in tokenizer_r_files					)					)
                   __lowerCAmelCase					:						Tuple					=					tuple(f for f in tokenizer_r_files if '''tokenizer.json''' not in f					)
                   self.assertSequenceEqual(A_      ,							A_					)

                   # Checks everything loads correctly in the same way
                   __lowerCAmelCase					:						Optional[Any]					=					tokenizer_r.from_pretrained(A_					)
                   __lowerCAmelCase					:						Any					=					tokenizer_p.from_pretrained(A_					)

                   # Check special tokens are set accordingly on Rust and Python
                   for key in tokenizer_pp.special_tokens_map:
                         self.assertTrue(hasattr(A_      ,							A_					)					)
                         # self.assertEqual(getattr(tokenizer_rp, key), getattr(tokenizer_pp, key))
                         # self.assertEqual(getattr(tokenizer_rp, key + "_id"), getattr(tokenizer_pp, key + "_id"))

                   shutil.rmtree(A_					)

                   # Save tokenizer rust, legacy_format=True
                   __lowerCAmelCase					:						List[Any]					=					tempfile.mkdtemp()

                   __lowerCAmelCase					:						Dict					=					tokenizer_r.save_pretrained(A_      ,							legacy_format=A_					)
                   __lowerCAmelCase					:						List[str]					=					tokenizer_p.save_pretrained(A_					)

                   # Checks it save with the same files
                   self.assertSequenceEqual(A_      ,							A_					)

                   # Checks everything loads correctly in the same way
                   __lowerCAmelCase					:						Any					=					tokenizer_r.from_pretrained(A_					)
                   __lowerCAmelCase					:						Any					=					tokenizer_p.from_pretrained(A_					)

                   # Check special tokens are set accordingly on Rust and Python
                   for key in tokenizer_pp.special_tokens_map:
                         self.assertTrue(hasattr(A_      ,							A_					)					)

                   shutil.rmtree(A_					)

                   # Save tokenizer rust, legacy_format=False
                   __lowerCAmelCase					:						Tuple					=					tempfile.mkdtemp()

                   __lowerCAmelCase					:						str					=					tokenizer_r.save_pretrained(A_      ,							legacy_format=A_					)
                   __lowerCAmelCase					:						int					=					tokenizer_p.save_pretrained(A_					)

                   # Checks it saved the tokenizer.json file
                   self.assertTrue(any('''tokenizer.json''' in f for f in tokenizer_r_files					)					)

                   # Checks everything loads correctly in the same way
                   __lowerCAmelCase					:						str					=					tokenizer_r.from_pretrained(A_					)
                   __lowerCAmelCase					:						Optional[Any]					=					tokenizer_p.from_pretrained(A_					)

                   # Check special tokens are set accordingly on Rust and Python
                   for key in tokenizer_pp.special_tokens_map:
                         self.assertTrue(hasattr(A_      ,							A_					)					)

                   shutil.rmtree(A_					)







@require_torch
@require_sentencepiece
@require_tokenizers
class   __lowercase      (unittest.TestCase ):
 _UpperCamelCase			  =  """facebook/mbart-large-en-ro"""
 _UpperCamelCase			  =  [
     """ UN Chief Says There Is No Military Solution in Syria""",
     """ Secretary-General Ban Ki-moon says his response to Russia's stepped up military support for Syria is that \"there is no military solution\" to the nearly five-year conflict and more weapons will only worsen the violence and misery for millions of people.""",
 ]
 _UpperCamelCase			  =  [
     """Şeful ONU declară că nu există o soluţie militară în Siria""",
     """Secretarul General Ban Ki-moon declară că răspunsul său la intensificarea sprijinului militar al Rusiei"""
     """ pentru Siria este că \"nu există o soluţie militară\" la conflictul de aproape cinci ani şi că noi arme nu vor"""
     """ face decât să înrăutăţească violenţele şi mizeria pentru milioane de oameni.""",
 ]
 _UpperCamelCase			  =  [8274, 127873, 25916, 7, 8622, 2071, 438, 67485, 53, 187895, 23, 51712, 2, EN_CODE]
 @classmethod
 def 	UpperCamelCase__  (							cls					)					->Tuple:



       '''simple docstring'''





       __lowerCAmelCase					:						MBartTokenizer					=					MBartTokenizer.from_pretrained(
           cls.checkpoint_name      ,							src_lang='''en_XX'''      ,							tgt_lang='''ro_RO'''					)
       __lowerCAmelCase					:						Optional[Any]					=					1
       return cls
 def 	UpperCamelCase__  (							self					)					->List[Any]:



       '''simple docstring'''





       self.assertEqual(self.tokenizer.fairseq_tokens_to_ids['''ar_AR''']      ,							25_0001					)
       self.assertEqual(self.tokenizer.fairseq_tokens_to_ids['''en_EN''']      ,							25_0004					)
       self.assertEqual(self.tokenizer.fairseq_tokens_to_ids['''ro_RO''']      ,							25_0020					)
 def 	UpperCamelCase__  (							self					)					->Any:



       '''simple docstring'''





       __lowerCAmelCase					:						Dict					=					self.tokenizer.batch_encode_plus(self.src_text					).input_ids[0]
       self.assertListEqual(self.expected_src_tokens      ,							A_					)
 def 	UpperCamelCase__  (							self					)					->List[Any]:



       '''simple docstring'''





       self.assertIn(A_      ,							self.tokenizer.all_special_ids					)
       __lowerCAmelCase					:						Any					=					[RO_CODE, 884, 9019, 96, 9, 916, 8_6792, 36, 1_8743, 1_5596, 5, 2]
       __lowerCAmelCase					:						Any					=					self.tokenizer.decode(A_      ,							skip_special_tokens=A_					)
       __lowerCAmelCase					:						Any					=					self.tokenizer.decode(generated_ids[1:]      ,							skip_special_tokens=A_					)
       self.assertEqual(A_      ,							A_					)
       self.assertNotIn(self.tokenizer.eos_token      ,							A_					)
 def 	UpperCamelCase__  (							self					)					->str:



       '''simple docstring'''





       __lowerCAmelCase					:						Tuple					=					['''this is gunna be a long sentence ''' * 20]
       assert isinstance(src_text[0]      ,							A_					)
       __lowerCAmelCase					:						int					=					10
       __lowerCAmelCase					:						int					=					self.tokenizer(A_      ,							max_length=A_      ,							truncation=A_					).input_ids[0]
       self.assertEqual(ids[-2]      ,							2					)
       self.assertEqual(ids[-1]      ,							A_					)
       self.assertEqual(len(A_					)      ,							A_					)
 def 	UpperCamelCase__  (							self					)					->str:



       '''simple docstring'''





       self.assertListEqual(self.tokenizer.convert_tokens_to_ids(['''<mask>''', '''ar_AR''']					)      ,							[25_0026, 25_0001]					)
 def 	UpperCamelCase__  (							self					)					->Tuple:



       '''simple docstring'''





       __lowerCAmelCase					:						Dict					=					tempfile.mkdtemp()
       __lowerCAmelCase					:						List[str]					=					self.tokenizer.fairseq_tokens_to_ids
       self.tokenizer.save_pretrained(A_					)
       __lowerCAmelCase					:						Dict					=					MBartTokenizer.from_pretrained(A_					)
       self.assertDictEqual(new_tok.fairseq_tokens_to_ids      ,							A_					)
 @require_torch
 def 	UpperCamelCase__  (							self					)					->Dict:



       '''simple docstring'''





       __lowerCAmelCase					:						Optional[Any]					=					self.tokenizer(self.src_text      ,							text_target=self.tgt_text      ,							padding=A_      ,							return_tensors='''pt'''					)
       __lowerCAmelCase					:						Dict					=					shift_tokens_right(batch['''labels''']      ,							self.tokenizer.pad_token_id					)

       # fairseq batch: https://gist.github.com/sshleifer/cba08bc2109361a74ac3760a7e30e4f4
       assert batch.input_ids[1][-2:].tolist() == [2, EN_CODE]
       assert batch.decoder_input_ids[1][0].tolist() == RO_CODE
       assert batch.decoder_input_ids[1][-1] == 2
       assert batch.labels[1][-2:].tolist() == [2, RO_CODE]
 @require_torch
 def 	UpperCamelCase__  (							self					)					->Dict:



       '''simple docstring'''





       __lowerCAmelCase					:						str					=					self.tokenizer(
           self.src_text      ,							text_target=self.tgt_text      ,							padding=A_      ,							truncation=A_      ,							max_length=len(self.expected_src_tokens					)      ,							return_tensors='''pt'''      ,							)

       __lowerCAmelCase					:						Union[str, Any]					=					shift_tokens_right(batch['''labels''']      ,							self.tokenizer.pad_token_id					)

       self.assertIsInstance(A_      ,							A_					)

       self.assertEqual((2, 14)      ,							batch.input_ids.shape					)
       self.assertEqual((2, 14)      ,							batch.attention_mask.shape					)
       __lowerCAmelCase					:						Union[str, Any]					=					batch.input_ids.tolist()[0]
       self.assertListEqual(self.expected_src_tokens      ,							A_					)
       self.assertEqual(2      ,							batch.decoder_input_ids[0, -1]					)  # EOS
       # Test that special tokens are reset
       self.assertEqual(self.tokenizer.prefix_tokens      ,							[]					)
       self.assertEqual(self.tokenizer.suffix_tokens      ,							[self.tokenizer.eos_token_id, EN_CODE]					)
 def 	UpperCamelCase__  (							self					)					->Dict:



       '''simple docstring'''





       __lowerCAmelCase					:						List[Any]					=					self.tokenizer(self.src_text      ,							padding=A_      ,							truncation=A_      ,							max_length=3      ,							return_tensors='''pt'''					)
       __lowerCAmelCase					:						Optional[Any]					=					self.tokenizer(
           text_target=self.tgt_text      ,							padding=A_      ,							truncation=A_      ,							max_length=10      ,							return_tensors='''pt'''					)
       __lowerCAmelCase					:						Union[str, Any]					=					targets['''input_ids''']
       __lowerCAmelCase					:						int					=					shift_tokens_right(A_      ,							self.tokenizer.pad_token_id					)

       self.assertEqual(batch.input_ids.shape[1]      ,							3					)
       self.assertEqual(batch.decoder_input_ids.shape[1]      ,							10					)





 @require_torch
 def 	UpperCamelCase__  (							self					)					->List[str]:



       '''simple docstring'''





       __lowerCAmelCase					:						Dict					=					self.tokenizer._build_translation_inputs(
           '''A test'''      ,							return_tensors='''pt'''      ,							src_lang='''en_XX'''      ,							tgt_lang='''ar_AR'''					)

       self.assertEqual(
           nested_simplify(A_					)      ,							{
               # A, test, EOS, en_XX
               '''input_ids''': [[62, 3034, 2, 25_0004]],
               '''attention_mask''': [[1, 1, 1, 1]],
               # ar_AR
               '''forced_bos_token_id''': 25_0001,
           }      ,							)





import itertools
import random
import unittest

import numpy as np

from transformers import WAV_2_VEC_2_PRETRAINED_MODEL_ARCHIVE_LIST, WavaVecaConfig, WavaVecaFeatureExtractor
from transformers.testing_utils import require_torch, slow

from ...test_sequence_feature_extraction_common import SequenceFeatureExtractionTestMixin


_UpperCamelCase 			=		random.Random()







def 		_lowercase (     lowercase__   ,	lowercase__=1.0   ,	lowercase__=None   ,	lowercase__=None						):
      if rng is None:
            __lowerCAmelCase					:						Optional[Any]					=					global_rng

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

      return values







class   __lowercase      (unittest.TestCase ):
 def __init__(							self      ,							A_      ,							A_=7      ,							A_=400      ,							A_=2000      ,							A_=1      ,							A_=0.0      ,							A_=1_6000      ,							A_=True      ,							A_=True      ,							)					->List[Any]:



       '''simple docstring'''





       __lowerCAmelCase					:						List[Any]					=					parent
       __lowerCAmelCase					:						Optional[int]					=					batch_size
       __lowerCAmelCase					:						Any					=					min_seq_length
       __lowerCAmelCase					:						Tuple					=					max_seq_length
       __lowerCAmelCase					:						Tuple					=					(self.max_seq_length - self.min_seq_length) // (self.batch_size - 1)
       __lowerCAmelCase					:						Dict					=					feature_size
       __lowerCAmelCase					:						Optional[int]					=					padding_value
       __lowerCAmelCase					:						Tuple					=					sampling_rate
       __lowerCAmelCase					:						Union[str, Any]					=					return_attention_mask
       __lowerCAmelCase					:						Dict					=					do_normalize
 def 	UpperCamelCase__  (							self					)					->Optional[Any]:



       '''simple docstring'''





       return {
           "feature_size": self.feature_size,
           "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      ,							A_=False      ,							A_=False					)					->Union[str, Any]:



       '''simple docstring'''





       def _flatten(A_					):
             return list(itertools.chain(*A_					)					)

       if equal_length:
             __lowerCAmelCase					:						Dict					=					floats_list((self.batch_size, self.max_seq_length)					)
       else:
             # make sure that inputs increase in size
             __lowerCAmelCase					:						Tuple					=					[
                 _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:
             __lowerCAmelCase					:						Tuple					=					[np.asarray(A_					) for x in speech_inputs]

       return speech_inputs







class   __lowercase      (_UpperCAmelCase		,   unittest.TestCase ):
 _UpperCamelCase			  =  WavaVecaFeatureExtractor
 def 	UpperCamelCase__  (							self					)					->Dict:



       '''simple docstring'''





       __lowerCAmelCase					:						List[Any]					=					WavaVecaFeatureExtractionTester(self					)
 def 	UpperCamelCase__  (							self      ,							A_					)					->Optional[Any]:



       '''simple docstring'''





       self.assertTrue(np.all(np.mean(A_      ,							axis=0					) < 1e-3					)					)
       self.assertTrue(np.all(np.abs(np.var(A_      ,							axis=0					) - 1					) < 1e-3					)					)
 def 	UpperCamelCase__  (							self					)					->Tuple:



       '''simple docstring'''





       __lowerCAmelCase					:						List[str]					=					self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()					)
       # create three inputs of length 800, 1000, and 1200
       __lowerCAmelCase					:						Optional[Any]					=					[floats_list((1, x)					)[0] for x in range(800      ,							1400      ,							200					)]
       __lowerCAmelCase					:						Any					=					[np.asarray(A_					) for speech_input in speech_inputs]

       # Test not batched input
       __lowerCAmelCase					:						Optional[Any]					=					feat_extract(speech_inputs[0]      ,							return_tensors='''np'''					).input_values
       __lowerCAmelCase					:						Dict					=					feat_extract(np_speech_inputs[0]      ,							return_tensors='''np'''					).input_values
       self.assertTrue(np.allclose(A_      ,							A_      ,							atol=1e-3					)					)

       # Test batched
       __lowerCAmelCase					:						Dict					=					feat_extract(A_      ,							return_tensors='''np'''					).input_values
       __lowerCAmelCase					:						Dict					=					feat_extract(A_      ,							return_tensors='''np'''					).input_values
       for enc_seq_a, enc_seq_a in zip(A_      ,							A_					):
             self.assertTrue(np.allclose(A_      ,							A_      ,							atol=1e-3					)					)

       # Test 2-D numpy arrays are batched.
       __lowerCAmelCase					:						int					=					[floats_list((1, x)					)[0] for x in (800, 800, 800)]
       __lowerCAmelCase					:						List[Any]					=					np.asarray(A_					)
       __lowerCAmelCase					:						Any					=					feat_extract(A_      ,							return_tensors='''np'''					).input_values
       __lowerCAmelCase					:						Union[str, Any]					=					feat_extract(A_      ,							return_tensors='''np'''					).input_values
       for enc_seq_a, enc_seq_a in zip(A_      ,							A_					):
             self.assertTrue(np.allclose(A_      ,							A_      ,							atol=1e-3					)					)
 def 	UpperCamelCase__  (							self					)					->Union[str, Any]:



       '''simple docstring'''





       __lowerCAmelCase					:						Optional[int]					=					self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()					)
       __lowerCAmelCase					:						str					=					[floats_list((1, x)					)[0] for x in range(800      ,							1400      ,							200					)]

       __lowerCAmelCase					:						str					=					['''longest''', '''max_length''', '''do_not_pad''']
       __lowerCAmelCase					:						str					=					[None, 1600, None]
       for max_length, padding in zip(A_      ,							A_					):
             __lowerCAmelCase					:						Optional[int]					=					feat_extract(A_      ,							padding=A_      ,							max_length=A_      ,							return_tensors='''np'''					)
             __lowerCAmelCase					:						Optional[Any]					=					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][:1000]					)
             self.assertTrue(input_values[0][1000:].sum() < 1e-6					)
             self._check_zero_mean_unit_variance(input_values[2][:1200]					)
 def 	UpperCamelCase__  (							self					)					->Dict:



       '''simple docstring'''





       __lowerCAmelCase					:						List[str]					=					self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()					)
       __lowerCAmelCase					:						Optional[int]					=					range(800      ,							1400      ,							200					)
       __lowerCAmelCase					:						Union[str, Any]					=					[floats_list((1, x)					)[0] for x in lengths]

       __lowerCAmelCase					:						int					=					['''longest''', '''max_length''', '''do_not_pad''']
       __lowerCAmelCase					:						List[str]					=					[None, 1600, None]

       for max_length, padding in zip(A_      ,							A_					):
             __lowerCAmelCase					:						Union[str, Any]					=					feat_extract(A_      ,							max_length=A_      ,							padding=A_					)
             __lowerCAmelCase					:						Union[str, Any]					=					processed.input_values

             self._check_zero_mean_unit_variance(input_values[0][:800]					)
             self._check_zero_mean_unit_variance(input_values[1][:1000]					)
             self._check_zero_mean_unit_variance(input_values[2][:1200]					)
 def 	UpperCamelCase__  (							self					)					->Tuple:



       '''simple docstring'''





       __lowerCAmelCase					:						Dict					=					self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()					)
       __lowerCAmelCase					:						Optional[Any]					=					[floats_list((1, x)					)[0] for x in range(800      ,							1400      ,							200					)]
       __lowerCAmelCase					:						List[str]					=					feat_extract(
           A_      ,							truncation=A_      ,							max_length=1000      ,							padding='''max_length'''      ,							return_tensors='''np'''					)
       __lowerCAmelCase					:						int					=					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 	UpperCamelCase__  (							self					)					->List[str]:



       '''simple docstring'''





       __lowerCAmelCase					:						Dict					=					self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()					)
       __lowerCAmelCase					:						int					=					[floats_list((1, x)					)[0] for x in range(800      ,							1400      ,							200					)]
       __lowerCAmelCase					:						int					=					feat_extract(
           A_      ,							truncation=A_      ,							max_length=1000      ,							padding='''longest'''      ,							return_tensors='''np'''					)
       __lowerCAmelCase					:						Optional[Any]					=					processed.input_values

       self._check_zero_mean_unit_variance(input_values[0, :800]					)
       self._check_zero_mean_unit_variance(input_values[1, :1000]					)
       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, 1000)					)

       __lowerCAmelCase					:						Any					=					[floats_list((1, x)					)[0] for x in range(800      ,							1400      ,							200					)]
       __lowerCAmelCase					:						Optional[int]					=					feat_extract(
           A_      ,							truncation=A_      ,							max_length=2000      ,							padding='''longest'''      ,							return_tensors='''np'''					)
       __lowerCAmelCase					:						List[str]					=					processed.input_values

       self._check_zero_mean_unit_variance(input_values[0, :800]					)
       self._check_zero_mean_unit_variance(input_values[1, :1000]					)
       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, 1200)					)
 @require_torch
 def 	UpperCamelCase__  (							self					)					->Any:



       '''simple docstring'''





       import torch

       __lowerCAmelCase					:						Union[str, Any]					=					self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()					)
       __lowerCAmelCase					:						Any					=					np.random.rand(100					).astype(np.floataa					)
       __lowerCAmelCase					:						List[Any]					=					np_speech_inputs.tolist()

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





 @slow
 @require_torch
 def 	UpperCamelCase__  (							self					)					->int:



       '''simple docstring'''





       for model_id in WAV_2_VEC_2_PRETRAINED_MODEL_ARCHIVE_LIST:
             __lowerCAmelCase					:						Any					=					WavaVecaConfig.from_pretrained(A_					)
             __lowerCAmelCase					:						Tuple					=					WavaVecaFeatureExtractor.from_pretrained(A_					)

             # only "layer" feature extraction norm should make use of
             # attention_mask
             self.assertEqual(feat_extract.return_attention_mask      ,							config.feat_extract_norm == '''layer'''					)


