from __future__ import annotations

import unittest

from transformers import EsmConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
      import numpy
      import tensorflow as tf

      from transformers.models.esm.modeling_tf_esm import (
          TF_ESM_PRETRAINED_MODEL_ARCHIVE_LIST,
          TFEsmForMaskedLM,
          TFEsmForSequenceClassification,
          TFEsmForTokenClassification,
          TFEsmModel,
      )





class      A							:


   def __init__(self     :						List[str]       ,  __UpperCAmelCase     :						Optional[Any]       ,  )						->				List[Any]:
         """simple docstring"""



         UpperCAmelCase__								=  parent
         UpperCAmelCase__								=  1_3
         UpperCAmelCase__								=  7
         UpperCAmelCase__								=  True
         UpperCAmelCase__								=  True
         UpperCAmelCase__								=  True
         UpperCAmelCase__								=  9_9
         UpperCAmelCase__								=  3_2
         UpperCAmelCase__								=  2
         UpperCAmelCase__								=  4
         UpperCAmelCase__								=  3_7
         UpperCAmelCase__								=  "gelu"
         UpperCAmelCase__								=  0.1
         UpperCAmelCase__								=  0.1
         UpperCAmelCase__								=  5_1_2
         UpperCAmelCase__								=  1_6
         UpperCAmelCase__								=  2
         UpperCAmelCase__								=  0.02
         UpperCAmelCase__								=  3
         UpperCAmelCase__								=  4
         UpperCAmelCase__								=  None


   def 			lowercase_      (self     :						Optional[Any]		)						->				str:
         """simple docstring"""



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

         UpperCAmelCase__								=  None
         if self.use_input_mask:
               UpperCAmelCase__								=  random_attention_mask([self.batch_size, self.seq_length]		)

         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__								=  EsmConfig(
             vocab_size=self.vocab_size       ,  hidden_size=self.hidden_size       ,  num_hidden_layers=self.num_hidden_layers       ,  pad_token_id=1       ,  num_attention_heads=self.num_attention_heads       ,  intermediate_size=self.intermediate_size       ,  hidden_act=self.hidden_act       ,  hidden_dropout_prob=self.hidden_dropout_prob       ,  attention_probs_dropout_prob=self.attention_probs_dropout_prob       ,  max_position_embeddings=self.max_position_embeddings       ,  type_vocab_size=self.type_vocab_size       ,  initializer_range=self.initializer_range       ,  )

         return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels


   def 			lowercase_      (self     :						Union[str, Any]		)						->				Tuple:
         """simple docstring"""



         (
             (
             UpperCAmelCase__
         )		,      (
             UpperCAmelCase__
         )		,      (
             UpperCAmelCase__
         )		,      (
             UpperCAmelCase__
         )		,      (
             UpperCAmelCase__
         )		,      (
             UpperCAmelCase__
         )		,      
         )								=  self.prepare_config_and_inputs()

         UpperCAmelCase__								=  True
         UpperCAmelCase__								=  floats_tensor([self.batch_size, self.seq_length, self.hidden_size]		)
         UpperCAmelCase__								=  ids_tensor([self.batch_size, self.seq_length]       ,  vocab_size=2		)

         return (
             config,
             input_ids,
             input_mask,
             sequence_labels,
             token_labels,
             choice_labels,
             encoder_hidden_states,
             encoder_attention_mask,
         )


   def 			lowercase_      (self     :						Any       ,  __UpperCAmelCase     :						List[Any]       ,  __UpperCAmelCase     :						List[str]       ,  __UpperCAmelCase     :						List[Any]       ,  __UpperCAmelCase     :						Dict       ,  __UpperCAmelCase     :						Union[str, Any]       ,  __UpperCAmelCase     :						int		)						->				str:
         """simple docstring"""



         UpperCAmelCase__								=  TFEsmModel(config=__UpperCAmelCase		)
         UpperCAmelCase__								=  {"input_ids": input_ids, "attention_mask": input_mask}
         UpperCAmelCase__								=  model(__UpperCAmelCase		)

         UpperCAmelCase__								=  [input_ids, input_mask]
         UpperCAmelCase__								=  model(__UpperCAmelCase		)

         UpperCAmelCase__								=  model(__UpperCAmelCase		)

         self.parent.assertEqual(result.last_hidden_state.shape       ,  (self.batch_size, self.seq_length, self.hidden_size)		)


   def 			lowercase_      (self     :						Optional[Any]       ,  __UpperCAmelCase     :						Union[str, Any]       ,  __UpperCAmelCase     :						Optional[int]       ,  __UpperCAmelCase     :						Dict       ,  __UpperCAmelCase     :						List[Any]       ,  __UpperCAmelCase     :						Optional[Any]       ,  __UpperCAmelCase     :						Optional[int]       ,  __UpperCAmelCase     :						Any       ,  __UpperCAmelCase     :						Tuple       ,  )						->				List[str]:
         """simple docstring"""



         UpperCAmelCase__								=  True

         UpperCAmelCase__								=  TFEsmModel(config=__UpperCAmelCase		)
         UpperCAmelCase__								=  {
             "input_ids": input_ids,
             "attention_mask": input_mask,
             "encoder_hidden_states": encoder_hidden_states,
             "encoder_attention_mask": encoder_attention_mask,
         }
         UpperCAmelCase__								=  model(__UpperCAmelCase		)

         UpperCAmelCase__								=  [input_ids, input_mask]
         UpperCAmelCase__								=  model(__UpperCAmelCase       ,  encoder_hidden_states=__UpperCAmelCase		)

         # Also check the case where encoder outputs are not passed
         UpperCAmelCase__								=  model(__UpperCAmelCase       ,  attention_mask=__UpperCAmelCase		)

         self.parent.assertEqual(result.last_hidden_state.shape       ,  (self.batch_size, self.seq_length, self.hidden_size)		)


   def 			lowercase_      (self     :						Optional[Any]       ,  __UpperCAmelCase     :						List[Any]       ,  __UpperCAmelCase     :						Tuple       ,  __UpperCAmelCase     :						int       ,  __UpperCAmelCase     :						List[str]       ,  __UpperCAmelCase     :						Tuple       ,  __UpperCAmelCase     :						int		)						->				Optional[Any]:
         """simple docstring"""



         UpperCAmelCase__								=  TFEsmForMaskedLM(config=__UpperCAmelCase		)
         UpperCAmelCase__								=  model([input_ids, input_mask]		)
         self.parent.assertEqual(result.logits.shape       ,  (self.batch_size, self.seq_length, self.vocab_size)		)


   def 			lowercase_      (self     :						Any       ,  __UpperCAmelCase     :						Optional[int]       ,  __UpperCAmelCase     :						List[Any]       ,  __UpperCAmelCase     :						Dict       ,  __UpperCAmelCase     :						List[Any]       ,  __UpperCAmelCase     :						Optional[Any]       ,  __UpperCAmelCase     :						Optional[Any]		)						->				int:
         """simple docstring"""



         UpperCAmelCase__								=  self.num_labels
         UpperCAmelCase__								=  TFEsmForTokenClassification(config=__UpperCAmelCase		)
         UpperCAmelCase__								=  {"input_ids": input_ids, "attention_mask": input_mask}
         UpperCAmelCase__								=  model(__UpperCAmelCase		)
         self.parent.assertEqual(result.logits.shape       ,  (self.batch_size, self.seq_length, self.num_labels)		)





   def 			lowercase_      (self     :						List[str]		)						->				List[Any]:
         """simple docstring"""



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





