class_docstr: Pipeline that aims at extracting spoken text contained within some audio.
  
  The input can be either a raw waveform or a audio file. In case of the audio file, ffmpeg should be installed for
  to support multiple audio formats
  
  Arguments:
      model ([`PreTrainedModel`] or [`TFPreTrainedModel`]):
          The model that will be used by the pipeline to make predictions. This needs to be a model inheriting from
          [`PreTrainedModel`] for PyTorch and [`TFPreTrainedModel`] for TensorFlow.
      tokenizer ([`PreTrainedTokenizer`]):
          The tokenizer that will be used by the pipeline to encode data for the model. This object inherits from
          [`PreTrainedTokenizer`].
      feature_extractor ([`SequenceFeatureExtractor`]):
          The feature extractor that will be used by the pipeline to encode waveform for the model.
      chunk_length_s (`float`, *optional*, defaults to 0):
          The input length for in each chunk. If `chunk_length_s = 0` then chunking is disabled (default). Only
          available for CTC models, e.g. [`Wav2Vec2ForCTC`].
  
          <Tip>
  
          For more information on how to effectively use `chunk_length_s`, please have a look at the [ASR chunking
          blog post](https://huggingface.co/blog/asr-chunking).
  
          </Tip>
  
      stride_length_s (`float`, *optional*, defaults to `chunk_length_s / 6`):
          The length of stride on the left and right of each chunk. Used only with `chunk_length_s > 0`. This enables
          the model to *see* more context and infer letters better than without this context but the pipeline
          discards the stride bits at the end to make the final reconstitution as perfect as possible.
  
          <Tip>
  
          For more information on how to effectively use `stride_length_s`, please have a look at the [ASR chunking
          blog post](https://huggingface.co/blog/asr-chunking).
  
          </Tip>
  
      framework (`str`, *optional*):
          The framework to use, either `"pt"` for PyTorch or `"tf"` for TensorFlow. The specified framework must be
          installed. If no framework is specified, will default to the one currently installed. If no framework is
          specified and both frameworks are installed, will default to the framework of the `model`, or to PyTorch if
          no model is provided.
      device (`int`, *optional*, defaults to -1):
          Device ordinal for CPU/GPU supports. Setting this to -1 will leverage CPU, a positive will run the model on
          the associated CUDA device id.
      decoder (`pyctcdecode.BeamSearchDecoderCTC`, *optional*):
          [PyCTCDecode's
          BeamSearchDecoderCTC](https://github.com/kensho-technologies/pyctcdecode/blob/2fd33dc37c4111417e08d89ccd23d28e9b308d19/pyctcdecode/decoder.py#L180)
          can be passed for language model boosted decoding. See [`Wav2Vec2ProcessorWithLM`] for more information.
class_docstr_tok: ["Pipeline","that","aims","at","extracting","spoken","text","contained","within","some","audio",".","The","input","can","be","either","a","raw","waveform","or","a","audio","file",".","In","case","of","the","audio","file",",","ffmpeg","should","be","installed","for","to","support","multiple","audio","formats","Arguments",":","model","(","[","`","PreTrainedModel","`","]","or","[","`","TFPreTrainedModel","`","]",")",":","The","model","that","will","be","used","by","the","pipeline","to","make","predictions",".","This","needs","to","be","a","model","inheriting","from","[","`","PreTrainedModel","`","]","for","PyTorch","and","[","`","TFPreTrainedModel","`","]","for","TensorFlow",".","tokenizer","(","[","`","PreTrainedTokenizer","`","]",")",":","The","tokenizer","that","will","be","used","by","the","pipeline","to","encode","data","for","the","model",".","This","object","inherits","from","[","`","PreTrainedTokenizer","`","]",".","feature_extractor","(","[","`","SequenceFeatureExtractor","`","]",")",":","The","feature","extractor","that","will","be","used","by","the","pipeline","to","encode","waveform","for","the","model",".","chunk_length_s","(","`","float","`",",","*","optional","*",",","defaults","to","0",")",":","The","input","length","for","in","each","chunk",".","If","`","chunk_length_s","=","0","`","then","chunking","is","disabled","(","default",")",".","Only","available","for","CTC","models",",","e.g",".","[","`","Wav2Vec2ForCTC","`","]",".","<","Tip",">","For","more","information","on","how","to","effectively","use","`","chunk_length_s","`",",","please","have","a","look","at","the","[","ASR","chunking","blog","post","]","(","https",":","\/\/huggingface.co\/blog\/asr-chunking",")",".","<","\/Tip",">","stride_length_s","(","`","float","`",",","*","optional","*",",","defaults","to","`","chunk_length_s","\/","6","`",")",":","The","length","of","stride","on","the","left","and","right","of","each","chunk",".","Used","only","with","`","chunk_length_s",">","0","`",".","This","enables","the","model","to","*","see","*","more","context","and","infer","letters","better","than","without","this","context","but","the","pipeline","discards","the","stride","bits","at","the","end","to","make","the","final","reconstitution","as","perfect","as","possible",".","<","Tip",">","For","more","information","on","how","to","effectively","use","`","stride_length_s","`",",","please","have","a","look","at","the","[","ASR","chunking","blog","post","]","(","https",":","\/\/huggingface.co\/blog\/asr-chunking",")",".","<","\/Tip",">","framework","(","`","str","`",",","*","optional","*",")",":","The","framework","to","use",",","either","`","``","pt","''","`","for","PyTorch","or","`","``","tf","''","`","for","TensorFlow",".","The","specified","framework","must","be","installed",".","If","no","framework","is","specified",",","will","default","to","the","one","currently","installed",".","If","no","framework","is","specified","and","both","frameworks","are","installed",",","will","default","to","the","framework","of","the","`","model","`",",","or","to","PyTorch","if","no","model","is","provided",".","device","(","`","int","`",",","*","optional","*",",","defaults","to","-1",")",":","Device","ordinal","for","CPU\/GPU","supports",".","Setting","this","to","-1","will","leverage","CPU",",","a","positive","will","run","the","model","on","the","associated","CUDA","device","id",".","decoder","(","`","pyctcdecode.BeamSearchDecoderCTC","`",",","*","optional","*",")",":","[","PyCTCDecode's","BeamSearchDecoderCTC","]","(","https",":","\/\/github.com\/kensho-technologies\/pyctcdecode\/blob\/2fd33dc37c4111417e08d89ccd23d28e9b308d19\/pyctcdecode\/decoder.py","#","L180",")","can","be","passed","for","language","model","boosted","decoding",".","See","[","`","Wav2Vec2ProcessorWithLM","`","]","for","more","information","."]
code: def _forward(self, model_inputs):
      is_last = model_inputs.pop("is_last")
      if self.type == "seq2seq":
          encoder = self.model.get_encoder()
          # we need to pass `processed.get("attention_mask")` here since audio encoder
          # attention mask  length is different from expected text decoder `encoder_attention_mask` length
          # `generate` magic to create the mask automatically won't work, we basically need to help
          # it here.
          # Consume values so we can let extra information flow freely through
          # the pipeline (important for `partial` in microphone)
          if "input_features" in model_inputs:
              inputs = model_inputs.pop("input_features")
          elif "input_values" in model_inputs:
              inputs = model_inputs.pop("input_values")
          else:
              raise ValueError(
                  "Seq2Seq speech recognition model requires either a "
                  f"`input_features` or `input_values` key, but only has {model_inputs.keys()}"
              )
  
          accepts_attention_mask = "attention_mask" in set(
              inspect.signature(encoder.forward).parameters.keys()
          )
          if accepts_attention_mask:
              attention_mask = model_inputs.pop("attention_mask", None)
              tokens = self.model.generate(
                  encoder_outputs=encoder(
                      inputs, attention_mask=attention_mask
                  ),
                  attention_mask=attention_mask,
              )
          else:
              tokens = self.model.generate(inputs)
  
          out = {"tokens": tokens}
  
      else:
          stride = model_inputs.pop("stride", None)
          input_values = model_inputs.pop("input_values")
          attention_mask = model_inputs.pop("attention_mask", None)
          outputs = self.model(
              input_values=input_values, attention_mask=attention_mask
          )
          logits = outputs.logits
  
          if self.type == "ctc_with_lm":
              out = {"logits": logits}
          else:
              out = {"tokens": logits.argmax(dim=-1)}
          if stride is not None:
              # Send stride to `postprocess`.
              # it needs to be handled there where
              # the pieces are to be concatenated.
              ratio = 1 / self.model.config.inputs_to_logits_ratio
              if isinstance(stride, tuple):
                  out["stride"] = rescale_stride(
                      logits, [stride], ratio
                  )[0]
              else:
                  out["stride"] = rescale_stride(logits, stride, ratio)
      # Leftover
      extra = model_inputs
      return {"is_last": is_last, **out, **extra}
  
file_path: H2O/h2o_flexgen/benchmark/third_party/transformers/src/transformers/pipelines/automatic_speech_recognition.py
imports: import inspect
  from collections import defaultdict
  from typing import TYPE_CHECKING, Dict, Optional, Union
  import numpy
  from ..utils import is_torch_available, logging
  from .audio_utils import ffmpeg_read
  from .base import ChunkPipeline
label_desc: Use image node_id 5 for calling the AutomaticSpeechRecognitionPipeline obj's underlying member method code with example usage: obj._forward(model_inputs) and returns: dict