class_docstr: CLIP model retrofitted for performing contrastive evaluation between tokenized audio data and the corresponding
  transcribed text.
  
  Originally from https://github.com/lucidrains/DALLE-pytorch/blob/main/dalle_pytorch/dalle_pytorch.py
class_docstr_tok: ["CLIP","model","retrofitted","for","performing","contrastive","evaluation","between","tokenized","audio","data","and","the","corresponding","transcribed","text",".","Originally","from","https",":","\/\/github.com\/lucidrains\/DALLE-pytorch\/blob\/main\/dalle_pytorch\/dalle_pytorch.py"]
code: def forward(self, text, speech_tokens, return_loss=False):
      b, device = text.shape[0], text.device
      if self.training:
          text_mask = (
              torch.rand_like(text.float()) > self.text_mask_percentage
          )
          voice_mask = (
              torch.rand_like(speech_tokens.float())
              > self.voice_mask_percentage
          )
      else:
          text_mask = torch.ones_like(text.float()).bool()
          voice_mask = torch.ones_like(speech_tokens.float()).bool()
  
      text_emb = self.text_emb(text)
      speech_emb = self.speech_emb(speech_tokens)
  
      if not self.xformers:
          text_emb += self.text_pos_emb(
              torch.arange(text.shape[1], device=device)
          )
          speech_emb += self.speech_pos_emb(
              torch.arange(speech_emb.shape[1], device=device)
          )
  
      enc_text = self.text_transformer(text_emb, mask=text_mask)
      enc_speech = self.speech_transformer(speech_emb, mask=voice_mask)
  
      text_latents = masked_mean(enc_text, text_mask, dim=1)
      speech_latents = masked_mean(enc_speech, voice_mask, dim=1)
  
      text_latents = self.to_text_latent(text_latents)
      speech_latents = self.to_speech_latent(speech_latents)
  
      text_latents, speech_latents = map(
          lambda t: F.normalize(t, p=2, dim=-1),
          (text_latents, speech_latents),
      )
  
      temp = self.temperature.exp()
  
      if not return_loss:
          sim = (
              einsum("n d, n d -> n", text_latents, speech_latents)
              * temp
          )
          return sim
  
      sim = (
          einsum("i d, j d -> i j", text_latents, speech_latents) * temp
      )
      labels = torch.arange(b, device=device)
      loss = (
          F.cross_entropy(sim, labels)
          + F.cross_entropy(sim.t(), labels)
      ) / 2
      return loss
  
file_path: TTS/TTS/tts/layers/tortoise/clvp.py
imports: import torch
  import torch.nn
  import torch.nn.functional
  from torch import einsum
  from TTS.tts.layers.tortoise.arch_utils import CheckpointedXTransformerEncoder
  from TTS.tts.layers.tortoise.transformer import Transformer
  from TTS.tts.layers.tortoise.xtransformers import Encoder
label_desc: Use image node_id 2 for calling the CLVP obj's underlying member method code with example usage: obj.forward(text, speech_tokens, return_loss) and returns: loss, sim