code: def sample_triplet(X, batch_size):
      sampled_data = np.zeros((batch_size, 3), dtype=np.int)
  
      count = 0
      while count < batch_size:
          u = random.randint(0, X.shape[0] - 1)
          u_row = X.getrow(u)
          _, u_nz = u_row.nonzero()
          min_rating = u_row[:, u_nz].todense().min()
  
          i = u_nz[random.randint(0, len(u_nz) - 1)]
          ratingi = u_row[:, i]
  
          if ratingi > min_rating:
              j = u_nz[random.randint(0, len(u_nz) - 1)]
  
              while u_row[:, j] >= ratingi:
                  j = u_nz[random.randint(0, len(u_nz) - 1)]
  
              sampled_data[count, :] = [u, i, j]
              count += 1
  
      print("Done sampling")
      return sampled_data
  
imports: import random
  import numpy
  import torch
label_desc: Use image node_id 1 for calling a global function with example usage: sample_triplet(X, batch_size) and returns: sampled_data