code: def text_similarity_metric(preds, labels):
      """
      Returns accuracy, F1 scores and average rank scores for text similarity task
  
      :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 metrics(accuracy, F1, average rank) for text similarity task
      """
      scores = text_similarity_acc_and_f1(preds, labels)
      scores["average_rank"] = text_similarity_avg_ranks(preds, labels)
      return scores
  
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 20 for calling a global function with example usage: text_similarity_metric(preds, labels) and returns: scores