class_docstr: This lobe enables the integration of HuggingFace and SpeechBrain
  pretrained wav2vec2.0/Hubert models.
  
  Source paper wav2vec2.0: https://arxiv.org/abs/2006.11477
  Source paper Hubert: https://arxiv.org/abs/2106.07447
  Transformer from HuggingFace needs to be installed:
  https://huggingface.co/transformers/installation.html
  
  The model can be used as a fixed feature extractor or can be finetuned. It
  will download automatically the model from HuggingFace or use a local path.
  
  Arguments
  ---------
  source : str
      HuggingFace hub name: e.g "facebook/wav2vec2-large-lv60"
  save_path : str
      Path (dir) of the downloaded model.
  output_norm : bool (default: True)
      If True, a layer_norm (affine) will be applied to the output obtained
      from the wav2vec model.
  freeze : bool (default: True)
      If True, the model is frozen. If False, the model will be trained
      alongside with the rest of the pipeline.
  freeze_feature_extractor :  bool (default: False)
      When freeze = False and freeze_feature_extractor True, the featue_extractor module of the model is Frozen. If False
      all the wav2vec model will be trained including featue_extractor module.
  apply_spec_augment : bool (default: False)
      If True, the model will apply spec augment on the output of feature extractor
      (inside huggingface Wav2VecModel() class).
      If False, the model will not apply spec augment. We set this to false to prevent from doing it twice.
  output_all_hiddens : bool (default: False)
      If True, the forward function outputs the hidden states from all transformer layers.
      For example wav2vec2-base has 12 transformer layers and the output is of shape (13, B, T, C),
      where a projection of the CNN output is added to the beginning.
      If False, the forward function outputs the hidden states only from the last transformer layer.
  
  Example
  -------
  >>> inputs = torch.rand([10, 600])
  >>> model_hub = "facebook/wav2vec2-base-960h"
  >>> save_path = "savedir"
  >>> model = Wav2Vec2(model_hub, save_path)
  >>> outputs = model(inputs)
class_docstr_tok: ["This","lobe","enables","the","integration","of","HuggingFace","and","SpeechBrain","pretrained","wav2vec2.0\/Hubert","models",".","Source","paper","wav2vec2.0",":","https",":","\/\/arxiv.org\/abs\/2006.11477","Source","paper","Hubert",":","https",":","\/\/arxiv.org\/abs\/2106.07447","Transformer","from","HuggingFace","needs","to","be","installed",":","https",":","\/\/huggingface.co\/transformers\/installation.html","The","model","can","be","used","as","a","fixed","feature","extractor","or","can","be","finetuned",".","It","will","download","automatically","the","model","from","HuggingFace","or","use","a","local","path",".","Arguments","--","--","--","--","-","source",":","str","HuggingFace","hub","name",":","e.g","``","facebook\/wav2vec2-large-lv60","''","save_path",":","str","Path","(","dir",")","of","the","downloaded","model",".","output_norm",":","bool","(","default",":","True",")","If","True",",","a","layer_norm","(","affine",")","will","be","applied","to","the","output","obtained","from","the","wav2vec","model",".","freeze",":","bool","(","default",":","True",")","If","True",",","the","model","is","frozen",".","If","False",",","the","model","will","be","trained","alongside","with","the","rest","of","the","pipeline",".","freeze_feature_extractor",":","bool","(","default",":","False",")","When","freeze","=","False","and","freeze_feature_extractor","True",",","the","featue_extractor","module","of","the","model","is","Frozen",".","If","False","all","the","wav2vec","model","will","be","trained","including","featue_extractor","module",".","apply_spec_augment",":","bool","(","default",":","False",")","If","True",",","the","model","will","apply","spec","augment","on","the","output","of","feature","extractor","(","inside","huggingface","Wav2VecModel","(",")","class",")",".","If","False",",","the","model","will","not","apply","spec","augment",".","We","set","this","to","false","to","prevent","from","doing","it","twice",".","output_all_hiddens",":","bool","(","default",":","False",")","If","True",",","the","forward","function","outputs","the","hidden","states","from","all","transformer","layers",".","For","example","wav2vec2-base","has","12","transformer","layers","and","the","output","is","of","shape","(","13",",","B",",","T",",","C",")",",","where","a","projection","of","the","CNN","output","is","added","to","the","beginning",".","If","False",",","the","forward","function","outputs","the","hidden","states","only","from","the","last","transformer","layer",".","Example","--","--","--","-",">",">",">","inputs","=","torch.rand","(","[","10",",","600","]",")",">",">",">","model_hub","=","``","facebook\/wav2vec2-base-960h","''",">",">",">","save_path","=","``","savedir","''",">",">",">","model","=","Wav2Vec2","(","model_hub",",","save_path",")",">",">",">","outputs","=","model","(","inputs",")"]
docstr: Takes an input waveform and return its corresponding wav2vec encoding.
  
  Arguments
  ---------
  wav : torch.Tensor (signal)
      A batch of audio signals to transform to features.
  wav_len : tensor
      The relative length of the wav given in SpeechBrain format.
docstr_tok: ["Takes","an","input","waveform","and","return","its","corresponding","wav2vec","encoding",".","Arguments","--","--","--","--","-","wav",":","torch.Tensor","(","signal",")","A","batch","of","audio","signals","to","transform","to","features",".","wav_len",":","tensor","The","relative","length","of","the","wav","given","in","SpeechBrain","format","."]
code: def extract_features(self, wav, wav_lens=None):
      """Takes an input waveform and return its corresponding wav2vec encoding.
  
      Arguments
      ---------
      wav : torch.Tensor (signal)
          A batch of audio signals to transform to features.
      wav_len : tensor
          The relative length of the wav given in SpeechBrain format.
      """
  
      padding_mask = make_padding_masks(wav, wav_len=wav_lens)
  
      if self.normalize_wav:
          wav = F.layer_norm(wav, wav.shape[1:])
  
      # Extract wav2vec output
      out = self.model(
          wav,
          attention_mask=padding_mask,
          output_hidden_states=self.output_all_hiddens,
      )
  
      if self.output_all_hiddens:
          out = torch.stack(list(out.hidden_states), dim=0)
          norm_shape = out.shape[-3:]
      else:
          out = out.last_hidden_state
          norm_shape = out.shape
  
      # We normalize the output if required
      if self.output_norm:
          out = F.layer_norm(out, norm_shape[1:])
  
      return out
  
file_path: speechbrain/speechbrain/lobes/models/huggingface_transformers/wav2vec2.py
imports: import torch
  import logging
  import numpy
  import torch.nn.functional
  from speechbrain.lobes.models.huggingface_transformers.huggingface import HFTransformersInterface
  from speechbrain.lobes.models.huggingface_transformers.huggingface import make_padding_masks
  import transformers
  from transformers.models.wav2vec2.modeling_wav2vec2 import _compute_mask_indices
label_desc: Use image node_id 4 for calling the Wav2Vec2 obj's underlying member method code with example usage: obj.extract_features(wav, wav_lens) and returns: out