class_docstr: This lobe enables the integration of use of weighted sum representations
  from different layers in a SSL encoder.
  
  The model can be used as a fixed feature extractor for SSL benchmarking. It
  will download automatically the model from HuggingFace or use a local path.
  
  More details in recipes/SSL_benchmark
  
  Arguments
  ---------
  hub : str
      HuggingFace hub name: e.g "facebook/wav2vec2-large-lv60"
  layernorm: bool, (default: False)
      Whether layer representations should be layernormed before sum
  
  Example
  -------
  >>> inputs = torch.rand([10, 600])
  >>> model_hub = "facebook/wav2vec2-base-960h"
  >>> model = WeightedSSLModel(model_hub)
  >>> outputs = model(inputs)
docstr: This method outputs a weighted sum of the layers representations of the SSL encoder
  
  Arguments
  ---------
  wav : tensor
      The wavs
  wav_lens : tensor
      The wav lengths
docstr_tok: ["This","method","outputs","a","weighted","sum","of","the","layers","representations","of","the","SSL","encoder","Arguments","--","--","--","--","-","wav",":","tensor","The","wavs","wav_lens",":","tensor","The","wav","lengths"]
code: def forward(self, wav, wav_lens=None):
      """This method outputs a weighted sum of the layers representations of the SSL encoder
  
      Arguments
      ---------
      wav : tensor
          The wavs
      wav_lens : tensor
          The wav lengths
      """
  
      feats = self.model(wav)
      hidden_states = torch.stack(feats.hidden_states, dim=0).detach()
      # First dimension should be equal to the number of layers in the hparams
      assert (
          self.num_layers == hidden_states.shape[0]
      ), "Num layers not equal to num hidden states"
      norm_weights = torch.nn.functional.softmax(self.weights, dim=-1)
      # Layernorming the layers representations if asked
      if self.layernorm:
          hidden_states = [
              F.layer_norm(t, (t.shape[-1],)) for t in hidden_states
          ]
      # Summing the weighted layers
      weighted_feats = (
          hidden_states * norm_weights[:, None, None, None]
      ).sum(axis=0)
      return weighted_feats
  
file_path: speechbrain/speechbrain/lobes/models/huggingface_transformers/weighted_ssl.py
imports: import torch
  import logging
  import torch.nn.functional
  from speechbrain.lobes.models.huggingface_transformers.huggingface import HFTransformersInterface
label_desc: Use image node_id 2 for calling the WeightedSSLModel obj's underlying member method code with example usage: obj.forward(wav, wav_lens) and returns: weighted_feats