class_docstr: This class implements the imperceptible, robust, and targeted attack to generate adversarial examples for automatic
  speech recognition models. This attack will be implemented specifically for DeepSpeech model and is framework
  dependent, specifically for PyTorch.
  
  | Paper link: https://arxiv.org/abs/1903.10346
docstr: The forward pass of the first stage of the attack.
  
  :param original_input: Samples of shape (nb_samples, seq_length). Note that, sequences in the batch must have
                         equal lengths. A possible example of `original_input` could be:
                         `original_input = np.array([np.array([0.1, 0.2, 0.1]), np.array([0.3, 0.1, 0.0])])`.
  :param original_output: Target values of shape (nb_samples). Each sample in `original_output` is a string and
                          it may possess different lengths. A possible example of `original_output` could be:
                          `original_output = np.array(['SIXTY ONE', 'HELLO'])`.
  :param local_batch_size: Current batch size.
  :param local_max_length: Max length of the current batch.
  :param rescale: Current rescale coefficients.
  :param input_mask: Masks of true inputs.
  :param real_lengths: Real lengths of original sequences.
  :return: A tuple of (loss, local_delta, decoded_output, masked_adv_input, local_delta_rescale)
              - loss: The loss tensor of the first stage of the attack.
              - local_delta: The delta of the current batch.
              - decoded_output: Transcription output.
              - masked_adv_input: Perturbed inputs.
              - local_delta_rescale: The rescaled delta.
docstr_tok: ["The","forward","pass","of","the","first","stage","of","the","attack",".",":","param","original_input",":","Samples","of","shape","(","nb_samples",",","seq_length",")",".","Note","that",",","sequences","in","the","batch","must","have","equal","lengths",".","A","possible","example","of","`","original_input","`","could","be",":","`","original_input","=","np.array","(","[","np.array","(","[","0.1",",","0.2",",","0.1","]",")",",","np.array","(","[","0.3",",","0.1",",","0.0","]",")","]",")","`",".",":","param","original_output",":","Target","values","of","shape","(","nb_samples",")",".","Each","sample","in","`","original_output","`","is","a","string","and","it","may","possess","different","lengths",".","A","possible","example","of","`","original_output","`","could","be",":","`","original_output","=","np.array","(","[","'SIXTY","ONE","'",",","'HELLO","'","]",")","`",".",":","param","local_batch_size",":","Current","batch","size",".",":","param","local_max_length",":","Max","length","of","the","current","batch",".",":","param","rescale",":","Current","rescale","coefficients",".",":","param","input_mask",":","Masks","of","true","inputs",".",":","param","real_lengths",":","Real","lengths","of","original","sequences",".",":","return",":","A","tuple","of","(","loss",",","local_delta",",","decoded_output",",","masked_adv_input",",","local_delta_rescale",")","-","loss",":","The","loss","tensor","of","the","first","stage","of","the","attack",".","-","local_delta",":","The","delta","of","the","current","batch",".","-","decoded_output",":","Transcription","output",".","-","masked_adv_input",":","Perturbed","inputs",".","-","local_delta_rescale",":","The","rescaled","delta","."]
code: def _forward_1st_stage(
      self,
      original_input: np.ndarray,
      original_output: np.ndarray,
      local_batch_size: int,
      local_max_length: int,
      rescale: np.ndarray,
      input_mask: np.ndarray,
      real_lengths: np.ndarray,
  ) -> Tuple[
      "torch.Tensor",
      "torch.Tensor",
      np.ndarray,
      "torch.Tensor",
      "torch.Tensor",
  ]:
      """
      The forward pass of the first stage of the attack.
  
      :param original_input: Samples of shape (nb_samples, seq_length). Note that, sequences in the batch must have
                             equal lengths. A possible example of `original_input` could be:
                             `original_input = np.array([np.array([0.1, 0.2, 0.1]), np.array([0.3, 0.1, 0.0])])`.
      :param original_output: Target values of shape (nb_samples). Each sample in `original_output` is a string and
                              it may possess different lengths. A possible example of `original_output` could be:
                              `original_output = np.array(['SIXTY ONE', 'HELLO'])`.
      :param local_batch_size: Current batch size.
      :param local_max_length: Max length of the current batch.
      :param rescale: Current rescale coefficients.
      :param input_mask: Masks of true inputs.
      :param real_lengths: Real lengths of original sequences.
      :return: A tuple of (loss, local_delta, decoded_output, masked_adv_input, local_delta_rescale)
                  - loss: The loss tensor of the first stage of the attack.
                  - local_delta: The delta of the current batch.
                  - decoded_output: Transcription output.
                  - masked_adv_input: Perturbed inputs.
                  - local_delta_rescale: The rescaled delta.
      """
      import torch
  
      # Compute perturbed inputs
      local_delta = self.global_optimal_delta[
          :local_batch_size, :local_max_length
      ]
      local_delta_rescale = torch.clamp(
          local_delta, -self.eps, self.eps
      ).to(self.estimator.device)
      local_delta_rescale *= torch.tensor(rescale).to(
          self.estimator.device
      )
      adv_input = local_delta_rescale + torch.tensor(original_input).to(
          self.estimator.device
      )
      masked_adv_input = adv_input * torch.tensor(input_mask).to(
          self.estimator.device
      )
  
      # Compute loss and decoded output
      (
          loss,
          decoded_output,
      ) = self.estimator.compute_loss_and_decoded_output(
          masked_adv_input=masked_adv_input,
          original_output=original_output,
          real_lengths=real_lengths,
      )
  
      return (
          loss,
          local_delta,
          decoded_output,
          masked_adv_input,
          local_delta_rescale,
      )
  
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  from typing import TYPE_CHECKING, Optional, Tuple, List
  import numpy
  import scipy
  from art.attacks.attack import EvasionAttack
  from art.estimators.pytorch import PyTorchEstimator
  from art.estimators.speech_recognition.pytorch_deep_speech import PyTorchDeepSpeech
  from art.estimators.speech_recognition.speech_recognizer import SpeechRecognizerMixin
  from art.estimators.speech_recognition.speech_recognizer import PytorchSpeechRecognizerMixin
label_desc: Use image node_id 5 for calling the ImperceptibleASRPyTorch obj's underlying member method code with example usage: obj._forward_1st_stage(original_input, original_output, local_batch_size, local_max_length, rescale, input_mask, real_lengths) and returns: loss,  local_delta,  decoded_output,  masked_adv_input,  local_delta_rescale