'''simple docstring'''

import argparse
import dataclasses
import json
import logging
import os
import shutil
from typing import List, Optional

import datasets
from accelerate import Accelerator
from datasets import load_dataset
from finetuning import finetune
from tqdm.auto import tqdm

import transformers
from transformers import AutoConfig, set_seed
from transformers.trainer_utils import IntervalStrategy


A_     :						Any    							=logging.getLogger(__name__)

A_     :						str    							='''pytorch_model.bin'''


@dataclasses.dataclass
class     __UpperCAmelCase       :
  __A :				str											= dataclasses.field(
      metadata={'help': 'Path to pretrained model or model identifier from huggingface.co/models.'}		)
  __A :				Optional[str]											= dataclasses.field(
      default=__a						,       metadata={'help': 'Where do you want to store the pretrained models downloaded from huggingface.co.'}						,       )






@dataclasses.dataclass
class     __UpperCAmelCase       :
  __A :				str											= dataclasses.field(metadata={'help': 'A csv or a json file containing the training data.'}		)
  __A :				str											= dataclasses.field(metadata={'help': 'A csv or a json file containing the data to predict on.'}		)
  __A :				Optional[str]											= dataclasses.field(
      default=__a						,       metadata={'help': 'A csv or a json file containing the validation data.'}		)
  __A :				Optional[str]											= dataclasses.field(
      default=__a						,       metadata={'help': 'The name of the task to train on.'}						,       )
  __A :				Optional[List[str]]											= dataclasses.field(
      default=__a						,       metadata={'help': 'The list of labels for the task.'}		)






@dataclasses.dataclass
class     __UpperCAmelCase       :
  __A :				str											= dataclasses.field(
      metadata={'help': 'The output directory where the model predictions and checkpoints will be written.'}		)
  __A :				Optional[str]											= dataclasses.field(
      default='accuracy'						,       metadata={'help': 'The evaluation metric used for the task.'}		)
  __A :				Optional[str]											= dataclasses.field(
      default='no'						,       metadata={
          'help': 'The evaluation strategy to adopt during training. Possible values are: ["no", "step", "epoch]'
      }						,       )
  __A :				Optional[int]											= dataclasses.field(
      default=10						,       metadata={'help': 'Number of evaluation calls with no improvement after which training will be stopped.'}						,       )
  __A :				Optional[float]											= dataclasses.field(
      default=0.0						,       metadata={
          'help': 'How much the specified evaluation metric must improve to satisfy early stopping conditions.'
      }						,       )
  __A :				Optional[bool]											= dataclasses.field(
      default=__a						,       metadata={'help': 'Whether to filter the pseudo-labeled data based on the confidence score.'}						,       )
  __A :				Optional[bool]											= dataclasses.field(
      default=__a						,       metadata={'help': 'Whether to filter the pseudo-labeled data based on the validation performance.'}						,       )
  __A :				Optional[bool]											= dataclasses.field(
      default=__a						,       metadata={'help': 'Whether to fine-tune on labeled data after pseudo training.'}						,       )
  __A :				Optional[float]											= dataclasses.field(
      default=0.0						,       metadata={'help': 'Confidence threshold for pseudo-labeled data filtering.'}						,       )
  __A :				Optional[int]											= dataclasses.field(
      default=1_00						,       metadata={'help': 'Number of evaluation calls with no improvement after which training will be stopped.'}						,       )
  __A :				Optional[int]											= dataclasses.field(
      default=__a						,       metadata={'help': 'Random seed for initialization.'}						,       )






