code: def top_n_accuracy(preds, labels):
      """
      This method calculates the percentage of documents for which the model makes top n accurate predictions.
      The definition of top n accurate a top n accurate prediction is as follows:
      For any given question document pair, there can be multiple predictions from the model and multiple labels.
      If any of those predictions overlap at all with any of the labels, those predictions are considered to be top n accurate.
      """
      answer_in_top_n = []
      n_questions = len(preds)
      for i in range(n_questions):
          f1_score = 0
          current_preds = preds[i][0]
          for idx, pred in enumerate(current_preds):
              f1_score = max(
                  [
                      squad_f1_single(
                          current_preds, label, pred_idx=idx
                      )
                      for label in labels[i]
                  ]
              )
              if f1_score:
                  break
          if f1_score:
              answer_in_top_n.append(1)
          else:
              answer_in_top_n.append(0)
  
      return np.mean(answer_in_top_n)
  
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 17 for calling a global function with example usage: top_n_accuracy(preds, labels) and returns: np