class_docstr: An wrapper for the HuggingFace encodec model
  
  Arguments
  ---------
  source : str
      A HuggingFace repository identifier or a path
  save_path : str
      The location where the pretrained model will be saved
  sample_rate : int
      The audio sampling rate
  bandwidth : float
      The encoding bandwidth, in kbps (optional)
      Supported bandwidths:
      1.5, 3.0, 6.0, 12.0, 24.0
  flat_embeddings : bool
      If set to True, embeddings will be flattened into
      (Batch x Length x (Heads * Embedding))
  freeze : bool
      whether the model will be frozen (e.g. not trainable if used
      as part of training another model)
  renorm_embeddings : bool
      whether embeddings should be renormalized. In the original
      model.
  
  Example
  -------
  >>> model_hub = "facebook/encodec_24khz"
  >>> save_path = "savedir"
  >>> model = Encodec(model_hub, save_path)
  >>> audio = torch.randn(4, 1000)
  >>> length = torch.tensor([1.0, .5, .75, 1.0])
  >>> tokens, emb = model.encode(audio, length)
  >>> tokens.shape
  torch.Size([4, 4, 2])
  >>> emb.shape
  torch.Size([4, 4, 2, 128])
  >>> rec = model.decode(tokens, length)
  >>> rec.shape
  torch.Size([4, 1, 1280])
  >>> rec_emb = model.decode_emb(emb, length)
  >>> rec_emb.shape
  torch.Size([4, 1, 1280])
  >>> rec_tokens = model.tokens(emb, length)
  >>> rec_tokens.shape
  torch.Size([4, 4, 2])
  >>> model = Encodec(model_hub, save_path, flat_embeddings=True)
  >>> _, emb = model.encode(audio, length)
  >>> emb.shape
  torch.Size([4, 4, 256])
class_docstr_tok: ["An","wrapper","for","the","HuggingFace","encodec","model","Arguments","--","--","--","--","-","source",":","str","A","HuggingFace","repository","identifier","or","a","path","save_path",":","str","The","location","where","the","pretrained","model","will","be","saved","sample_rate",":","int","The","audio","sampling","rate","bandwidth",":","float","The","encoding","bandwidth",",","in","kbps","(","optional",")","Supported","bandwidths",":","1.5",",","3.0",",","6.0",",","12.0",",","24.0","flat_embeddings",":","bool","If","set","to","True",",","embeddings","will","be","flattened","into","(","Batch","x","Length","x","(","Heads","*","Embedding",")",")","freeze",":","bool","whether","the","model","will","be","frozen","(","e.g",".","not","trainable","if","used","as","part","of","training","another","model",")","renorm_embeddings",":","bool","whether","embeddings","should","be","renormalized",".","In","the","original","model",".","Example","--","--","--","-",">",">",">","model_hub","=","``","facebook\/encodec_24khz","''",">",">",">","save_path","=","``","savedir","''",">",">",">","model","=","Encodec","(","model_hub",",","save_path",")",">",">",">","audio","=","torch.randn","(","4",",","1000",")",">",">",">","length","=","torch.tensor","(","[","1.0",",",".5",",",".75",",","1.0","]",")",">",">",">","tokens",",","emb","=","model.encode","(","audio",",","length",")",">",">",">","tokens.shape","torch.Size","(","[","4",",","4",",","2","]",")",">",">",">","emb.shape","torch.Size","(","[","4",",","4",",","2",",","128","]",")",">",">",">","rec","=","model.decode","(","tokens",",","length",")",">",">",">","rec.shape","torch.Size","(","[","4",",","1",",","1280","]",")",">",">",">","rec_emb","=","model.decode_emb","(","emb",",","length",")",">",">",">","rec_emb.shape","torch.Size","(","[","4",",","1",",","1280","]",")",">",">",">","rec_tokens","=","model.tokens","(","emb",",","length",")",">",">",">","rec_tokens.shape","torch.Size","(","[","4",",","4",",","2","]",")",">",">",">","model","=","Encodec","(","model_hub",",","save_path",",","flat_embeddings=True",")",">",">",">","_",",","emb","=","model.encode","(","audio",",","length",")",">",">",">","emb.shape","torch.Size","(","[","4",",","4",",","256","]",")"]
docstr: Comberts embeddings to raw tokens
  
  Arguments
  ---------
  emb : torch.Tensor
      Raw embeddings
  length : torch.Tensor
      A 1-D tensor of relative lengths. If supplied,
      padded positions will be zeroed out
  
  Returns
  -------
  tokens : torch.Tensor
      A (Batch x Length) tensor of token indices
docstr_tok: ["Comberts","embeddings","to","raw","tokens","Arguments","--","--","--","--","-","emb",":","torch.Tensor","Raw","embeddings","length",":","torch.Tensor","A","1-D","tensor","of","relative","lengths",".","If","supplied",",","padded","positions","will","be","zeroed","out","Returns","--","--","--","-","tokens",":","torch.Tensor","A","(","Batch","x","Length",")","tensor","of","token","indices"]
code: def tokens(self, emb, length=None):
      """Comberts embeddings to raw tokens
  
      Arguments
      ---------
      emb : torch.Tensor
          Raw embeddings
      length : torch.Tensor
          A 1-D tensor of relative lengths. If supplied,
          padded positions will be zeroed out
  
      Returns
      -------
      tokens : torch.Tensor
          A (Batch x Length) tensor of token indices"""
      with torch.set_grad_enabled(not self.freeze):
          if self.flat_embeddings:
              batch_size, max_len, _ = emb.shape
              emb = emb.reshape(
                  batch_size, max_len, self.num_heads, self.emb_dim
              )
          if self.renorm_embeddings:
              emb = emb * self.emb_std + self.emb_mean
          scaled_states = emb.pow(2).sum(-1, keepdim=True)
          vocab = self.vocabulary.transpose(-1, -2).unsqueeze(0)
          emb_perm = emb.permute(0, 2, 1, 3)
          emb_vocab_prod = (emb_perm @ vocab).moveaxis(1, 2)
          vocab_sum = vocab.pow(2).sum(-2, keepdim=True).moveaxis(1, 2)
          dist = -(scaled_states - 2 * emb_vocab_prod + vocab_sum)
          tokens = dist.max(dim=-1).indices
          if length is not None:
              clean_padding_(tokens, length)
          return tokens
  
file_path: speechbrain/speechbrain/lobes/models/huggingface_transformers/encodec.py
imports: import torch
  import logging
  from torch.nn import functional
  from speechbrain.dataio.dataio import length_to_mask, clean_padding_
  from speechbrain.lobes.models.huggingface_transformers.huggingface import HFTransformersInterface
label_desc: Use image node_id 11 for calling the Encodec obj's underlying member method code with example usage: obj.tokens(emb, length) and returns: tokens