code: def text_similarity_acc_and_f1(preds, labels):
      """
      Returns accuracy and F1 scores for top-1(highest) ranked sequence(context/passage) for each sample/query
  
      :param preds: list of numpy arrays of dimension n1 x n2 containing n2 predicted ranks for n1 sequences/queries
      :type preds: List of numpy array containing similarity scores for each sequence in batch
      :param labels: list of arrays of dimension n1 x n2 where each array contains n2 labels(0/1) indicating whether the sequence/passage is a positive(1) passage or hard_negative(0) passage
      :type labels: List of list containing values(0/1)
  
      :return: predicted ranks of passages for each query
      """
      top_1_pred = reduce(
          lambda x, y: x + [0] * y[0] + [1] + [0] * (len(y) - y[0] - 1),
          preds,
          [],
      )
      labels = reduce(
          lambda x, y: x + list(y.astype("long")), labels, []
      )
      res = acc_and_f1(top_1_pred, labels)
      return res
  
imports: import logging
  import numpy
  import torch
  from functools import reduce
  from scipy.stats import pearsonr, spearmanr
  from seqeval.metrics import classification_report
  from seqeval.metrics import f1_score
  from sklearn.metrics import matthews_corrcoef, f1_score, mean_squared_error, r2_score, classification_report
  from farm.utils import flatten_list
label_desc: Use image node_id 18 for calling a global function with example usage: text_similarity_acc_and_f1(preds, labels) and returns: res