code: def find_best_thresh(preds, scores, na_probs, qid_to_has_ans):
      """
      Find the best threshold of the raw scores.
  
      The initial score is set to the number of unanswerable questions,
      assuming that each unanswerable question is successfully predicted.
      In the following traverse, the best threshold is constantly adjusted
      according to the difference from the assumption ('diff').
      """
      num_no_ans = sum(
          1 for k in qid_to_has_ans if not qid_to_has_ans[k]
      )
      cur_score = num_no_ans
      best_score = cur_score
      best_thresh = 0.0
      # Rearrange the na_probs in an ascending order, so that the questions
      # with higher probability of answerability the sooner will be read.
      qid_list = sorted(na_probs, key=lambda k: na_probs[k])
      for i, qid in enumerate(qid_list):
          if qid not in scores:
              continue
          if qid_to_has_ans[qid]:
              # For the answerable question
              diff = scores[qid]
          else:
              # For the unanswerable question
              if preds[qid]:
                  # Falsely predict the answerability
                  diff = -1
              else:
                  # Correctly predict the answerability. This is Only true if the
                  # prediction is blank, which is no the case before revision
                  diff = 0
          cur_score += diff
          if cur_score > best_score:
              # adjust the best thresh over current thresh (na_probs[qid])
              best_score = cur_score
              best_thresh = na_probs[qid]
      return 100.0 * best_score / len(scores), best_thresh
  
file_path: gluon-nlp/scripts/question_answering/eval_utils.py
imports: import collections
  import json
  import copy
  import re
  import string
label_desc: Use image node_id 10 for calling a global function with example usage: find_best_thresh(preds, scores, na_probs, qid_to_has_ans) and returns: unknown,  best_thresh