def METHOD_NAME(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