code: def test_self_adversarial_negative_sampling(temperature):
      labels = np.array([1, 0, -2, 0, 1], dtype=np.int32)
      logit_scores = np.array(
          [1.2, -2.3, 0.0, 4.5, -0.67], dtype=np.float32
      )
      scores = expit(logit_scores)
  
      loss_func = SelfAdversarialNegativeSampling(temperature)
      actual_loss = loss_func(
          tf.constant(labels), tf.constant(logit_scores)
      )
  
      def loss_part(score, label):
          # equations (5) and (6) in http://arxiv.org/abs/1902.10197
          if label == 1:
              # positive edge
              return -np.log(score)
  
          # Negative sample. The
          relevant = scores[np.where(labels == label)]
          numer = np.exp(temperature * score)
          denom = np.sum(np.exp(temperature * relevant))
  
          # sigmoid(-x) == 1 - sigmoid(x)
          return -np.log(1 - score) * numer / denom
  
      expected_loss = np.mean(
          [
              loss_part(score, label)
              for score, label in zip(scores, labels)
          ]
      )
      assert actual_loss.numpy() == pytest.approx(
          expected_loss, rel=1e-6
      )
  
file_path: stellargraph/tests/test_losses.py
imports: from stellargraph.losses import *
  import numpy
  import pytest
  import tensorflow
  from scipy.special import softmax, expit
label_desc: Use image node_id 2 for calling a global function with example usage: test_self_adversarial_negative_sampling(temperature) and returns: unknown, unknown