class_docstr: Compute the Contrastive loss defined in:
  
      Chen, Ting, et al. "A simple framework for contrastive learning of visual representations." International
      conference on machine learning. PMLR, 2020. (http://proceedings.mlr.press/v119/chen20j.html)
  
  Adapted from:
      https://github.com/Sara-Ahmed/SiT/blob/1aacd6adcd39b71efc903d16b4e9095b97dda76f/losses.py#L5
docstr: Args:
      temperature: Can be scaled between 0 and 1 for learning from negative samples, ideally set to 0.5.
  
  Raises:
      ValueError: When an input of dimension length > 2 is passed
      ValueError: When input and target are of different shapes
docstr_tok: ["Args",":","temperature",":","Can","be","scaled","between","0","and","1","for","learning","from","negative","samples",",","ideally","set","to","0.5",".","Raises",":","ValueError",":","When","an","input","of","dimension","length",">","2","is","passed","ValueError",":","When","input","and","target","are","of","different","shapes"]
code: def __init__(
      self, temperature: float = 0.5, batch_size: int = -1
  ) -> None:
      """
      Args:
          temperature: Can be scaled between 0 and 1 for learning from negative samples, ideally set to 0.5.
  
      Raises:
          ValueError: When an input of dimension length > 2 is passed
          ValueError: When input and target are of different shapes
  
      """
      super().__init__()
      self.temperature = temperature
  
      if batch_size != -1:
          warn(
              "batch_size is no longer required to be set. It will be estimated dynamically in the forward call"
          )
  
file_path: MONAI/monai/losses/contrastive.py
imports: from __future__ import annotations
  from warnings import warn
  import torch
  from torch.nn import functional
  from torch.nn.modules.loss import _Loss
label_desc: Use image node_id 1 to create a new ContrastiveLoss object from inherited base classes: _Loss with example: obj = ContrastiveLoss(temperature, batch_size)