






"""simple docstring"""



import unittest

from transformers import FunnelConfig, FunnelTokenizer, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
 import torch

 from transformers import (
     MODEL_FOR_PRETRAINING_MAPPING,
     FunnelBaseModel,
     FunnelForMaskedLM,
     FunnelForMultipleChoice,
     FunnelForPreTraining,
     FunnelForQuestionAnswering,
     FunnelForSequenceClassification,
     FunnelForTokenClassification,
     FunnelModel,
 )


class 	_UpperCamelCase :



    '''simple docstring'''


    def __init__(      self   ,			__lowercase   ,			__lowercase=13   ,			__lowercase=7   ,			__lowercase=True   ,			__lowercase=True   ,			__lowercase=True   ,			__lowercase=True   ,			__lowercase=99   ,			__lowercase=[1, 1, 2]   ,			__lowercase=1   ,			__lowercase=32   ,			__lowercase=4   ,			__lowercase=8   ,			__lowercase=37   ,			__lowercase="gelu_new"   ,			__lowercase=0.1   ,			__lowercase=0.1   ,			__lowercase=0.0   ,			__lowercase=512   ,			__lowercase=3   ,			__lowercase=0.02   ,			__lowercase=3   ,			__lowercase=4   ,			__lowercase=None   ,			__lowercase=False   ,			):
     UpperCAmelCase__ 						=				parent
     UpperCAmelCase__ 						=				batch_size
     UpperCAmelCase__ 						=				seq_length
     UpperCAmelCase__ 						=				is_training
     UpperCAmelCase__ 						=				use_input_mask
     UpperCAmelCase__ 						=				use_token_type_ids
     UpperCAmelCase__ 						=				use_labels
     UpperCAmelCase__ 						=				vocab_size
     UpperCAmelCase__ 						=				block_sizes
     UpperCAmelCase__ 						=				num_decoder_layers
     UpperCAmelCase__ 						=				d_model
     UpperCAmelCase__ 						=				n_head
     UpperCAmelCase__ 						=				d_head
     UpperCAmelCase__ 						=				d_inner
     UpperCAmelCase__ 						=				hidden_act
     UpperCAmelCase__ 						=				hidden_dropout
     UpperCAmelCase__ 						=				attention_dropout
     UpperCAmelCase__ 						=				activation_dropout
     UpperCAmelCase__ 						=				max_position_embeddings
     UpperCAmelCase__ 						=				type_vocab_size
     UpperCAmelCase__ 						=				2
     UpperCAmelCase__ 						=				num_labels
     UpperCAmelCase__ 						=				num_choices
     UpperCAmelCase__ 						=				scope
     UpperCAmelCase__ 						=				initializer_std

     # Used in the tests to check the size of the first attention layer
     UpperCAmelCase__ 						=				n_head
     # Used in the tests to check the size of the first hidden state
     UpperCAmelCase__ 						=				self.d_model
     # Used in the tests to check the number of output hidden states/attentions
     UpperCAmelCase__ 						=				sum(self.block_sizes			) + (0 if base else self.num_decoder_layers)
     # FunnelModel adds two hidden layers: input embeddings and the sum of the upsampled encoder hidden state with
     # the last hidden state of the first block (which is the first hidden state of the decoder).
     if not base:
      UpperCAmelCase__ 						=				self.num_hidden_layers + 2


    def 		A__      (      self			):
     UpperCAmelCase__ 						=				ids_tensor([self.batch_size, self.seq_length]   ,			self.vocab_size			)

     UpperCAmelCase__ 						=				None
     if self.use_input_mask:
      UpperCAmelCase__ 						=				ids_tensor([self.batch_size, self.seq_length]   ,			vocab_size=2			)

     UpperCAmelCase__ 						=				None
     if self.use_token_type_ids:
      UpperCAmelCase__ 						=				ids_tensor([self.batch_size, self.seq_length]   ,			self.type_vocab_size			)

     UpperCAmelCase__ 						=				None
     UpperCAmelCase__ 						=				None
     UpperCAmelCase__ 						=				None
     if self.use_labels:
      UpperCAmelCase__ 						=				ids_tensor([self.batch_size]   ,			self.type_sequence_label_size			)
      UpperCAmelCase__ 						=				ids_tensor([self.batch_size, self.seq_length]   ,			self.num_labels			)
      UpperCAmelCase__ 						=				ids_tensor([self.batch_size]   ,			self.num_choices			)
      UpperCAmelCase__ 						=				ids_tensor([self.batch_size, self.seq_length]   ,			1			)

     UpperCAmelCase__ 						=				self.get_config()

     return (
         config,
         input_ids,
         token_type_ids,
         input_mask,
         sequence_labels,
         token_labels,
         choice_labels,
         fake_token_labels,
     )


    def 		A__      (      self			):
     return FunnelConfig(
         vocab_size=self.vocab_size   ,			block_sizes=self.block_sizes   ,			num_decoder_layers=self.num_decoder_layers   ,			d_model=self.d_model   ,			n_head=self.n_head   ,			d_head=self.d_head   ,			d_inner=self.d_inner   ,			hidden_act=self.hidden_act   ,			hidden_dropout=self.hidden_dropout   ,			attention_dropout=self.attention_dropout   ,			activation_dropout=self.activation_dropout   ,			max_position_embeddings=self.max_position_embeddings   ,			type_vocab_size=self.type_vocab_size   ,			initializer_std=self.initializer_std   ,			)


    def 		A__      (      self   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			):
     UpperCAmelCase__ 						=				FunnelModel(config=__lowercase			)
     model.to(__lowercase			)
     model.eval()
     UpperCAmelCase__ 						=				model(__lowercase   ,			attention_mask=__lowercase   ,			token_type_ids=__lowercase			)
     UpperCAmelCase__ 						=				model(__lowercase   ,			token_type_ids=__lowercase			)
     UpperCAmelCase__ 						=				model(__lowercase			)
     self.parent.assertEqual(result.last_hidden_state.shape   ,			(self.batch_size, self.seq_length, self.d_model)			)

     UpperCAmelCase__ 						=				False
     UpperCAmelCase__ 						=				model(__lowercase			)
     self.parent.assertEqual(result.last_hidden_state.shape   ,			(self.batch_size, self.seq_length, self.d_model)			)

     UpperCAmelCase__ 						=				False
     UpperCAmelCase__ 						=				model(__lowercase			)
     self.parent.assertEqual(result.last_hidden_state.shape   ,			(self.batch_size, self.seq_length, self.d_model)			)


    def 		A__      (      self   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			):
     UpperCAmelCase__ 						=				FunnelBaseModel(config=__lowercase			)
     model.to(__lowercase			)
     model.eval()
     UpperCAmelCase__ 						=				model(__lowercase   ,			attention_mask=__lowercase   ,			token_type_ids=__lowercase			)
     UpperCAmelCase__ 						=				model(__lowercase   ,			token_type_ids=__lowercase			)
     UpperCAmelCase__ 						=				model(__lowercase			)
     self.parent.assertEqual(result.last_hidden_state.shape   ,			(self.batch_size, 2, self.d_model)			)

     UpperCAmelCase__ 						=				False
     UpperCAmelCase__ 						=				model(__lowercase			)
     self.parent.assertEqual(result.last_hidden_state.shape   ,			(self.batch_size, 3, self.d_model)			)

     UpperCAmelCase__ 						=				False
     UpperCAmelCase__ 						=				model(__lowercase			)
     self.parent.assertEqual(result.last_hidden_state.shape   ,			(self.batch_size, 2, self.d_model)			)


    def 		A__      (      self   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			):
     UpperCAmelCase__ 						=				self.num_labels
     UpperCAmelCase__ 						=				FunnelForPreTraining(config=__lowercase			)
     model.to(__lowercase			)
     model.eval()
     UpperCAmelCase__ 						=				model(__lowercase   ,			attention_mask=__lowercase   ,			token_type_ids=__lowercase   ,			labels=__lowercase			)
     self.parent.assertEqual(result.logits.shape   ,			(self.batch_size, self.seq_length)			)


    def 		A__      (      self   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			):
     UpperCAmelCase__ 						=				FunnelForMaskedLM(config=__lowercase			)
     model.to(__lowercase			)
     model.eval()
     UpperCAmelCase__ 						=				model(__lowercase   ,			attention_mask=__lowercase   ,			token_type_ids=__lowercase   ,			labels=__lowercase			)
     self.parent.assertEqual(result.logits.shape   ,			(self.batch_size, self.seq_length, self.vocab_size)			)


    def 		A__      (      self   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			):
     UpperCAmelCase__ 						=				self.num_labels
     UpperCAmelCase__ 						=				FunnelForSequenceClassification(__lowercase			)
     model.to(__lowercase			)
     model.eval()
     UpperCAmelCase__ 						=				model(__lowercase   ,			attention_mask=__lowercase   ,			token_type_ids=__lowercase   ,			labels=__lowercase			)
     self.parent.assertEqual(result.logits.shape   ,			(self.batch_size, self.num_labels)			)


    def 		A__      (      self   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			):
     UpperCAmelCase__ 						=				self.num_choices
     UpperCAmelCase__ 						=				FunnelForMultipleChoice(config=__lowercase			)
     model.to(__lowercase			)
     model.eval()
     UpperCAmelCase__ 						=				input_ids.unsqueeze(1			).expand(-1   ,			self.num_choices   ,			-1			).contiguous()
     UpperCAmelCase__ 						=				token_type_ids.unsqueeze(1			).expand(-1   ,			self.num_choices   ,			-1			).contiguous()
     UpperCAmelCase__ 						=				input_mask.unsqueeze(1			).expand(-1   ,			self.num_choices   ,			-1			).contiguous()
     UpperCAmelCase__ 						=				model(
         __lowercase   ,			attention_mask=__lowercase   ,			token_type_ids=__lowercase   ,			labels=__lowercase   ,			)
     self.parent.assertEqual(result.logits.shape   ,			(self.batch_size, self.num_choices)			)


    def 		A__      (      self   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			):
     UpperCAmelCase__ 						=				self.num_labels
     UpperCAmelCase__ 						=				FunnelForTokenClassification(config=__lowercase			)
     model.to(__lowercase			)
     model.eval()
     UpperCAmelCase__ 						=				model(__lowercase   ,			attention_mask=__lowercase   ,			token_type_ids=__lowercase   ,			labels=__lowercase			)
     self.parent.assertEqual(result.logits.shape   ,			(self.batch_size, self.seq_length, self.num_labels)			)


    def 		A__      (      self   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			__lowercase   ,			):
     UpperCAmelCase__ 						=				FunnelForQuestionAnswering(config=__lowercase			)
     model.to(__lowercase			)
     model.eval()
     UpperCAmelCase__ 						=				model(
         __lowercase   ,			attention_mask=__lowercase   ,			token_type_ids=__lowercase   ,			start_positions=__lowercase   ,			end_positions=__lowercase   ,			)
     self.parent.assertEqual(result.start_logits.shape   ,			(self.batch_size, self.seq_length)			)
     self.parent.assertEqual(result.end_logits.shape   ,			(self.batch_size, self.seq_length)			)






    def 		A__      (      self			):
     UpperCAmelCase__ 						=				self.prepare_config_and_inputs()
     (
         UpperCAmelCase__				
     ) 						=				config_and_inputs
     UpperCAmelCase__ 						=				{"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
     return config, inputs_dict



@require_torch
class 	_UpperCamelCase ( lowercase__		,     lowercase__		,     unittest.TestCase							):



    '''simple docstring'''


    __lowercase    :   Optional[int]											=						False
    __lowercase    :   Optional[Any]											=						False
    __lowercase    :   Dict											=						(
        (
            FunnelModel,
            FunnelForMaskedLM,
            FunnelForPreTraining,
            FunnelForQuestionAnswering,
            FunnelForTokenClassification,
        )
        if is_torch_available()
        else ()
    )
    __lowercase    :   List[Any]											=						(
        {
            'feature-extraction': (FunnelBaseModel, FunnelModel),
            'fill-mask': FunnelForMaskedLM,
            'question-answering': FunnelForQuestionAnswering,
            'text-classification': FunnelForSequenceClassification,
            'token-classification': FunnelForTokenClassification,
            'zero-shot': FunnelForSequenceClassification,
        }
        if is_torch_available()
        else {}
    )


    def 		A__      (      self   ,			__lowercase   ,			__lowercase   ,			__lowercase=False			):
     UpperCAmelCase__ 						=				super()._prepare_for_class(__lowercase   ,			__lowercase   ,			return_labels=__lowercase			)

     if return_labels:
      if model_class in get_values(__lowercase			):
       UpperCAmelCase__ 						=				torch.zeros(
           (self.model_tester.batch_size, self.model_tester.seq_length)   ,			dtype=torch.long   ,			device=__lowercase			)
     return inputs_dict


    def 		A__      (      self			):
     UpperCAmelCase__ 						=				FunnelModelTester(self			)
     UpperCAmelCase__ 						=				ConfigTester(self   ,			config_class=__lowercase			)


    def 		A__      (      self			):
     self.config_tester.run_common_tests()


    def 		A__      (      self			):
     UpperCAmelCase__ 						=				self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_model(*__lowercase			)


    def 		A__      (      self			):
     UpperCAmelCase__ 						=				self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_pretraining(*__lowercase			)


    def 		A__      (      self			):
     UpperCAmelCase__ 						=				self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_masked_lm(*__lowercase			)


    def 		A__      (      self			):
     UpperCAmelCase__ 						=				self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_token_classification(*__lowercase			)


    def 		A__      (      self			):
     UpperCAmelCase__ 						=				self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_question_answering(*__lowercase			)






    def 		A__      (      self   ,			__lowercase			):
     if hasattr(__lowercase   ,			"""weight"""			) and module.weight is not None:
      module.weight.data.fill_(3			)
     if hasattr(__lowercase   ,			"""bias"""			) and module.bias is not None:
      module.bias.data.fill_(3			)

     for param in ["r_w_bias", "r_r_bias", "r_kernel", "r_s_bias", "seg_embed"]:
      if hasattr(__lowercase   ,			__lowercase			) and getattr(__lowercase   ,			__lowercase			) is not None:
       UpperCAmelCase__ 						=				getattr(__lowercase   ,			__lowercase			)
       weight.data.fill_(3			)



@require_torch
class 	_UpperCamelCase ( lowercase__		,     unittest.TestCase							):



    '''simple docstring'''


    __lowercase    :   int											=						False
    __lowercase    :   int											=						False
    __lowercase    :   Any											=						(
        (FunnelBaseModel, FunnelForMultipleChoice, FunnelForSequenceClassification) if is_torch_available() else ()
    )


    def 		A__      (      self			):
     UpperCAmelCase__ 						=				FunnelModelTester(self   ,			base=__lowercase			)
     UpperCAmelCase__ 						=				ConfigTester(self   ,			config_class=__lowercase			)


    def 		A__      (      self			):
     self.config_tester.run_common_tests()


    def 		A__      (      self			):
     UpperCAmelCase__ 						=				self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_base_model(*__lowercase			)


    def 		A__      (      self			):
     UpperCAmelCase__ 						=				self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_sequence_classification(*__lowercase			)


    def 		A__      (      self			):
     UpperCAmelCase__ 						=				self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_multiple_choice(*__lowercase			)


    def 		A__      (      self			):
     UpperCAmelCase__ 						=				self.model_tester.prepare_config_and_inputs_for_common()
     UpperCAmelCase__ 						=				True

     for model_class in self.all_model_classes:
      if model_class.__name__ == "FunnelBaseModel":
       continue
      UpperCAmelCase__ 						=				model_class(__lowercase			)
      model.to(__lowercase			)
      model.train()
      UpperCAmelCase__ 						=				self._prepare_for_class(__lowercase   ,			__lowercase   ,			return_labels=__lowercase			)
      UpperCAmelCase__ 						=				model(**__lowercase			).loss
      loss.backward()






    def 		A__      (      self   ,			__lowercase			):
     if hasattr(__lowercase   ,			"""weight"""			) and module.weight is not None:
      module.weight.data.fill_(3			)
     if hasattr(__lowercase   ,			"""bias"""			) and module.bias is not None:
      module.bias.data.fill_(3			)

     for param in ["r_w_bias", "r_r_bias", "r_kernel", "r_s_bias", "seg_embed"]:
      if hasattr(__lowercase   ,			__lowercase			) and getattr(__lowercase   ,			__lowercase			) is not None:
       UpperCAmelCase__ 						=				getattr(__lowercase   ,			__lowercase			)
       weight.data.fill_(3			)



@require_torch
@require_sentencepiece
@require_tokenizers
class 	_UpperCamelCase ( unittest.TestCase							):



    '''simple docstring'''


    def 		A__      (      self			):
     UpperCAmelCase__ 						=				13
     UpperCAmelCase__ 						=				7
     UpperCAmelCase__ 						=				torch.arange(0   ,			batch_size * sequence_length			).long().reshape(__lowercase   ,			__lowercase			)
     UpperCAmelCase__ 						=				[0, 1, 2, 3, 4, 5, 6, 4, 1, 3, 5, 0, 1]
     UpperCAmelCase__ 						=				torch.tensor([[2] + [0] * a + [1] * (sequence_length - a - 1) for a in lengths]			)

     UpperCAmelCase__ 						=				FunnelModel.from_pretrained("""sgugger/funnel-random-tiny"""			)
     UpperCAmelCase__ 						=				model(__lowercase   ,			token_type_ids=__lowercase			)[0].abs()

     UpperCAmelCase__ 						=				torch.tensor(2_344.8_352			)
     UpperCAmelCase__ 						=				torch.tensor(0.8_052			)
     self.assertTrue(torch.allclose(output.sum()   ,			__lowercase   ,			atol=1e-4			)			)
     self.assertTrue(torch.allclose(output.mean()   ,			__lowercase   ,			atol=1e-4			)			)

     UpperCAmelCase__ 						=				torch.tensor([[1] * 7, [1] * 4 + [0] * 3] * 6 + [[0, 1, 1, 0, 0, 1, 1]]			)
     UpperCAmelCase__ 						=				model(__lowercase   ,			attention_mask=__lowercase   ,			token_type_ids=__lowercase			)[0].abs()

     UpperCAmelCase__ 						=				torch.tensor(2_343.8_425			)
     UpperCAmelCase__ 						=				torch.tensor(0.8_049			)
     self.assertTrue(torch.allclose(output.sum()   ,			__lowercase   ,			atol=1e-4			)			)
     self.assertTrue(torch.allclose(output.mean()   ,			__lowercase   ,			atol=1e-4			)			)






    @slow
    def 		A__      (      self			):
     UpperCAmelCase__ 						=				FunnelTokenizer.from_pretrained("""huggingface/funnel-small"""			)
     UpperCAmelCase__ 						=				FunnelModel.from_pretrained("""huggingface/funnel-small"""			)
     UpperCAmelCase__ 						=				tokenizer("""Hello! I am the Funnel Transformer model."""   ,			return_tensors="""pt"""			)
     UpperCAmelCase__ 						=				model(**__lowercase			)[0]

     UpperCAmelCase__ 						=				torch.tensor(235.7_246			)
     UpperCAmelCase__ 						=				torch.tensor(0.0_256			)
     self.assertTrue(torch.allclose(output.sum()   ,			__lowercase   ,			atol=1e-4			)			)
     self.assertTrue(torch.allclose(output.mean()   ,			__lowercase   ,			atol=1e-4			)			)










from typing import List, Optional, Union

import numpy as np

from ...feature_extraction_sequence_utils import SequenceFeatureExtractor
from ...feature_extraction_utils import BatchFeature
from ...utils import PaddingStrategy, TensorType, logging


__lowercase							:Optional[int]							=	logging.get_logger(__name__)



class  _a  (					lowercase__				):






							"""simple docstring"""

							snake_case_							=    ["input_values", "attention_mask"]

							def __init__(   self					:  List[str]				,						a					:  Dict=1				,						a					:  Tuple=1_60_00				,						a					:  Union[str, Any]=0.0				,						a					:  Dict=False				,						a					:  List[Any]=True				,						**a					:  Any				,						)						->Optional[int]:
													super().__init__(feature_size=a				,						sampling_rate=a				,						padding_value=a				,						**a     )
													SCREAMING_SNAKE_CASE__  :					int =       return_attention_mask
													SCREAMING_SNAKE_CASE__  :					str =       do_normalize

							@staticmethod
							def   A_	(   a					:  List[np.ndarray]				,						a					:  List[np.ndarray]				,						a					:  float = 0.0     )						->List[np.ndarray]:
													if attention_mask is not None:
																			SCREAMING_SNAKE_CASE__  :					int =       np.array(a				,						np.intaa     )
																			SCREAMING_SNAKE_CASE__  :					List[str] =       []

																			for vector, length in zip(a				,						attention_mask.sum(-1     )     ):
																									SCREAMING_SNAKE_CASE__  :					List[str] =       (vector - vector[:length].mean()) / np.sqrt(vector[:length].var() + 1E-7     )
																									if length < normed_slice.shape[0]:
																															SCREAMING_SNAKE_CASE__  :					Tuple =       padding_value

																									normed_input_values.append(a     )
													else:
																			SCREAMING_SNAKE_CASE__  :					List[Any] =       [(x - x.mean()) / np.sqrt(x.var() + 1E-7     ) for x in input_values]

													return normed_input_values






							def __call__(   self					:  Union[str, Any]				,						a					:  Union[np.ndarray, List[float], List[np.ndarray], List[List[float]]]				,						a					:  Union[bool, str, PaddingStrategy] = False				,						a					:  Optional[int] = None				,						a					:  bool = False				,						a					:  Optional[int] = None				,						a					:  Optional[bool] = None				,						a					:  Optional[Union[str, TensorType]] = None				,						a					:  Optional[int] = None				,						**a					:  Optional[Any]				,						)						->BatchFeature:

													if sampling_rate is not None:
																			if sampling_rate != self.sampling_rate:
																									raise ValueError(
																									    f"""The model corresponding to this feature extractor: {self} was trained using a sampling rate of"""
																									    f""" {self.sampling_rate}. Please make sure that the provided `raw_speech` input was sampled with"""
																									    f""" {self.sampling_rate} and not {sampling_rate}."""     )
													else:
																			logger.warning(
																			    "It is strongly recommended to pass the ``sampling_rate`` argument to this function. "
																			    "Failing to do so can result in silent errors that might be hard to debug."     )

													SCREAMING_SNAKE_CASE__  :					List[Any] =       isinstance(a				,						np.ndarray     ) and len(raw_speech.shape     ) > 1
													if is_batched_numpy and len(raw_speech.shape     ) > 2:
																			raise ValueError(f"""Only mono-channel audio is supported for input to {self}"""     )
													SCREAMING_SNAKE_CASE__  :					List[Any] =       is_batched_numpy or (
													    isinstance(a				,						(list, tuple)     ) and (isinstance(raw_speech[0]				,						(np.ndarray, tuple, list)     ))
													)

													# always return batch
													if not is_batched:
																			SCREAMING_SNAKE_CASE__  :					Any =       [raw_speech]

													# convert into correct format for padding
													SCREAMING_SNAKE_CASE__  :					Any =       BatchFeature({"input_values": raw_speech}     )

													SCREAMING_SNAKE_CASE__  :					Tuple =       self.pad(
													    a				,						padding=a				,						max_length=a				,						truncation=a				,						pad_to_multiple_of=a				,						return_attention_mask=a				,						)

													# convert input values to correct format
													SCREAMING_SNAKE_CASE__  :					Any =       padded_inputs["input_values"]
													if not isinstance(input_values[0]				,						np.ndarray     ):
																			SCREAMING_SNAKE_CASE__  :					Optional[Any] =       [np.asarray(a				,						dtype=np.floataa     ) for array in input_values]
													elif (
													    not isinstance(a				,						np.ndarray     )
													    and isinstance(input_values[0]				,						np.ndarray     )
													    and input_values[0].dtype is np.dtype(np.floataa     )
													):
																			SCREAMING_SNAKE_CASE__  :					List[Any] =       [array.astype(np.floataa     ) for array in input_values]
													elif isinstance(a				,						np.ndarray     ) and input_values.dtype is np.dtype(np.floataa     ):
																			SCREAMING_SNAKE_CASE__  :					Union[str, Any] =       input_values.astype(np.floataa     )

													# convert attention_mask to correct format
													SCREAMING_SNAKE_CASE__  :					Dict =       padded_inputs.get("attention_mask"     )
													if attention_mask is not None:
																			SCREAMING_SNAKE_CASE__  :					Optional[int] =       [np.asarray(a				,						dtype=np.intaa     ) for array in attention_mask]

													# zero-mean and unit-variance normalization
													if self.do_normalize:
																			SCREAMING_SNAKE_CASE__  :					int =       (
																			    attention_mask
																			    if self._get_padding_strategies(a				,						max_length=a     ) is not PaddingStrategy.DO_NOT_PAD
																			    else None
																			)
																			SCREAMING_SNAKE_CASE__  :					Optional[int] =       self.zero_mean_unit_var_norm(
																			    padded_inputs["input_values"]				,						attention_mask=a				,						padding_value=self.padding_value     )

													if return_tensors is not None:
																			SCREAMING_SNAKE_CASE__  :					Optional[int] =       padded_inputs.convert_to_tensors(a     )

													return padded_inputs