



import os
import unittest

from transformers import BertTokenizerFast
from transformers.models.bert.tokenization_bert import (
    VOCAB_FILES_NAMES,
    BasicTokenizer,
    BertTokenizer,
    WordpieceTokenizer,
    _is_control,
    _is_punctuation,
    _is_whitespace,
)
from transformers.testing_utils import require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin, filter_non_english



@require_tokenizers
class     UpperCAmelCase_       (			_A  ,   unittest.TestCase):
							lowerCamelCase__       =						BertTokenizer
							lowerCamelCase__       =						BertTokenizerFast
							lowerCamelCase__       =						True
							lowerCamelCase__       =						True
							lowerCamelCase__       =						filter_non_english







							def   snake_case__ (  self):

														'''simple docstring'''

														super().setUp()

														_lowerCAmelCase	:				Union[str, Any]					  =       [
														    "[UNK]",
														    "[CLS]",
														    "[SEP]",
														    "[PAD]",
														    "[MASK]",
														    "want",
														    "##want",
														    "##ed",
														    "wa",
														    "un",
														    "runn",
														    "##ing",
														    ",",
														    "low",
														    "lowest",
														]
														_lowerCAmelCase	:				Optional[int]					  =       os.path.join(self.tmpdirname,     VOCAB_FILES_NAMES["vocab_file"])
														with open(self.vocab_file,     "w",     encoding="utf-8") as vocab_writer:
																					vocab_writer.write("".join([x + "\n" for x in vocab_tokens]))







							def   snake_case__ (  self,     __a):

														'''simple docstring'''

														_lowerCAmelCase	:				Tuple					  =       "UNwant\u00E9d,running"
														_lowerCAmelCase	:				int					  =       "unwanted, running"
														return input_text, output_text







							def   snake_case__ (  self):

														'''simple docstring'''

														_lowerCAmelCase	:				Optional[Any]					  =       self.tokenizer_class(self.vocab_file)

														_lowerCAmelCase	:				Optional[int]					  =       tokenizer.tokenize("UNwant\u00E9d,running")
														self.assertListEqual(a_,     ["un", "##want", "##ed", ",", "runn", "##ing"])
														self.assertListEqual(tokenizer.convert_tokens_to_ids(a_),     [9, 6, 7, 12, 10, 11])







							def   snake_case__ (  self):

														'''simple docstring'''

														if not self.test_rust_tokenizer:
																					return

														_lowerCAmelCase	:				Union[str, Any]					  =       self.get_tokenizer()
														_lowerCAmelCase	:				Union[str, Any]					  =       self.get_rust_tokenizer()

														_lowerCAmelCase	:				Tuple					  =       "UNwant\u00E9d,running"

														_lowerCAmelCase	:				Any					  =       tokenizer.tokenize(a_)
														_lowerCAmelCase	:				int					  =       rust_tokenizer.tokenize(a_)
														self.assertListEqual(a_,     a_)

														_lowerCAmelCase	:				Optional[int]					  =       tokenizer.encode(a_,     add_special_tokens=a_)
														_lowerCAmelCase	:				Dict					  =       rust_tokenizer.encode(a_,     add_special_tokens=a_)
														self.assertListEqual(a_,     a_)

														_lowerCAmelCase	:				Any					  =       self.get_rust_tokenizer()
														_lowerCAmelCase	:				Optional[Any]					  =       tokenizer.encode(a_)
														_lowerCAmelCase	:				List[Any]					  =       rust_tokenizer.encode(a_)
														self.assertListEqual(a_,     a_)

														# With lower casing
														_lowerCAmelCase	:				Any					  =       self.get_tokenizer(do_lower_case=a_)
														_lowerCAmelCase	:				int					  =       self.get_rust_tokenizer(do_lower_case=a_)

														_lowerCAmelCase	:				List[str]					  =       "UNwant\u00E9d,running"

														_lowerCAmelCase	:				str					  =       tokenizer.tokenize(a_)
														_lowerCAmelCase	:				List[Any]					  =       rust_tokenizer.tokenize(a_)
														self.assertListEqual(a_,     a_)

														_lowerCAmelCase	:				Union[str, Any]					  =       tokenizer.encode(a_,     add_special_tokens=a_)
														_lowerCAmelCase	:				Tuple					  =       rust_tokenizer.encode(a_,     add_special_tokens=a_)
														self.assertListEqual(a_,     a_)

														_lowerCAmelCase	:				Tuple					  =       self.get_rust_tokenizer()
														_lowerCAmelCase	:				str					  =       tokenizer.encode(a_)
														_lowerCAmelCase	:				List[Any]					  =       rust_tokenizer.encode(a_)
														self.assertListEqual(a_,     a_)







							def   snake_case__ (  self):

														'''simple docstring'''

														_lowerCAmelCase	:				int					  =       BasicTokenizer()

														self.assertListEqual(tokenizer.tokenize("ah\u535A\u63A8zz"),     ["ah", "\u535A", "\u63A8", "zz"])







							def   snake_case__ (  self):

														'''simple docstring'''

														_lowerCAmelCase	:				int					  =       BasicTokenizer(do_lower_case=a_)

														self.assertListEqual(
														    tokenizer.tokenize(" \tHeLLo!how  \n Are yoU?  "),     ["hello", "!", "how", "are", "you", "?"])
														self.assertListEqual(tokenizer.tokenize("H\u00E9llo"),     ["hello"])







							def   snake_case__ (  self):

														'''simple docstring'''

														_lowerCAmelCase	:				Dict					  =       BasicTokenizer(do_lower_case=a_,     strip_accents=a_)

														self.assertListEqual(
														    tokenizer.tokenize(" \tHäLLo!how  \n Are yoU?  "),     ["hällo", "!", "how", "are", "you", "?"])
														self.assertListEqual(tokenizer.tokenize("H\u00E9llo"),     ["h\u00E9llo"])







							def   snake_case__ (  self):

														'''simple docstring'''

														_lowerCAmelCase	:				Optional[Any]					  =       BasicTokenizer(do_lower_case=a_,     strip_accents=a_)

														self.assertListEqual(
														    tokenizer.tokenize(" \tHäLLo!how  \n Are yoU?  "),     ["hallo", "!", "how", "are", "you", "?"])
														self.assertListEqual(tokenizer.tokenize("H\u00E9llo"),     ["hello"])







							def   snake_case__ (  self):

														'''simple docstring'''

														_lowerCAmelCase	:				Dict					  =       BasicTokenizer(do_lower_case=a_)

														self.assertListEqual(
														    tokenizer.tokenize(" \tHäLLo!how  \n Are yoU?  "),     ["hallo", "!", "how", "are", "you", "?"])
														self.assertListEqual(tokenizer.tokenize("H\u00E9llo"),     ["hello"])







							def   snake_case__ (  self):

														'''simple docstring'''

														_lowerCAmelCase	:				Tuple					  =       BasicTokenizer(do_lower_case=a_)

														self.assertListEqual(
														    tokenizer.tokenize(" \tHeLLo!how  \n Are yoU?  "),     ["HeLLo", "!", "how", "Are", "yoU", "?"])







							def   snake_case__ (  self):

														'''simple docstring'''

														_lowerCAmelCase	:				int					  =       BasicTokenizer(do_lower_case=a_,     strip_accents=a_)

														self.assertListEqual(
														    tokenizer.tokenize(" \tHäLLo!how  \n Are yoU?  "),     ["HäLLo", "!", "how", "Are", "yoU", "?"])







							def   snake_case__ (  self):

														'''simple docstring'''

														_lowerCAmelCase	:				Any					  =       BasicTokenizer(do_lower_case=a_,     strip_accents=a_)

														self.assertListEqual(
														    tokenizer.tokenize(" \tHäLLo!how  \n Are yoU?  "),     ["HaLLo", "!", "how", "Are", "yoU", "?"])







							def   snake_case__ (  self):

														'''simple docstring'''

														_lowerCAmelCase	:				Any					  =       BasicTokenizer(do_lower_case=a_,     never_split=["[UNK]"])

														self.assertListEqual(
														    tokenizer.tokenize(" \tHeLLo!how  \n Are yoU? [UNK]"),     ["HeLLo", "!", "how", "Are", "yoU", "?", "[UNK]"])







							def   snake_case__ (  self):

														'''simple docstring'''

														_lowerCAmelCase	:				str					  =       BasicTokenizer()
														_lowerCAmelCase	:				Optional[Any]					  =       "a\n'll !!to?'d of, can't."
														_lowerCAmelCase	:				Union[str, Any]					  =       ["a", "'", "ll", "!", "!", "to", "?", "'", "d", "of", ",", "can", "'", "t", "."]
														self.assertListEqual(tokenizer.tokenize(a_),     a_)







							def   snake_case__ (  self):

														'''simple docstring'''

														_lowerCAmelCase	:				Optional[Any]					  =       ["[UNK]", "[CLS]", "[SEP]", "want", "##want", "##ed", "wa", "un", "runn", "##ing"]

														_lowerCAmelCase	:				Optional[Any]					  =       {}
														for i, token in enumerate(a_):
																					_lowerCAmelCase	:				List[str]					  =       i
														_lowerCAmelCase	:				List[Any]					  =       WordpieceTokenizer(vocab=a_,     unk_token="[UNK]")

														self.assertListEqual(tokenizer.tokenize(""),     [])

														self.assertListEqual(tokenizer.tokenize("unwanted running"),     ["un", "##want", "##ed", "runn", "##ing"])

														self.assertListEqual(tokenizer.tokenize("unwantedX running"),     ["[UNK]", "runn", "##ing"])







							def   snake_case__ (  self):

														'''simple docstring'''

														self.assertTrue(_is_whitespace(" "))
														self.assertTrue(_is_whitespace("\t"))
														self.assertTrue(_is_whitespace("\r"))
														self.assertTrue(_is_whitespace("\n"))
														self.assertTrue(_is_whitespace("\u00A0"))

														self.assertFalse(_is_whitespace("A"))
														self.assertFalse(_is_whitespace("-"))







							def   snake_case__ (  self):

														'''simple docstring'''

														self.assertTrue(_is_control("\u0005"))

														self.assertFalse(_is_control("A"))
														self.assertFalse(_is_control(" "))
														self.assertFalse(_is_control("\t"))
														self.assertFalse(_is_control("\r"))







							def   snake_case__ (  self):

														'''simple docstring'''

														self.assertTrue(_is_punctuation("-"))
														self.assertTrue(_is_punctuation("$"))
														self.assertTrue(_is_punctuation("`"))
														self.assertTrue(_is_punctuation("."))

														self.assertFalse(_is_punctuation("A"))
														self.assertFalse(_is_punctuation(" "))







							def   snake_case__ (  self):

														'''simple docstring'''

														_lowerCAmelCase	:				Dict					  =       self.get_tokenizer()
														_lowerCAmelCase	:				Union[str, Any]					  =       self.get_rust_tokenizer()

														# Example taken from the issue https://github.com/huggingface/tokenizers/issues/340
														self.assertListEqual([tokenizer.tokenize(a_) for t in ["Test", "\xad", "test"]],     [["[UNK]"], [], ["[UNK]"]])

														self.assertListEqual(
														    [rust_tokenizer.tokenize(a_) for t in ["Test", "\xad", "test"]],     [["[UNK]"], [], ["[UNK]"]])







							@slow
							def   snake_case__ (  self):

														'''simple docstring'''

														_lowerCAmelCase	:				Union[str, Any]					  =       self.tokenizer_class.from_pretrained("bert-base-uncased")

														_lowerCAmelCase	:				str					  =       tokenizer.encode("sequence builders",     add_special_tokens=a_)
														_lowerCAmelCase	:				int					  =       tokenizer.encode("multi-sequence build",     add_special_tokens=a_)

														_lowerCAmelCase	:				int					  =       tokenizer.build_inputs_with_special_tokens(a_)
														_lowerCAmelCase	:				List[Any]					  =       tokenizer.build_inputs_with_special_tokens(a_,     a_)

														assert encoded_sentence == [101] + text + [102]
														assert encoded_pair == [101] + text + [102] + text_a + [102]







							def   snake_case__ (  self):

														'''simple docstring'''

														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	:				List[Any]					  =       f"A, naïve {tokenizer_r.mask_token} AllenNLP sentence."
																												_lowerCAmelCase	:				str					  =       tokenizer_r.encode_plus(
																												    a_,     return_attention_mask=a_,     return_token_type_ids=a_,     return_offsets_mapping=a_,     add_special_tokens=a_,     )

																												_lowerCAmelCase	:				List[str]					  =       tokenizer_r.do_lower_case if hasattr(a_,     "do_lower_case") else False
																												_lowerCAmelCase	:				Optional[Any]					  =       (
																												    [
																												        ((0, 0), tokenizer_r.cls_token),
																												        ((0, 1), "A"),
																												        ((1, 2), ","),
																												        ((3, 5), "na"),
																												        ((5, 6), "##ï"),
																												        ((6, 8), "##ve"),
																												        ((9, 15), tokenizer_r.mask_token),
																												        ((16, 21), "Allen"),
																												        ((21, 23), "##NL"),
																												        ((23, 24), "##P"),
																												        ((25, 33), "sentence"),
																												        ((33, 34), "."),
																												        ((0, 0), tokenizer_r.sep_token),
																												    ]
																												    if not do_lower_case
																												    else [
																												        ((0, 0), tokenizer_r.cls_token),
																												        ((0, 1), "a"),
																												        ((1, 2), ","),
																												        ((3, 8), "naive"),
																												        ((9, 15), tokenizer_r.mask_token),
																												        ((16, 21), "allen"),
																												        ((21, 23), "##nl"),
																												        ((23, 24), "##p"),
																												        ((25, 33), "sentence"),
																												        ((33, 34), "."),
																												        ((0, 0), tokenizer_r.sep_token),
																												    ]
																												)

																												self.assertEqual(
																												    [e[1] for e in expected_results],     tokenizer_r.convert_ids_to_tokens(tokens["input_ids"]))
																												self.assertEqual([e[0] for e in expected_results],     tokens["offset_mapping"])







							def   snake_case__ (  self):

														'''simple docstring'''

														_lowerCAmelCase	:				Optional[int]					  =       ["的", "人", "有"]
														_lowerCAmelCase	:				Optional[Any]					  =       "".join(a_)
														for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
																					with self.subTest(f"{tokenizer.__class__.__name__} ({pretrained_name})"):
																												_lowerCAmelCase	:				List[Any]					  =       True
																												_lowerCAmelCase	:				int					  =       self.tokenizer_class.from_pretrained(a_,     **a_)
																												_lowerCAmelCase	:				List[str]					  =       self.rust_tokenizer_class.from_pretrained(a_,     **a_)

																												_lowerCAmelCase	:				Tuple					  =       tokenizer_p.encode(a_,     add_special_tokens=a_)
																												_lowerCAmelCase	:				Any					  =       tokenizer_r.encode(a_,     add_special_tokens=a_)

																												_lowerCAmelCase	:				Union[str, Any]					  =       tokenizer_r.convert_ids_to_tokens(a_)
																												_lowerCAmelCase	:				int					  =       tokenizer_p.convert_ids_to_tokens(a_)

																												# it is expected that each Chinese character is not preceded by "##"
																												self.assertListEqual(a_,     a_)
																												self.assertListEqual(a_,     a_)

																												_lowerCAmelCase	:				List[str]					  =       False
																												_lowerCAmelCase	:				List[Any]					  =       self.rust_tokenizer_class.from_pretrained(a_,     **a_)
																												_lowerCAmelCase	:				Dict					  =       self.tokenizer_class.from_pretrained(a_,     **a_)

																												_lowerCAmelCase	:				Tuple					  =       tokenizer_r.encode(a_,     add_special_tokens=a_)
																												_lowerCAmelCase	:				List[str]					  =       tokenizer_p.encode(a_,     add_special_tokens=a_)

																												_lowerCAmelCase	:				Union[str, Any]					  =       tokenizer_r.convert_ids_to_tokens(a_)
																												_lowerCAmelCase	:				Dict					  =       tokenizer_p.convert_ids_to_tokens(a_)

																												# it is expected that only the first Chinese character is not preceded by "##".
																												_lowerCAmelCase	:				Tuple					  =       [
																												    f"##{token}" if idx != 0 else token for idx, token in enumerate(a_)
																												]
																												self.assertListEqual(a_,     a_)
																												self.assertListEqual(a_,     a_)