@require_tf
class      A							(				UpperCAmelCase_		,				UpperCAmelCase_		,				unittest.TestCase     ):
   __UpperCAmelCase : List[str]      =			(
       (
           TFEsmModel,
           TFEsmForMaskedLM,
           TFEsmForSequenceClassification,
           TFEsmForTokenClassification,
       )
       if is_tf_available()
       else ()
   )
   __UpperCAmelCase : Optional[int]      =			(
       {
           'feature-extraction': TFEsmModel,
           'fill-mask': TFEsmForMaskedLM,
           'text-classification': TFEsmForSequenceClassification,
           'token-classification': TFEsmForTokenClassification,
           'zero-shot': TFEsmForSequenceClassification,
       }
       if is_tf_available()
       else {}
   )
   __UpperCAmelCase : str      =			False
   __UpperCAmelCase : Union[str, Any]      =			False


   def 			lowercase_      (self     :						Dict		)						->				Optional[Any]:
         """simple docstring"""



         UpperCAmelCase__								=  TFEsmModelTester(self		)
         UpperCAmelCase__								=  ConfigTester(self       ,  config_class=__UpperCAmelCase       ,  hidden_size=3_7		)


   def 			lowercase_      (self     :						List[Any]		)						->				int:
         """simple docstring"""



         self.config_tester.run_common_tests()


   def 			lowercase_      (self     :						str		)						->				str:
         """simple docstring"""



         UpperCAmelCase__								=  self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*__UpperCAmelCase		)


   def 			lowercase_      (self     :						List[Any]		)						->				int:
         """simple docstring"""



         UpperCAmelCase__								=  self.model_tester.prepare_config_and_inputs_for_decoder()
         self.model_tester.create_and_check_model_as_decoder(*__UpperCAmelCase		)


   def 			lowercase_      (self     :						Dict		)						->				Tuple:
         """simple docstring"""



         UpperCAmelCase__								=  self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_masked_lm(*__UpperCAmelCase		)


   def 			lowercase_      (self     :						List[str]		)						->				int:
         """simple docstring"""



         UpperCAmelCase__								=  self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_token_classification(*__UpperCAmelCase		)


   @slow
   def 			lowercase_      (self     :						List[Any]		)						->				str:
         """simple docstring"""



         for model_name in TF_ESM_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
               UpperCAmelCase__								=  TFEsmModel.from_pretrained(__UpperCAmelCase		)
               self.assertIsNotNone(__UpperCAmelCase		)


   @unittest.skip("Protein models do not support embedding resizing."		)
   def 			lowercase_      (self     :						Optional[int]		)						->				Union[str, Any]:
         """simple docstring"""



         pass


   @unittest.skip("Protein models do not support embedding resizing."		)
   def 			lowercase_      (self     :						Dict		)						->				str:
         """simple docstring"""



         pass





   def 			lowercase_      (self     :						Tuple		)						->				Union[str, Any]:
         """simple docstring"""



         UpperCAmelCase__		,      UpperCAmelCase__								=  self.model_tester.prepare_config_and_inputs_for_common()

         for model_class in self.all_model_classes:
               UpperCAmelCase__								=  model_class(__UpperCAmelCase		)
               assert isinstance(model.get_input_embeddings()       ,  tf.keras.layers.Layer		)
               if model_class is TFEsmForMaskedLM:
                     # Output embedding test differs from the main test because they're a matrix, not a layer
                     UpperCAmelCase__								=  model.get_bias()
                     assert isinstance(__UpperCAmelCase       ,  __UpperCAmelCase		)
                     for k, v in name.items():
                           assert isinstance(__UpperCAmelCase       ,  tf.Variable		)
               else:
                     UpperCAmelCase__								=  model.get_output_embeddings()
                     assert x is None
                     UpperCAmelCase__								=  model.get_bias()
                     assert name is None





