class_docstr: Three way contrastive loss used for VinVL pretraining.
  Described here https://arxiv.org/pdf/2101.00529
  
  A thin wrapper around MLP for 3 way classification.
  Effectively ITM with 3 labels.
  contrastive 3-way loss has 3 labels,
  0 for a match, 1, 2 for a corrupt caption/image
code: def forward(
      self,
      sequence_output: torch.Tensor,
      processed_sample_list: Dict[str, Dict[str, torch.Tensor]],
  ):
      output_dict = {}
  
      if self.config.constrastive_label_key in processed_sample_list:
          next_sentence_labels = processed_sample_list[
              self.config.constrastive_label_key
          ]
      else:
          assert (
              LABEL_KEY in processed_sample_list
              and processed_sample_list[LABEL_KEY] is not None
          ), (
              f"Constrastive three way pretraining requires {LABEL_KEY} to "
              + "be in sample list with value not None."
          )
  
          next_sentence_labels = processed_sample_list[LABEL_KEY][
              self.config.constrastive_label_key
          ]
  
      scores = self.contrast_head(sequence_output)["scores"]
      constrastive_loss = self.ce_loss(
          scores.contiguous().view(-1, 3),
          next_sentence_labels.contiguous().view(-1),
      )
      output_dict["losses"] = {}
      output_dict["losses"][self.config.loss_name] = constrastive_loss
      return output_dict
  
file_path: mmf/mmf/models/transformers/heads/contrastive.py
imports: from dataclasses import dataclass
  from typing import Dict, Optional
  import torch
  from mmf.common.registry import registry
  from mmf.models.transformers.base import BaseTransformerHead
  from mmf.models.transformers.heads.mlp import MLP
label_desc: Use image node_id 2 for calling the ThreeWayContrastive obj's underlying member method code with example usage: obj.forward(sequence_output, processed_sample_list) and returns: output_dict