'''simple docstring'''






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


lowerCAmelCase									=   random.Random()






def   __A    (				a_    :	Union[str, Any]   ,a_    :	Tuple=1.0   ,a_    :	Optional[int]=None   ,a_    :	Union[str, Any]=None						):
		if rng is None:
				lowerCAmelCase  :     str       						= global_rng

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

		return values
class 		lowerCamelCase	(   unittest.TestCase							):



	def __init__( self		,   a_		,   a_=7		,   a_=400		,   a_=2_000		,   a_=1		,   a_=0.0		,   a_=16_000		,   a_=True		,   a_=True		,   ):
			lowerCAmelCase  :     Dict       						= parent
			lowerCAmelCase  :     Optional[int]       						= batch_size
			lowerCAmelCase  :     Dict       						= min_seq_length
			lowerCAmelCase  :     Dict       						= max_seq_length
			lowerCAmelCase  :     Optional[Any]       						= (self.max_seq_length - self.min_seq_length) // (self.batch_size - 1)
			lowerCAmelCase  :     Union[str, Any]       						= feature_size
			lowerCAmelCase  :     Tuple       						= padding_value
			lowerCAmelCase  :     Dict       						= sampling_rate
			lowerCAmelCase  :     int       						= return_attention_mask
			lowerCAmelCase  :     Optional[Any]       						= do_normalize



	def 	_lowerCamelCase     ( self						):
			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 	_lowerCamelCase     ( self		,   a_=False		,   a_=False						):
			def _flatten(a_						):
					return list(itertools.chain(*a_						)						)

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

			return speech_inputs