@require_tf
class      A							(				unittest.TestCase     ):


   @slow
   def 			lowercase_      (self     :						Tuple		)						->				Optional[int]:
         """simple docstring"""



         UpperCAmelCase__								=  TFEsmForMaskedLM.from_pretrained("facebook/esm2_t6_8M_UR50D"		)

         UpperCAmelCase__								=  tf.constant([[0, 1, 2, 3, 4, 5]]		)
         UpperCAmelCase__								=  model(__UpperCAmelCase		)[0]
         UpperCAmelCase__								=  [1, 6, 3_3]
         self.assertEqual(list(output.numpy().shape		)       ,  __UpperCAmelCase		)
         # compare the actual values for a slice.
         UpperCAmelCase__								=  tf.constant(
             [
                 [
                     [8.921518, -10.589814, -6.4671307],
                     [-6.3967156, -13.911377, -1.1211915],
                     [-7.781247, -13.951557, -3.740592],
                 ]
             ]		)
         self.assertTrue(numpy.allclose(output[:, :3, :3].numpy()       ,  expected_slice.numpy()       ,  atol=1E-2		)		)





   @slow
   def 			lowercase_      (self     :						Optional[Any]		)						->				Optional[int]:
         """simple docstring"""



         UpperCAmelCase__								=  TFEsmModel.from_pretrained("facebook/esm2_t6_8M_UR50D"		)

         UpperCAmelCase__								=  tf.constant([[0, 6, 4, 1_3, 5, 4, 1_6, 1_2, 1_1, 7, 2]]		)
         UpperCAmelCase__								=  model(__UpperCAmelCase		)[0]
         # compare the actual values for a slice.
         UpperCAmelCase__								=  tf.constant(
             [
                 [
                     [0.14443092, 0.54125327, 0.3247739],
                     [0.30340484, 0.00526676, 0.31077722],
                     [0.32278043, -0.24987096, 0.3414628],
                 ]
             ]		)
         self.assertTrue(numpy.allclose(output[:, :3, :3].numpy()       ,  expected_slice.numpy()       ,  atol=1E-4		)		)




import warnings
from typing import Any, Dict, List, Optional, Union

