code: def metrics_per_bin(preds, labels, num_bins=10):
      pred_bins = [[] for _ in range(num_bins)]
      label_bins = [[] for _ in range(num_bins)]
      count_per_bin = [0] * num_bins
      for pred, label in zip(preds, labels):
          current_score = pred[0][0].confidence
          if current_score >= 1.0:
              current_score = 0.9999
          pred_bins[int(current_score * num_bins)].append(pred)
          label_bins[int(current_score * num_bins)].append(label)
          count_per_bin[int(current_score * num_bins)] += 1
  
      em_per_bin = [0] * num_bins
      confidence_per_bin = [0] * num_bins
      for i in range(num_bins):
          em_per_bin[i] = squad_EM_start(
              preds=pred_bins[i], labels=label_bins[i]
          )
          confidence_per_bin[i] = confidence(preds=pred_bins[i])
      return em_per_bin, confidence_per_bin, count_per_bin
  
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 14 for calling a global function with example usage: metrics_per_bin(preds, labels, num_bins) and returns: em_per_bin,  confidence_per_bin,  count_per_bin