def snake_case_      (					__snake_case  :							str	,   __snake_case  :							Dict	,   __snake_case  :							str	,   __snake_case  :							Any	,   __snake_case  :							Any	,   __snake_case  :							Tuple)			->					List[Any]:
   lowerCAmelCase_			=      datasets.concatenate_datasets([infer_input, infer_output]	,   axis=1)

   if args.do_filter_by_confidence:
      lowerCAmelCase_			=      dataset.filter(lambda __snake_case: example["probability"] > args.confidence_threshold)

   if args.do_filter_by_val_performance:
      assert eval_result >= 0.0 and eval_result <= 1.0
      lowerCAmelCase_			=      int(eval_result * len(__snake_case))
      print(__snake_case)
      lowerCAmelCase_			=      dataset.sort('''probability'''	,   reverse=__snake_case)
      lowerCAmelCase_			=      dataset.select(range(__snake_case))

   lowerCAmelCase_			=      dataset.remove_columns(['''label''', '''probability'''])
   lowerCAmelCase_			=      dataset.rename_column('''prediction'''	,   '''label''')
   lowerCAmelCase_			=      dataset.map(lambda __snake_case: {"label": idalabel[example["label"]]})
   lowerCAmelCase_			=      dataset.shuffle(seed=args.seed)

   lowerCAmelCase_			=      os.path.join(__snake_case	,   F'''train_pseudo.{args.data_file_extension}''')
   if args.data_file_extension == "csv":
      dataset.to_csv(__snake_case	,   index=__snake_case)
   else:
      dataset.to_json(__snake_case)






