code: def lifted_struct_loss_np(labels, embedding, margin):
      num_data = embedding.shape[0]
      # Reshape labels to compute adjacency matrix.
      labels_reshaped = np.reshape(labels, (labels.shape[0], 1))
  
      adjacency = np.equal(labels_reshaped, labels_reshaped.T)
      pdist_matrix = pairwise_distance_np(embedding)
      loss_np = 0.0
      num_constraints = 0.0
      for i in range(num_data):
          for j in range(num_data):
              if adjacency[i][j] > 0.0 and i != j:
                  d_pos = pdist_matrix[i][j]
                  negs = []
                  for k in range(num_data):
                      if not adjacency[i][k]:
                          negs.append(margin - pdist_matrix[i][k])
                  for m in range(num_data):
                      if not adjacency[j][m]:
                          negs.append(margin - pdist_matrix[j][m])
  
                  negs = np.array(negs)
                  max_elem = np.max(negs)
                  negs -= max_elem
                  negs = np.exp(negs)
                  soft_maximum = np.log(np.sum(negs)) + max_elem
  
                  num_constraints += 1.0
                  this_loss = max(soft_maximum + d_pos, 0)
                  loss_np += this_loss * this_loss
  
      loss_np = loss_np / num_constraints / 2.0
      return loss_np
  
file_path: addons/tensorflow_addons/losses/tests/lifted_test.py
imports: import pytest
  import numpy
  import tensorflow
  from tensorflow_addons.losses import lifted
  from tensorflow_addons.utils import test_utils
label_desc: Use image node_id 2 for calling a global function with example usage: lifted_struct_loss_np(labels, embedding, margin) and returns: loss_np