class_docstr: Represents a wav2vec 2.0 model as described in
  :cite:t:`https://doi.org/10.48550/arxiv.2006.11477`.
class_docstr_tok: ["Represents","a","wav2vec","2.0","model","as","described","in",":","cite",":","t",":","`","https",":","\/\/doi.org\/10.48550\/arxiv.2006.11477","`","."]
docstr: Quantize targets and produce logits for contrastive prediction.
  
  :param encoder_output:
      The encoder output. *Shape:* :math:`(N,S_{enc},M)`, where :math:`N`
      is the batch size, :math:`S_{enc}` is the encoder output sequence
      length, and :math:`M` is the dimensionality of the model.
  :param targets:
      The non-quantized context network targets that have been extracted
      from the input sequences. *Shape:* :math:`(N,S_{msk},M)`, where
      :math:`N` is the batch size, :math:`S_{msk}` is the masked sequence
      length, and :math:`M` is the dimensionality of the model.
  :param temporal_mask:
      The temporal mask that has been used to extract the context network
      targets. *Shape:* :math:`(N,S_{enc})`, where :math:`N` is the batch
      size and :math`S_{enc}` is the encoder output sequence length.
docstr_tok: ["Quantize","targets","and","produce","logits","for","contrastive","prediction",".",":","param","encoder_output",":","The","encoder","output",".","*","Shape",":","*",":","math",":","`","(","N",",","S_","{","enc","}",",","M",")","`",",","where",":","math",":","`","N","`","is","the","batch","size",",",":","math",":","`","S_","{","enc","}","`","is","the","encoder","output","sequence","length",",","and",":","math",":","`","M","`","is","the","dimensionality","of","the","model",".",":","param","targets",":","The","non-quantized","context","network","targets","that","have","been","extracted","from","the","input","sequences",".","*","Shape",":","*",":","math",":","`","(","N",",","S_","{","msk","}",",","M",")","`",",","where",":","math",":","`","N","`","is","the","batch","size",",",":","math",":","`","S_","{","msk","}","`","is","the","masked","sequence","length",",","and",":","math",":","`","M","`","is","the","dimensionality","of","the","model",".",":","param","temporal_mask",":","The","temporal","mask","that","has","been","used","to","extract","the","context","network","targets",".","*","Shape",":","*",":","math",":","`","(","N",",","S_","{","enc","}",")","`",",","where",":","math",":","`","N","`","is","the","batch","size","and",":","math","`","S_","{","enc","}","`","is","the","encoder","output","sequence","length","."]
code: def quantize_and_contrast(
      self,
      encoder_output: Tensor,
      targets: Tensor,
      temporal_mask: Tensor,
  ) -> "Wav2Vec2Output":
      """Quantize targets and produce logits for contrastive prediction.
  
      :param encoder_output:
          The encoder output. *Shape:* :math:`(N,S_{enc},M)`, where :math:`N`
          is the batch size, :math:`S_{enc}` is the encoder output sequence
          length, and :math:`M` is the dimensionality of the model.
      :param targets:
          The non-quantized context network targets that have been extracted
          from the input sequences. *Shape:* :math:`(N,S_{msk},M)`, where
          :math:`N` is the batch size, :math:`S_{msk}` is the masked sequence
          length, and :math:`M` is the dimensionality of the model.
      :param temporal_mask:
          The temporal mask that has been used to extract the context network
          targets. *Shape:* :math:`(N,S_{enc})`, where :math:`N` is the batch
          size and :math`S_{enc}` is the encoder output sequence length.
      """
      seqs = extract_masked_elements(encoder_output, temporal_mask)
  
      seqs = self.final_proj(seqs)
  
      quantizer_output = self.quantizer(targets)
  
      targets = self.final_target_proj(
          quantizer_output.quantized_vectors
      )
  
      distractors = self._sample_distractors(targets)
  
      logits = self._compute_logits(seqs, targets, distractors)
  
      return Wav2Vec2Output(
          logits,
          targets,
          temporal_mask,
          quantizer_output,
          self.diversity_loss_weight,
      )
  
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 4 for calling the Wav2Vec2Model obj's underlying member method code with example usage: obj.quantize_and_contrast(encoder_output, targets, temporal_mask) and returns: Wav2Vec2Output