def snake_case_      (					__snake_case  :							str	,   __snake_case  :							Any	,   __snake_case  :							Union[str, Any]	,   __snake_case  :							List[str]	,   **__snake_case  :							Any)			->					str:
   lowerCAmelCase_			=      Accelerator()
   # Make one log on every process with the configuration for debugging.
   logging.basicConfig(
       format='''%(asctime)s - %(levelname)s - %(name)s - %(message)s'''	,   datefmt='''%m/%d/%Y %H:%M:%S'''	,   level=logging.INFO	,   )
   logger.info(accelerator.state)

   # Setup logging, we only want one process per machine to log things on the
   # screen. accelerator.is_local_main_process is only True for one process per
   # machine.
   logger.setLevel(logging.INFO if accelerator.is_local_main_process else logging.ERROR)

   if accelerator.is_local_main_process:
      datasets.utils.logging.set_verbosity_warning()
      transformers.utils.logging.set_verbosity_info()
   else:
      datasets.utils.logging.set_verbosity_error()
      transformers.utils.logging.set_verbosity_error()

   lowerCAmelCase_			=      STModelArguments(model_name_or_path=__snake_case)
   lowerCAmelCase_			=      STDataArguments(train_file=__snake_case	,   infer_file=__snake_case)
   lowerCAmelCase_			=      STTrainingArguments(output_dir=__snake_case)
   lowerCAmelCase_			=      argparse.Namespace()

   for arg_class in (model_args, data_args, training_args):
      for key, value in vars(__snake_case).items():
         setattr(__snake_case	,   __snake_case	,   __snake_case)

   for key, value in kwargs.items():
      if hasattr(__snake_case	,   __snake_case):
         setattr(__snake_case	,   __snake_case	,   __snake_case)

    # Sanity checks
   lowerCAmelCase_			=      {}
   lowerCAmelCase_			=      None

   # You need to provide the training data and the data to predict on
   assert args.train_file is not None
   assert args.infer_file is not None
   lowerCAmelCase_			=      args.train_file
   lowerCAmelCase_			=      args.infer_file

   if args.evaluation_strategy != IntervalStrategy.NO.value:
      assert args.eval_file is not None
      lowerCAmelCase_			=      args.eval_file

   for key in data_files:
      lowerCAmelCase_			=      data_files[key].split('''.''')[-1]
      assert extension in ["csv", "json"], F'''`{key}_file` should be a csv or a json file.'''
      if args.data_file_extension is None:
         lowerCAmelCase_			=      extension
      else:
         assert extension == args.data_file_extension, F'''`{key}_file` should be a {args.data_file_extension} file`.'''

   assert (
       args.eval_metric in datasets.list_metrics()
   ), F'''{args.eval_metric} not in the list of supported metrics {datasets.list_metrics()}.'''

   # If passed along, set the training seed now.
   if args.seed is not None:
      set_seed(args.seed)

   logger.info('''Creating the initial data directory for self-training...''')
   lowerCAmelCase_			=      F'''{args.output_dir}/self-train_iter-{{}}'''.format
   lowerCAmelCase_			=      data_dir_format(0)

   if accelerator.is_main_process:
      if args.output_dir is not None:
         os.makedirs(args.output_dir	,   exist_ok=__snake_case)
         os.makedirs(__snake_case	,   exist_ok=__snake_case)
   accelerator.wait_for_everyone()

   lowerCAmelCase_			=      None
   lowerCAmelCase_			=      None
   lowerCAmelCase_			=      0
   lowerCAmelCase_			=      False
   # Show the progress bar
   lowerCAmelCase_			=      tqdm(range(args.max_selftrain_iterations)	,   disable=not accelerator.is_local_main_process)

   # Self-train
   for iteration in range(0	,   int(args.max_selftrain_iterations)):
      lowerCAmelCase_			=      data_dir_format(__snake_case)
      assert os.path.exists(__snake_case)

      # Stage 1: initial fine-tuning for iteration = 0 or pseudo-training for
      # iteration > 0
      lowerCAmelCase_			=      os.path.join(__snake_case	,   '''stage-1''')
      lowerCAmelCase_			=      {
          '''accelerator''': accelerator,
          '''model_name_or_path''': args.model_name_or_path,
          '''cache_dir''': args.cache_dir,
          '''do_train''': True,
          '''train_file''': data_files['''train'''] if iteration == 0 else data_files['''train_pseudo'''],
          '''do_eval''': True if args.eval_file is not None else False,
          '''eval_file''': data_files['''eval'''],
          '''do_predict''': True,
          '''infer_file''': data_files['''infer'''],
          '''task_name''': args.task_name,
          '''label_list''': args.label_list,
          '''output_dir''': current_output_dir,
          '''eval_metric''': args.eval_metric,
          '''evaluation_strategy''': args.evaluation_strategy,
          '''early_stopping_patience''': args.early_stopping_patience,
          '''early_stopping_threshold''': args.early_stopping_threshold,
          '''seed''': args.seed,
      }
      # Add additional training arguments
      for key, value in kwargs.items():
         if key not in arguments_dict and not hasattr(__snake_case	,   __snake_case):
            arguments_dict.update({key: value})

      lowerCAmelCase_			=      os.path.join(__snake_case	,   '''best-checkpoint'''	,   __snake_case)
      if os.path.exists(__snake_case):
         logger.info(
             '''Found existing model checkpoint at %s. Skipping self-training: iteration: %d, stage: 1.'''	,   __snake_case	,   __snake_case	,   )
      else:
         logger.info('''***** Running self-training: iteration: %d, stage: 1 *****'''	,   __snake_case)
         finetune(**__snake_case)
         accelerator.wait_for_everyone()
         assert os.path.exists(__snake_case)
         logger.info('''Self-training job completed: iteration: %d, stage: 1.'''	,   __snake_case)

      if iteration > 0 and args.finetune_on_labeled_data:
         # Stage 2 (optional): fine-tuning on the original labeled data
         lowerCAmelCase_			=      os.path.join(__snake_case	,   '''best-checkpoint''')
         lowerCAmelCase_			=      os.path.join(__snake_case	,   '''stage-2''')
         # Update arguments_dict
         lowerCAmelCase_			=      model_path
         lowerCAmelCase_			=      data_files['''train''']
         lowerCAmelCase_			=      current_output_dir

         lowerCAmelCase_			=      os.path.join(__snake_case	,   '''best-checkpoint'''	,   __snake_case)
         if os.path.exists(__snake_case):
            logger.info(
                '''Found existing model checkpoint at %s. Skipping self-training: iteration: %d, stage: 2.'''	,   __snake_case	,   __snake_case	,   )
         else:
            logger.info('''***** Running self-training: iteration: %d, stage: 2 *****'''	,   __snake_case)
            finetune(**__snake_case)
            accelerator.wait_for_everyone()
            assert os.path.exists(__snake_case)
            logger.info('''Self-training job completed: iteration: %d, stage: 2.'''	,   __snake_case)

      lowerCAmelCase_			=      iteration
      lowerCAmelCase_			=      data_dir_format(iteration + 1)

      lowerCAmelCase_			=      AutoConfig.from_pretrained(os.path.join(__snake_case	,   '''best-checkpoint'''))
      lowerCAmelCase_			=      config.idalabel
      lowerCAmelCase_			=      os.path.join(__snake_case	,   '''eval_results_best-checkpoint.json''')
      lowerCAmelCase_			=      os.path.join(__snake_case	,   '''test_results_best-checkpoint.json''')
      assert os.path.exists(__snake_case)

      with open(__snake_case	,   '''r''') as f:
         lowerCAmelCase_			=      float(json.load(__snake_case)[args.eval_metric])
      lowerCAmelCase_			=      os.path.join(__snake_case	,   '''infer_output_best-checkpoint.csv''')
      assert os.path.exists(__snake_case)
      # Loading the dataset from local csv or json files.
      lowerCAmelCase_			=      load_dataset(args.data_file_extension	,   data_files={'''data''': data_files['''infer''']})['''data''']
      lowerCAmelCase_			=      load_dataset('''csv'''	,   data_files={'''data''': infer_output_file})['''data''']

      if accelerator.is_main_process:
         os.makedirs(__snake_case	,   exist_ok=__snake_case)
         shutil.copy(__snake_case	,   os.path.join(__snake_case	,   F'''eval_results_iter-{iteration}.json'''))
         if os.path.exists(__snake_case):
            shutil.copy(__snake_case	,   os.path.join(__snake_case	,   F'''test_results_iter-{iteration}.json'''))
         create_pseudo_labeled_data(__snake_case	,   __snake_case	,   __snake_case	,   __snake_case	,   __snake_case	,   __snake_case)
      accelerator.wait_for_everyone()

      lowerCAmelCase_			=      os.path.join(__snake_case	,   F'''train_pseudo.{args.data_file_extension}''')

      if args.evaluation_strategy != IntervalStrategy.NO.value:
         lowerCAmelCase_			=      eval_result

         if best_iteration is None:
            lowerCAmelCase_			=      new_iteration
            lowerCAmelCase_			=      new_eval_result
         else:
            if new_eval_result - best_eval_result > args.early_stopping_threshold:
               lowerCAmelCase_			=      new_iteration
               lowerCAmelCase_			=      new_eval_result
               lowerCAmelCase_			=      0
            else:
               if new_eval_result == best_eval_result:
                  lowerCAmelCase_			=      new_iteration
                  lowerCAmelCase_			=      new_eval_result
               early_stopping_patience_counter += 1

            if early_stopping_patience_counter >= args.early_stopping_patience:
               lowerCAmelCase_			=      True

      progress_bar.update(1)

      if should_training_stop:
         break

   if best_iteration is not None:
      # Save the best iteration
      logger.info('''Best iteration: %d'''	,   __snake_case)
      logger.info('''Best evaluation result: %s = %f'''	,   args.eval_metric	,   __snake_case)
      accelerator.wait_for_everyone()
      if accelerator.is_main_process:
         shutil.copy(
             os.path.join(__snake_case	,   F'''eval_results_iter-{iteration}.json''')	,   os.path.join(__snake_case	,   '''eval_results_best-iteration.json''')	,   )
   else:
      # Assume that the last iteration is the best
      logger.info('''Best iteration: %d'''	,   args.max_selftrain_iterations - 1)
      logger.info('''Best evaluation result: %s = %f'''	,   args.eval_metric	,   __snake_case)
      accelerator.wait_for_everyone()
      if accelerator.is_main_process:
         shutil.copy(
             os.path.join(__snake_case	,   F'''eval_results_iter-{args.max_selftrain_iterations - 1}.json''')	,   os.path.join(__snake_case	,   '''eval_results_best-iteration.json''')	,   )






