class_docstr: Self Adversarial Sampling loss.
  
  Introduced in :cite:`sun2018rotate`.
  
  .. math::
  
      \mathcal{L} = -log \left( \sigma(\gamma + f_{model} (\mathbf{s},\mathbf{o})) \right)
      - \sum_{i=1}^{n} p(h'_{i}, r, t'_{i} ) \cdot log
      \left( \sigma(-f_{model}(\mathbf{s}'_{i},\mathbf{o}'_{i}) - \gamma) \right)
  
  where :math:`\mathbf{s}, \mathbf{o} \in \mathcal{R}^k` are the embeddings of the subject
  and object of a triple :math:`t=(s,r,o)`, :math:`\gamma \in \mathbb{R}` is the margin, :math:`\sigma` the sigmoid
  function, and :math:`p(s'_{i}, r, o'_{i})` is the negatives sampling distribution which is defined as:
  
  .. math::
  
      p(s'_j, r, o'_j | \{(s_i, r_i, o_i)\}) = \frac{\exp \left( \alpha \, f_{model}(\mathbf{s'_j}, \mathbf{o'_j}) \right)}
      {\sum_i \exp \left( \alpha \, f_{model}(\mathbf{s'_i}, \mathbf{o'_i}) \right)}
  
  where :math:`\alpha` is the temperature of sampling and :math:`f_{model}` is the scoring function of
  the desired embedding model.
  
  Example
  -------
  >>> import ampligraph.latent_features.loss_functions as lfs
  >>> loss = lfs.SelfAdversarialLoss({'margin': 1, 'alpha': 0.1, 'reduction': 'mean'})
  >>> isinstance(loss, lfs.SelfAdversarialLoss)
  True
  
  >>> loss = lfs.get('self_adversarial')
  >>> isinstance(loss, lfs.SelfAdversarialLoss)
  True
class_docstr_tok: ["Self","Adversarial","Sampling","loss",".","Introduced","in",":","cite",":","`","sun2018rotate","`",".","..","math",":",":","\\mathcal","{","L","}","=","-log","\\left","(","\\sigma","(","\\gamma","+","f_","{","model","}","(","\\mathbf","{","s","}",",","\\mathbf","{","o","}",")",")","\\right",")","-","\\sum_","{","i=1","}","^","{","n","}","p","(","h","'","_","{","i","}",",","r",",","t","'","_","{","i","}",")","\\cdot","log","\\left","(","\\sigma","(","-f_","{","model","}","(","\\mathbf","{","s","}","'","_","{","i","}",",","\\mathbf","{","o","}","'","_","{","i","}",")","-","\\gamma",")","\\right",")","where",":","math",":","`","\\mathbf","{","s","}",",","\\mathbf","{","o","}","\\in","\\mathcal","{","R","}","^k","`","are","the","embeddings","of","the","subject","and","object","of","a","triple",":","math",":","`","t=","(","s",",","r",",","o",")","`",",",":","math",":","`","\\gamma","\\in","\\mathbb","{","R","}","`","is","the","margin",",",":","math",":","`","\\sigma","`","the","sigmoid","function",",","and",":","math",":","`","p","(","s","'","_","{","i","}",",","r",",","o","'","_","{","i","}",")","`","is","the","negatives","sampling","distribution","which","is","defined","as",":","..","math",":",":","p","(","s'_j",",","r",",","o'_j","|","\\","{","(","s_i",",","r_i",",","o_i",")","\\","}",")","=","\\frac","{","\\exp","\\left","(","\\alpha","\\",",","f_","{","model","}","(","\\mathbf","{","s'_j","}",",","\\mathbf","{","o'_j","}",")","\\right",")","}","{","\\sum_i","\\exp","\\left","(","\\alpha","\\",",","f_","{","model","}","(","\\mathbf","{","s'_i","}",",","\\mathbf","{","o'_i","}",")","\\right",")","}","where",":","math",":","`","\\alpha","`","is","the","temperature","of","sampling","and",":","math",":","`","f_","{","model","}","`","is","the","scoring","function","of","the","desired","embedding","model",".","Example","--","--","--","-",">",">",">","import","ampligraph.latent_features.loss_functions","as","lfs",">",">",">","loss","=","lfs.SelfAdversarialLoss","(","{","'margin","'",":","1",",","'alpha","'",":","0.1",",","'reduction","'",":","'mean","'","}",")",">",">",">","isinstance","(","loss",",","lfs.SelfAdversarialLoss",")","True",">",">",">","loss","=","lfs.get","(","'self_adversarial","'",")",">",">",">","isinstance","(","loss",",","lfs.SelfAdversarialLoss",")","True"]
docstr: Initialize the loss.
  
  Parameters
  ----------
  loss_params : dict
      Dictionary of loss-specific hyperparams:
  
      - `"margin"`: (float) - Margin to be used for loss computation (default: 1).
      - `"alpha"`: (float) - Temperature of sampling (default: 0.5).
      - `"reduction"`: (str) - Specifies whether to `"sum"` or take the `"mean"` of the loss per sample w.r.t.                 corruption (default: `"sum"`).
  
      Example: `loss_params={'margin': 1, 'alpha': 0.5}`.
docstr_tok: ["Initialize","the","loss",".","Parameters","--","--","--","--","--","loss_params",":","dict","Dictionary","of","loss-specific","hyperparams",":","-","`","``","margin","''","`",":","(","float",")","-","Margin","to","be","used","for","loss","computation","(","default",":","1",")",".","-","`","``","alpha","''","`",":","(","float",")","-","Temperature","of","sampling","(","default",":","0.5",")",".","-","`","``","reduction","''","`",":","(","str",")","-","Specifies","whether","to","`","``","sum","''","`","or","take","the","`","``","mean","''","`","of","the","loss","per","sample","w.r.t",".","corruption","(","default",":","`","``","sum","''","`",")",".","Example",":","`","loss_params=","{","'margin","'",":","1",",","'alpha","'",":","0.5","}","`","."]
code: def __init__(self, loss_params={}, verbose=False):
      """Initialize the loss.
  
          Parameters
          ----------
          loss_params : dict
              Dictionary of loss-specific hyperparams:
  
              - `"margin"`: (float) - Margin to be used for loss computation (default: 1).
              - `"alpha"`: (float) - Temperature of sampling (default: 0.5).
              - `"reduction"`: (str) - Specifies whether to `"sum"` or take the `"mean"` of the loss per sample w.r.t. \
                  corruption (default: `"sum"`).
  
              Example: `loss_params={'margin': 1, 'alpha': 0.5}`.
  
          """
      super().__init__(loss_params, verbose)
  
imports: import abc
  import logging
  import six
  import tensorflow
  from tensorflow.python.keras import metrics
  from tensorflow.python.keras.utils import losses_utils
  from tensorflow.python.ops import math_ops
label_desc: Use image node_id 1 to create a new SelfAdversarialLoss object from inherited base classes: Loss with example: obj = SelfAdversarialLoss(loss_params, verbose)