code: def load_libsvm_data(path, list_size):
      """Returns features and labels in numpy.array."""
  
      def _parse_line(line):
          """Parses a single line in LibSVM format."""
          tokens = line.split("#")[0].split()
          assert len(tokens) >= 2, "Ill-formatted line: {}".format(line)
          label = float(tokens[0])
          qid = tokens[1]
          kv_pairs = [kv.split(":") for kv in tokens[2:]]
          features = {k: float(v) for (k, v) in kv_pairs}
          return qid, features, label
  
      tf.compat.v1.logging.info("Loading data from {}".format(path))
  
      # The 0-based index assigned to a query.
      qid_to_index = {}
      # The number of docs seen so far for a query.
      qid_to_ndoc = {}
      # Each feature is mapped an array with [num_queries, list_size, 1]. Label has
      # a shape of [num_queries, list_size]. We use list for each of them due to the
      # unknown number of queries.
      feature_map = {k: [] for k in example_feature_columns()}
      label_list = []
      total_docs = 0
      discarded_docs = 0
      with open(path, "rt") as f:
          for line in f:
              qid, features, label = _parse_line(line)
              if qid not in qid_to_index:
                  # Create index and allocate space for a new query.
                  qid_to_index[qid] = len(qid_to_index)
                  qid_to_ndoc[qid] = 0
                  for k in feature_map:
                      feature_map[k].append(
                          np.zeros([list_size, 1], dtype=np.float32)
                      )
                  label_list.append(
                      np.ones([list_size], dtype=np.float32) * -1.0
                  )
              total_docs += 1
              batch_idx = qid_to_index[qid]
              doc_idx = qid_to_ndoc[qid]
              qid_to_ndoc[qid] += 1
              # Keep the first 'list_size' docs only.
              if doc_idx >= list_size:
                  discarded_docs += 1
                  continue
              for k, v in six.iteritems(features):
                  assert (
                      k in feature_map
                  ), "Key {} not found in features.".format(k)
                  feature_map[k][batch_idx][doc_idx, 0] = v
              label_list[batch_idx][doc_idx] = label
  
      tf.compat.v1.logging.info(
          "Number of queries: {}".format(len(qid_to_index))
      )
      tf.compat.v1.logging.info(
          "Number of documents in total: {}".format(total_docs)
      )
      tf.compat.v1.logging.info(
          "Number of documents discarded: {}".format(discarded_docs)
      )
  
      # Convert everything to np.array.
      for k in feature_map:
          feature_map[k] = np.array(feature_map[k])
      return feature_map, np.array(label_list)
  
imports: from absl import flags
  import numpy
  import six
  import tensorflow
  from tensorflow import estimator
  import tensorflow_ranking
label_desc: Use image node_id 3 for calling a global function with example usage: load_libsvm_data(path, list_size) and returns: feature_map,  np, qid,  features,  label