code: def mergesetfeat3(X, labels, gX, glabels, beta=0.08, knn=20, lr=0.5):
      for i in range(0, X.shape[0]):
          if i % 1000 == 0:
              print("feat3:%d/%d" % (i, X.shape[0]))
          knnX = gX[glabels[:, 1] != labels[i, 1], :]
          sim = knnX.dot(X[i, :])
          knnX = knnX[sim > 0, :]
          sim = sim[sim > 0]
          if len(sim) > 0:
              idx = np.argsort(-sim)
              if len(sim) > 2 * knn:
                  sim = sim[idx[: 2 * knn]]
                  knnX = knnX[idx[: 2 * knn], :]
              else:
                  sim = sim[idx]
                  knnX = knnX[idx, :]
                  knn = min(knn, len(sim))
              knn_pos_weight = np.exp((sim[:knn] - 1) / beta)
              knn_neg_weight = np.ones(len(sim) - knn)
              knn_pos_prob = knn_pos_weight / np.sum(knn_pos_weight)
              knn_neg_prob = knn_neg_weight / np.sum(knn_neg_weight)
              X[i, :] += lr * (
                  knn_pos_prob.dot(knnX[:knn, :])
                  - knn_neg_prob.dot(knnX[knn:, :])
              )
              X[i, :] /= np.linalg.norm(X[i, :])
      return X
  
imports: import os
  import re
  import cv2
  import gc
  import numpy
  import pandas
  from tqdm import tqdm
  import warnings
label_desc: Use image node_id 9 for calling a global function with example usage: mergesetfeat3(X, labels, gX, glabels, beta, knn, lr) and returns: X