class_docstr: In the state-of-the-art KGE models, loss functions were designed according to
  various pointwise, pairwise and multi-class approaches. Refers to
  `Loss Functions in Knowledge Graph Embedding Models
  <https://alammehwish.github.io/dl4kg-eswc/papers/paper%201.pdf>`__
  
  **Pointwise Loss Function**
  
  `MSELoss <https://pytorch.org/docs/master/generated/torch.nn.MSELoss.html>`__
  Creates a criterion that measures the mean squared error (squared L2 norm)
  between each element in the input :math:`x` and target :math:`y`.
  
  
  `SOFTMARGINLOSS <https://pytorch.org/docs/master/generated/torch.nn.SoftMarginLoss
  .html>`__ Creates a criterion that optimizes a two-class classification
  logistic loss between input tensor :math:`x` and target tensor :math:`y`
  (containing 1 or -1).
  Tips:   The number of positive and negative samples should be about the same,
          otherwise it's easy to overfit
  
  .. math::
      \text{loss}(x, y) = \sum_i \frac{\log(1 + \exp(-y[i]*x[i]))}{\text{x.nelement}()}
  
  
  **Pairwise Loss Function**
  
  `SoftplusLoss <https://github.com/thunlp/OpenKE/blob/OpenKE-PyTorch/openke/module/loss/
  SoftplusLoss.py>`__
  refers to the paper `OpenKE: An Open Toolkit for Knowledge Embedding
  <https://www.aclweb.org/anthology/D18-2024.pdf>`__
  
  `SigmoidLoss <https://github.com/thunlp/OpenKE/blob/OpenKE-PyTorch/openke/module/loss/
  SigmoidLoss.py>`__
  refers to the paper `OpenKE: An Open Toolkit for Knowledge Embedding
  <https://www.aclweb.org/anthology/D18-2024.pdf>`__
  
  **Multi-Class Loss Function**
  
  `Binary Cross Entropy Loss <https://pytorch.org/docs/master/generated/torch.nn.BCELoss.html>`__
  Creates a criterion that measures the Binary Cross Entropy between the target
  and the output. Note that the targets
  :math:`y` should be numbers between 0 and 1.
class_docstr_tok: ["In","the","state-of-the-art","KGE","models",",","loss","functions","were","designed","according","to","various","pointwise",",","pairwise","and","multi-class","approaches",".","Refers","to","`","Loss","Functions","in","Knowledge","Graph","Embedding","Models","<","https",":","\/\/alammehwish.github.io\/dl4kg-eswc\/papers\/paper","%","201.pdf",">","`","__","*","*","Pointwise","Loss","Function","*","*","`","MSELoss","<","https",":","\/\/pytorch.org\/docs\/master\/generated\/torch.nn.MSELoss.html",">","`","__","Creates","a","criterion","that","measures","the","mean","squared","error","(","squared","L2","norm",")","between","each","element","in","the","input",":","math",":","`","x","`","and","target",":","math",":","`","y","`",".","`","SOFTMARGINLOSS","<","https",":","\/\/pytorch.org\/docs\/master\/generated\/torch.nn.SoftMarginLoss",".html",">","`","__","Creates","a","criterion","that","optimizes","a","two-class","classification","logistic","loss","between","input","tensor",":","math",":","`","x","`","and","target","tensor",":","math",":","`","y","`","(","containing","1","or","-1",")",".","Tips",":","The","number","of","positive","and","negative","samples","should","be","about","the","same",",","otherwise","it","'s","easy","to","overfit","..","math",":",":","\\text","{","loss","}","(","x",",","y",")","=","\\sum_i","\\frac","{","\\log","(","1","+","\\exp","(","-y","[","i","]","*","x","[","i","]",")",")","}","{","\\text","{","x.nelement","}","(",")","}","*","*","Pairwise","Loss","Function","*","*","`","SoftplusLoss","<","https",":","\/\/github.com\/thunlp\/OpenKE\/blob\/OpenKE-PyTorch\/openke\/module\/loss\/","SoftplusLoss.py",">","`","__","refers","to","the","paper","`","OpenKE",":","An","Open","Toolkit","for","Knowledge","Embedding","<","https",":","\/\/www.aclweb.org\/anthology\/D18-2024.pdf",">","`","__","`","SigmoidLoss","<","https",":","\/\/github.com\/thunlp\/OpenKE\/blob\/OpenKE-PyTorch\/openke\/module\/loss\/","SigmoidLoss.py",">","`","__","refers","to","the","paper","`","OpenKE",":","An","Open","Toolkit","for","Knowledge","Embedding","<","https",":","\/\/www.aclweb.org\/anthology\/D18-2024.pdf",">","`","__","*","*","Multi-Class","Loss","Function","*","*","`","Binary","Cross","Entropy","Loss","<","https",":","\/\/pytorch.org\/docs\/master\/generated\/torch.nn.BCELoss.html",">","`","__","Creates","a","criterion","that","measures","the","Binary","Cross","Entropy","between","the","target","and","the","output",".","Note","that","the","targets",":","math",":","`","y","`","should","be","numbers","between","0","and","1","."]
code: def __init__(
      self,
      loss_type,
      size_average=None,
      reduce=None,
      reduction="mean",
      adv_temperature=None,
      weight=None,
  ):
      super(KGLoss, self).__init__()
      self.loss_type = loss_type
      if loss_type == "MSELoss":
          self.loss_function = nn.MSELoss(
              size_average, reduce, reduction
          )
      elif loss_type == "SoftMarginLoss":
          self.loss_function = nn.SoftMarginLoss(
              size_average, reduce, reduction
          )
      elif loss_type == "SoftplusLoss":
          self.loss_function = SoftplusLoss(adv_temperature)
      elif loss_type == "SigmoidLoss":
          self.loss_function = SigmoidLoss(adv_temperature)
      elif loss_type == "BCELoss":
          self.loss_function = nn.BCELoss(
              weight, size_average, reduce, reduction
          )
      else:
          raise NotImplementedError()
      return
  
file_path: graph4nlp/graph4nlp/pytorch/modules/loss/kg_loss.py
imports: import torch
  import torch.nn
  from .base import KGLossBase
label_desc: Use image node_id 1 to create a new KGLoss object from inherited base classes: KGLossBase with example: obj = KGLoss(loss_type, size_average, reduce, reduction, adv_temperature, weight)