class 		lowerCamelCase	(   _A   , unittest.TestCase							):
	snake_case_   = WavaVecaFeatureExtractor



	def 	_lowerCamelCase     ( self						):
			lowerCAmelCase  :     Tuple       						= WavaVecaFeatureExtractionTester(self						)



	def 	_lowerCamelCase     ( self		,   a_						):
			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 	_lowerCamelCase     ( self						):
			# Tests that all call wrap to encode_plus and batch_encode_plus
			lowerCAmelCase  :     int       						= self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()						)
			# create three inputs of length 800, 1000, and 1200
			lowerCAmelCase  :     str       						= [floats_list((1, x)						)[0] for x in range(800		,   1_400		,   200						)]
			lowerCAmelCase  :     Dict       						= [np.asarray(a_						) for speech_input in speech_inputs]

			# Test not batched input
			lowerCAmelCase  :     Optional[int]       						= feat_extract(speech_inputs[0]		,   return_tensors="np"						).input_values
			lowerCAmelCase  :     Any       						= feat_extract(np_speech_inputs[0]		,   return_tensors="np"						).input_values
			self.assertTrue(np.allclose(a_		,   a_		,   atol=1e-3						)						)

			# Test batched
			lowerCAmelCase  :     Any       						= feat_extract(a_		,   return_tensors="np"						).input_values
			lowerCAmelCase  :     int       						= 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  :     Dict       						= [floats_list((1, x)						)[0] for x in (800, 800, 800)]
			lowerCAmelCase  :     Tuple       						= np.asarray(a_						)
			lowerCAmelCase  :     int       						= 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 	_lowerCamelCase     ( self						):
			lowerCAmelCase  :     int       						= self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()						)
			lowerCAmelCase  :     Any       						= [floats_list((1, x)						)[0] for x in range(800		,   1_400		,   200						)]

			lowerCAmelCase  :     Union[str, Any]       						= ["longest", "max_length", "do_not_pad"]
			lowerCAmelCase  :     Optional[int]       						= [None, 1_600, None]
			for max_length, padding in zip(a_		,   a_						):
					lowerCAmelCase  :     List[Any]       						= feat_extract(a_		,   padding=a_		,   max_length=a_		,   return_tensors="np"						)
					lowerCAmelCase  :     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][: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						):
			lowerCAmelCase  :     List[Any]       						= self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()						)
			lowerCAmelCase  :     Optional[int]       						= range(800		,   1_400		,   200						)
			lowerCAmelCase  :     Tuple       						= [floats_list((1, x)						)[0] for x in lengths]

			lowerCAmelCase  :     str       						= ["longest", "max_length", "do_not_pad"]
			lowerCAmelCase  :     Any       						= [None, 1_600, None]

			for max_length, padding in zip(a_		,   a_						):
					lowerCAmelCase  :     Dict       						= feat_extract(a_		,   max_length=a_		,   padding=a_						)
					lowerCAmelCase  :     int       						= 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						):
			lowerCAmelCase  :     List[Any]       						= self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()						)
			lowerCAmelCase  :     Tuple       						= [floats_list((1, x)						)[0] for x in range(800		,   1_400		,   200						)]
			lowerCAmelCase  :     Dict       						= feat_extract(
			    a_		,   truncation=a_		,   max_length=1_000		,   padding="max_length"		,   return_tensors="np"						)
			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]						)
			self._check_zero_mean_unit_variance(input_values[2]						)



	def 	_lowerCamelCase     ( self						):
			lowerCAmelCase  :     Optional[int]       						= self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()						)
			lowerCAmelCase  :     Tuple       						= [floats_list((1, x)						)[0] for x in range(800		,   1_400		,   200						)]
			lowerCAmelCase  :     Union[str, Any]       						= feat_extract(
			    a_		,   truncation=a_		,   max_length=1_000		,   padding="longest"		,   return_tensors="np"						)
			lowerCAmelCase  :     Dict       						= 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)						)

			lowerCAmelCase  :     List[str]       						= [floats_list((1, x)						)[0] for x in range(800		,   1_400		,   200						)]
			lowerCAmelCase  :     Union[str, Any]       						= feat_extract(
			    a_		,   truncation=a_		,   max_length=2_000		,   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, :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)						)



	@require_torch
	def 	_lowerCamelCase     ( self						):
			import torch

			lowerCAmelCase  :     Optional[int]       						= self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()						)
			lowerCAmelCase  :     List[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  :     Union[str, Any]       						= feature_extractor.pad([{"input_values": inputs}]		,   return_tensors="np"						)
					self.assertTrue(np_processed.input_values.dtype == np.floataa						)
					lowerCAmelCase  :     Tuple       						= feature_extractor.pad([{"input_values": inputs}]		,   return_tensors="pt"						)
					self.assertTrue(pt_processed.input_values.dtype == torch.floataa						)





	@slow
	@require_torch
	def 	_lowerCamelCase     ( self						):
			# this test makes sure that models that are using
			# group norm don't have their feature extractor return the
			# attention_mask
			for model_id in WAV_2_VEC_2_PRETRAINED_MODEL_ARCHIVE_LIST:
					lowerCAmelCase  :     Any       						= WavaVecaConfig.from_pretrained(a_						)
					lowerCAmelCase  :     List[str]       						= 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"						)



