code: def squad_f1_single(pred, label, pred_idx=0):
      label_start, label_end = label
      span = pred[pred_idx]
      pred_start = span.offset_answer_start
      pred_end = span.offset_answer_end
  
      if (pred_start + pred_end == 0) or (label_start + label_end == 0):
          if pred_start == label_start:
              return 1.0
          else:
              return 0.0
      pred_span = list(range(pred_start, pred_end + 1))
      label_span = list(range(label_start, label_end + 1))
      n_overlap = len([x for x in pred_span if x in label_span])
      if n_overlap == 0:
          return 0.0
      precision = n_overlap / len(pred_span)
      recall = n_overlap / len(label_span)
      f1 = (2 * precision * recall) / (precision + recall)
      return f1
  
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 12 for calling a global function with example usage: squad_f1_single(pred, label, pred_idx) and returns: f1, int, int, int