'''simple docstring'''

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


A_     :						List[Any]    							=logging.get_logger(__name__)


class     __UpperCAmelCase       ( __a		):
  __A :				int											= ['input_values', 'attention_mask']





  def __init__(	self    ,     _lowerCamelCase = 1    ,     _lowerCamelCase = 1_6000    ,     _lowerCamelCase = 0.0    ,     _lowerCamelCase = False    ,     _lowerCamelCase = 80    ,     _lowerCamelCase = 16    ,     _lowerCamelCase = 64    ,     _lowerCamelCase = "hann_window"    ,     _lowerCamelCase = 1.0    ,     _lowerCamelCase = 80    ,     _lowerCamelCase = 7600    ,     _lowerCamelCase = 1E-10    ,     _lowerCamelCase = 2    ,     _lowerCamelCase = True    ,     **_lowerCamelCase    ,     ):
     super().__init__(feature_size=_lowerCamelCase    ,     sampling_rate=_lowerCamelCase    ,     padding_value=_lowerCamelCase    ,     **_lowerCamelCase )
     lowerCAmelCase_			=      do_normalize
     lowerCAmelCase_			=      return_attention_mask

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

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

     lowerCAmelCase_			=      window_function(window_length=self.sample_size    ,     name=self.win_function    ,     periodic=_lowerCamelCase )

     lowerCAmelCase_			=      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'''    ,     _lowerCamelCase    ,     )
     if reduction_factor != 2.0:
        warnings.warn(
            '''The argument `reduction_factor` is deprecated and will be removed in version 4.30.0 of Transformers'''    ,     _lowerCamelCase    ,     )





  @staticmethod
  # Copied from transformers.models.wav2vec2.feature_extraction_wav2vec2.Wav2Vec2FeatureExtractor.zero_mean_unit_var_norm
  def 						UpperCAmelCase_	(	_lowerCamelCase    ,     _lowerCamelCase    ,     _lowerCamelCase = 0.0 ):
     if attention_mask is not None:
        lowerCAmelCase_			=      np.array(_lowerCamelCase    ,     np.intaa )
        lowerCAmelCase_			=      []

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

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

     return normed_input_values





  def 						UpperCAmelCase_	(	self    ,     _lowerCamelCase    ,     ):
     lowerCAmelCase_			=      spectrogram(
         _lowerCamelCase    ,     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    ,     _lowerCamelCase = None    ,     _lowerCamelCase = None    ,     _lowerCamelCase = False    ,     _lowerCamelCase = None    ,     _lowerCamelCase = False    ,     _lowerCamelCase = None    ,     _lowerCamelCase = None    ,     _lowerCamelCase = None    ,     _lowerCamelCase = None    ,     **_lowerCamelCase    ,     ):
     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:
        lowerCAmelCase_			=      self._process_audio(
            _lowerCamelCase    ,     _lowerCamelCase    ,     _lowerCamelCase    ,     _lowerCamelCase    ,     _lowerCamelCase    ,     _lowerCamelCase    ,     _lowerCamelCase    ,     _lowerCamelCase    ,     **_lowerCamelCase    ,     )
     else:
        lowerCAmelCase_			=      None

     if audio_target is not None:
        lowerCAmelCase_			=      self._process_audio(
            _lowerCamelCase    ,     _lowerCamelCase    ,     _lowerCamelCase    ,     _lowerCamelCase    ,     _lowerCamelCase    ,     _lowerCamelCase    ,     _lowerCamelCase    ,     _lowerCamelCase    ,     **_lowerCamelCase    ,     )

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

     return inputs





  def 						UpperCAmelCase_	(	self    ,     _lowerCamelCase    ,     _lowerCamelCase = False    ,     _lowerCamelCase = False    ,     _lowerCamelCase = None    ,     _lowerCamelCase = False    ,     _lowerCamelCase = None    ,     _lowerCamelCase = None    ,     _lowerCamelCase = None    ,     **_lowerCamelCase    ,     ):
     lowerCAmelCase_			=      isinstance(_lowerCamelCase    ,     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}''' )
     lowerCAmelCase_			=      is_batched_numpy or (
         isinstance(_lowerCamelCase    ,     (list, tuple) ) and (isinstance(speech[0]    ,     (np.ndarray, tuple, list) ))
     )

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

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

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

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

     lowerCAmelCase_			=      self.pad(
         _lowerCamelCase    ,     padding=_lowerCamelCase    ,     max_length=_lowerCamelCase    ,     truncation=_lowerCamelCase    ,     pad_to_multiple_of=_lowerCamelCase    ,     return_attention_mask=_lowerCamelCase    ,     **_lowerCamelCase    ,     )

     lowerCAmelCase_			=      feature_size_hack

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

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

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

     if return_tensors is not None:
        lowerCAmelCase_			=      padded_inputs.convert_to_tensors(_lowerCamelCase )

     return padded_inputs







  def 						UpperCAmelCase_	(	self ):
     lowerCAmelCase_			=      super().to_dict()

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

     return output





