class_docstr: Holds the output of a wav2vec 2.0 model.
class_docstr_tok: ["Holds","the","output","of","a","wav2vec","2.0","model","."]
docstr: Compute the contrastive loss.
docstr_tok: ["Compute","the","contrastive","loss","."]
code: def compute_contrastive_loss(self) -> Tensor:
      """Compute the contrastive loss."""
      batch_size, seq_len, num_logits = self.logits.shape
  
      # (N, S, L) -> (S x N, L)
      logits = self.logits.transpose(0, 1).reshape(-1, num_logits)
  
      # The target is always at index 0 in the candidate list.
      target_indices = logits.new_zeros(
          (batch_size * seq_len,), dtype=torch.int64
      )
  
      return cross_entropy(logits, target_indices, reduction="sum")
  
imports: from __future__ import annotations
  from dataclasses import dataclass
  from typing import Optional, Tuple
  import torch
  from torch import Tensor
  from torch.nn import Module
  from torch.nn.functional import cross_entropy
  from fairseq2.models.sequence import SequenceBatch
  from fairseq2.models.wav2vec2.frontend import Wav2Vec2Frontend
  from fairseq2.models.wav2vec2.masker import Wav2Vec2Masker, extract_masked_elements
  from fairseq2.models.wav2vec2.vector_quantizer import VectorQuantizer, VectorQuantizerOutput
  from fairseq2.nn.ops import repeat_interleave
  from fairseq2.nn.padding import PaddingMask
  from fairseq2.nn.projection import Linear
  from fairseq2.nn.transformer import TransformerEncoder
  from fairseq2.typing import DataType, Device
label_desc: Use image node_id 2 for calling the Wav2Vec2Output obj's underlying member method code with example usage: obj.compute_contrastive_loss() and returns: cross_entropy