import numpy as np

from ...audio_utils import mel_filter_bank, optimal_fft_length, spectrogram, window_function
from ...feature_extraction_sequence_utils import SequenceFeatureExtractor
from ...feature_extraction_utils import BatchFeature
from ...utils import PaddingStrategy, TensorType, logging


UpperCamelCase__											=					logging.get_logger(__name__)





class      A							(				UpperCAmelCase_     ):
   __UpperCAmelCase : int      =			['input_values', 'attention_mask']


   def __init__(self     :						Any       ,  __UpperCAmelCase     :						int = 1       ,  __UpperCAmelCase     :						int = 1_6_0_0_0       ,  __UpperCAmelCase     :						float = 0.0       ,  __UpperCAmelCase     :						bool = False       ,  __UpperCAmelCase     :						int = 8_0       ,  __UpperCAmelCase     :						int = 1_6       ,  __UpperCAmelCase     :						int = 6_4       ,  __UpperCAmelCase     :						str = "hann_window"       ,  __UpperCAmelCase     :						float = 1.0       ,  __UpperCAmelCase     :						float = 8_0       ,  __UpperCAmelCase     :						float = 7_6_0_0       ,  __UpperCAmelCase     :						float = 1E-10       ,  __UpperCAmelCase     :						int = 2       ,  __UpperCAmelCase     :						bool = True       ,  **__UpperCAmelCase     :						Any       ,  )						->				str:
         """simple docstring"""



         super().__init__(feature_size=__UpperCAmelCase       ,  sampling_rate=__UpperCAmelCase       ,  padding_value=__UpperCAmelCase       ,  **__UpperCAmelCase		)
         UpperCAmelCase__								=  do_normalize
         UpperCAmelCase__								=  return_attention_mask

         UpperCAmelCase__								=  num_mel_bins
         UpperCAmelCase__								=  hop_length
         UpperCAmelCase__								=  win_length
         UpperCAmelCase__								=  win_function
         UpperCAmelCase__								=  frame_signal_scale
         UpperCAmelCase__								=  fmin
         UpperCAmelCase__								=  fmax
         UpperCAmelCase__								=  mel_floor
         UpperCAmelCase__								=  reduction_factor

         UpperCAmelCase__								=  win_length * sampling_rate // 1_0_0_0
         UpperCAmelCase__								=  hop_length * sampling_rate // 1_0_0_0
         UpperCAmelCase__								=  optimal_fft_length(self.sample_size		)
         UpperCAmelCase__								=  (self.n_fft // 2) + 1

         UpperCAmelCase__								=  window_function(window_length=self.sample_size       ,  name=self.win_function       ,  periodic=__UpperCAmelCase		)

         UpperCAmelCase__								=  mel_filter_bank(
             num_frequency_bins=self.n_freqs       ,  num_mel_filters=self.num_mel_bins       ,  min_frequency=self.fmin       ,  max_frequency=self.fmax       ,  sampling_rate=self.sampling_rate       ,  norm="slaney"       ,  mel_scale="slaney"       ,  )

         if frame_signal_scale != 1.0:
               warnings.warn(
                   "The argument `frame_signal_scale` is deprecated and will be removed in version 4.30.0 of Transformers"       ,  __UpperCAmelCase       ,  )
         if reduction_factor != 2.0:
               warnings.warn(
                   "The argument `reduction_factor` is deprecated and will be removed in version 4.30.0 of Transformers"       ,  __UpperCAmelCase       ,  )


   @staticmethod
   # Copied from transformers.models.wav2vec2.feature_extraction_wav2vec2.Wav2Vec2FeatureExtractor.zero_mean_unit_var_norm
   def 			lowercase_      (__UpperCAmelCase     :						List[np.ndarray]       ,  __UpperCAmelCase     :						List[np.ndarray]       ,  __UpperCAmelCase     :						float = 0.0		)						->				List[np.ndarray]:
         """simple docstring"""



         if attention_mask is not None:
               UpperCAmelCase__								=  np.array(__UpperCAmelCase       ,  np.intaa		)
               UpperCAmelCase__								=  []

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

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

         return normed_input_values


   def 			lowercase_      (self     :						Optional[int]       ,  __UpperCAmelCase     :						np.ndarray       ,  )						->				np.ndarray:
         """simple docstring"""



         UpperCAmelCase__								=  spectrogram(
             __UpperCAmelCase       ,  window=self.window       ,  frame_length=self.sample_size       ,  hop_length=self.sample_stride       ,  fft_length=self.n_fft       ,  mel_filters=self.mel_filters       ,  mel_floor=self.mel_floor       ,  log_mel="log10"       ,  )
         return log_mel_spec.T


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



         if audio is None and audio_target is None:
               raise ValueError("You must provide either `audio` or `audio_target` values."		)

         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 audio 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."		)

         if audio is not None:
               UpperCAmelCase__								=  self._process_audio(
                   __UpperCAmelCase       ,  __UpperCAmelCase       ,  __UpperCAmelCase       ,  __UpperCAmelCase       ,  __UpperCAmelCase       ,  __UpperCAmelCase       ,  __UpperCAmelCase       ,  __UpperCAmelCase       ,  **__UpperCAmelCase       ,  )
         else:
               UpperCAmelCase__								=  None

         if audio_target is not None:
               UpperCAmelCase__								=  self._process_audio(
                   __UpperCAmelCase       ,  __UpperCAmelCase       ,  __UpperCAmelCase       ,  __UpperCAmelCase       ,  __UpperCAmelCase       ,  __UpperCAmelCase       ,  __UpperCAmelCase       ,  __UpperCAmelCase       ,  **__UpperCAmelCase       ,  )

               if inputs is None:
                     return inputs_target
               else:
                     UpperCAmelCase__								=  inputs_target["input_values"]
                     UpperCAmelCase__								=  inputs_target.get("attention_mask"		)
                     if decoder_attention_mask is not None:
                           UpperCAmelCase__								=  decoder_attention_mask

         return inputs


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



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

         if is_batched:
               UpperCAmelCase__								=  [np.asarray(__UpperCAmelCase       ,  dtype=np.floataa		) for speech in speech]
         elif not is_batched and not isinstance(__UpperCAmelCase       ,  np.ndarray		):
               UpperCAmelCase__								=  np.asarray(__UpperCAmelCase       ,  dtype=np.floataa		)
         elif isinstance(__UpperCAmelCase       ,  np.ndarray		) and speech.dtype is np.dtype(np.floataa		):
               UpperCAmelCase__								=  speech.astype(np.floataa		)

         # always return batch
         if not is_batched:
               UpperCAmelCase__								=  [speech]

         # needed to make pad() work on spectrogram inputs
         UpperCAmelCase__								=  self.feature_size

         # convert into correct format for padding
         if is_target:
               UpperCAmelCase__								=  [self._extract_mel_features(__UpperCAmelCase		) for waveform in speech]
               UpperCAmelCase__								=  BatchFeature({"input_values": features}		)
               UpperCAmelCase__								=  self.num_mel_bins
         else:
               UpperCAmelCase__								=  BatchFeature({"input_values": speech}		)

         UpperCAmelCase__								=  self.pad(
             __UpperCAmelCase       ,  padding=__UpperCAmelCase       ,  max_length=__UpperCAmelCase       ,  truncation=__UpperCAmelCase       ,  pad_to_multiple_of=__UpperCAmelCase       ,  return_attention_mask=__UpperCAmelCase       ,  **__UpperCAmelCase       ,  )

         UpperCAmelCase__								=  feature_size_hack

         # convert input values to correct format
         UpperCAmelCase__								=  padded_inputs["input_values"]
         if not isinstance(input_values[0]       ,  np.ndarray		):
               UpperCAmelCase__								=  [np.asarray(__UpperCAmelCase       ,  dtype=np.floataa		) for array in input_values]
         elif (
             not isinstance(__UpperCAmelCase       ,  np.ndarray		)
             and isinstance(input_values[0]       ,  np.ndarray		)
             and input_values[0].dtype is np.dtype(np.floataa		)
         ):
               UpperCAmelCase__								=  [array.astype(np.floataa		) for array in input_values]
         elif isinstance(__UpperCAmelCase       ,  np.ndarray		) and input_values.dtype is np.dtype(np.floataa		):
               UpperCAmelCase__								=  input_values.astype(np.floataa		)

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

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

         if return_tensors is not None:
               UpperCAmelCase__								=  padded_inputs.convert_to_tensors(__UpperCAmelCase		)

         return padded_inputs





   def 			lowercase_      (self     :						Tuple		)						->				Dict[str, Any]:
         """simple docstring"""



         UpperCAmelCase__								=  super().to_dict()

         # Don't serialize these as they are derived from the other properties.
         UpperCAmelCase__								=  ["window", "mel_filters", "sample_size", "sample_stride", "n_fft", "n_freqs"]
         for name in names:
               if name in output:
                     del output[name]

         return output



