class_docstr: The ComplEx model from the `"Complex Embeddings for Simple Link
  Prediction" <https://arxiv.org/abs/1606.06357>`_ paper.
  
  :class:`ComplEx` models relations as complex-valued bilinear mappings
  between head and tail entities using the Hermetian dot product.
  The entities and relations are embedded in different dimensional spaces,
  resulting in the scoring function:
  
  .. math::
      d(h, r, t) = Re(< \mathbf{e}_h,  \mathbf{e}_r, \mathbf{e}_t>)
  
  .. note::
  
      For an example of using the :class:`ComplEx` model, see
      `examples/kge_fb15k_237.py
      <https://github.com/pyg-team/pytorch_geometric/blob/master/examples/
      kge_fb15k_237.py>`_.
  
  Args:
      num_nodes (int): The number of nodes/entities in the graph.
      num_relations (int): The number of relations in the graph.
      hidden_channels (int): The hidden embedding size.
      sparse (bool, optional): If set to :obj:`True`, gradients w.r.t. to
          the embedding matrices will be sparse. (default: :obj:`False`)
class_docstr_tok: ["The","ComplEx","model","from","the","`","``","Complex","Embeddings","for","Simple","Link","Prediction","''","<","https",":","\/\/arxiv.org\/abs\/1606.06357",">","`","_","paper",".",":","class",":","`","ComplEx","`","models","relations","as","complex-valued","bilinear","mappings","between","head","and","tail","entities","using","the","Hermetian","dot","product",".","The","entities","and","relations","are","embedded","in","different","dimensional","spaces",",","resulting","in","the","scoring","function",":","..","math",":",":","d","(","h",",","r",",","t",")","=","Re","(","<","\\mathbf","{","e","}","_h",",","\\mathbf","{","e","}","_r",",","\\mathbf","{","e","}","_t",">",")","..","note",":",":","For","an","example","of","using","the",":","class",":","`","ComplEx","`","model",",","see","`","examples\/kge_fb15k_237.py","<","https",":","\/\/github.com\/pyg-team\/pytorch_geometric\/blob\/master\/examples\/","kge_fb15k_237.py",">","`","_",".","Args",":","num_nodes","(","int",")",":","The","number","of","nodes\/entities","in","the","graph",".","num_relations","(","int",")",":","The","number","of","relations","in","the","graph",".","hidden_channels","(","int",")",":","The","hidden","embedding","size",".","sparse","(","bool",",","optional",")",":","If","set","to",":","obj",":","`","True","`",",","gradients","w.r.t",".","to","the","embedding","matrices","will","be","sparse",".","(","default",":",":","obj",":","`","False","`",")"]
code: def loss(
      self,
      head_index: Tensor,
      rel_type: Tensor,
      tail_index: Tensor,
  ) -> Tensor:
      pos_score = self(head_index, rel_type, tail_index)
      neg_score = self(
          *self.random_sample(head_index, rel_type, tail_index)
      )
      scores = torch.cat([pos_score, neg_score], dim=0)
  
      pos_target = torch.ones_like(pos_score)
      neg_target = torch.zeros_like(neg_score)
      target = torch.cat([pos_target, neg_target], dim=0)
  
      return F.binary_cross_entropy_with_logits(scores, target)
  
file_path: pytorch_geometric/torch_geometric/nn/kge/complex.py
imports: import torch
  import torch.nn.functional
  from torch import Tensor
  from torch.nn import Embedding
  from torch_geometric.nn.kge import KGEModel
label_desc: Use image node_id 4 for calling the ComplEx obj's underlying member method code with example usage: obj.loss(head_index, rel_type, tail_index) and returns: F