



'''simple docstring'''





import argparse
import collections
import json
import os
import re
import string
import sys

import numpy as np


__a          =		re.compile(R"\b(a|an|the)\b", re.UNICODE)

__a          =		None





def 						__snake_case(				)		-> Any:
      snake_case__  :    Any    						=      argparse.ArgumentParser("""Official evaluation script for SQuAD version 2.0."""		)
      parser.add_argument("""data_file"""     ,   metavar="""data.json"""     ,   help="""Input data JSON file."""		)
      parser.add_argument("""pred_file"""     ,   metavar="""pred.json"""     ,   help="""Model predictions."""		)
      parser.add_argument(
          """--out-file"""     ,   """-o"""     ,   metavar="""eval.json"""     ,   help="""Write accuracy metrics to file (default is stdout)."""		)
      parser.add_argument(
          """--na-prob-file"""     ,   """-n"""     ,   metavar="""na_prob.json"""     ,   help="""Model estimates of probability of no answer."""		)
      parser.add_argument(
          """--na-prob-thresh"""     ,   """-t"""     ,   type=_lowerCAmelCase     ,   default=1.0     ,   help="""Predict \"\" if no-answer probability exceeds this (default = 1.0)."""     ,   )
      parser.add_argument(
          """--out-image-dir"""     ,   """-p"""     ,   metavar="""out_images"""     ,   default=_lowerCAmelCase     ,   help="""Save precision-recall curves to directory."""		)
      parser.add_argument("""--verbose"""     ,   """-v"""     ,   action="""store_true"""		)
      if len(sys.argv		) == 1:
            parser.print_help()
            sys.exit(1		)
      return parser.parse_args()





def 						__snake_case(				_lowerCAmelCase		)		-> List[Any]:
      snake_case__  :    Any    						=      {}
      for article in dataset:
            for p in article["paragraphs"]:
                  for qa in p["qas"]:
                        snake_case__  :    List[str]    						=      bool(qa["""answers"""]["""text"""]		)
      return qid_to_has_ans





def 						__snake_case(				_lowerCAmelCase		)		-> Tuple:

      def remove_articles(_lowerCAmelCase		):
            return ARTICLES_REGEX.sub(""" """     ,   _lowerCAmelCase		)

      def white_space_fix(_lowerCAmelCase		):
            return " ".join(text.split()		)

      def remove_punc(_lowerCAmelCase		):
            snake_case__  :    Optional[int]    						=      set(string.punctuation		)
            return "".join(ch for ch in text if ch not in exclude		)

      def lower(_lowerCAmelCase		):
            return text.lower()

      return white_space_fix(remove_articles(remove_punc(lower(_lowerCAmelCase		)		)		)		)





def 						__snake_case(				_lowerCAmelCase		)		-> Dict:
      if not s:
            return []
      return normalize_answer(_lowerCAmelCase		).split()





def 						__snake_case(				_lowerCAmelCase     ,   _lowerCAmelCase		)		-> int:
      return int(normalize_answer(_lowerCAmelCase		) == normalize_answer(_lowerCAmelCase		)		)





def 						__snake_case(				_lowerCAmelCase     ,   _lowerCAmelCase		)		-> int:
      snake_case__  :    Union[str, Any]    						=      get_tokens(_lowerCAmelCase		)
      snake_case__  :    Optional[Any]    						=      get_tokens(_lowerCAmelCase		)
      snake_case__  :    Optional[Any]    						=      collections.Counter(_lowerCAmelCase		) & collections.Counter(_lowerCAmelCase		)
      snake_case__  :    int    						=      sum(common.values()		)
      if len(_lowerCAmelCase		) == 0 or len(_lowerCAmelCase		) == 0:
            # If either is no-answer, then F1 is 1 if they agree, 0 otherwise
            return int(gold_toks == pred_toks		)
      if num_same == 0:
            return 0
      snake_case__  :    List[Any]    						=      1.0 * num_same / len(_lowerCAmelCase		)
      snake_case__  :    Any    						=      1.0 * num_same / len(_lowerCAmelCase		)
      snake_case__  :    List[str]    						=      (2 * precision * recall) / (precision + recall)
      return fa





def 						__snake_case(				_lowerCAmelCase     ,   _lowerCAmelCase		)		-> Any:
      snake_case__  :    Optional[Any]    						=      {}
      snake_case__  :    Any    						=      {}
      for article in dataset:
            for p in article["paragraphs"]:
                  for qa in p["qas"]:
                        snake_case__  :    Optional[int]    						=      qa["""id"""]
                        snake_case__  :    Optional[Any]    						=      [t for t in qa["""answers"""]["""text"""] if normalize_answer(_lowerCAmelCase		)]
                        if not gold_answers:
                              # For unanswerable questions, only correct answer is empty string
                              snake_case__  :    Optional[int]    						=      [""""""]
                        if qid not in preds:
                              print(f"Missing prediction for {qid}"		)
                              continue
                        snake_case__  :    Tuple    						=      preds[qid]
                        # Take max over all gold answers
                        snake_case__  :    str    						=      max(compute_exact(_lowerCAmelCase     ,   _lowerCAmelCase		) for a in gold_answers		)
                        snake_case__  :    Any    						=      max(compute_fa(_lowerCAmelCase     ,   _lowerCAmelCase		) for a in gold_answers		)
      return exact_scores, fa_scores





def 						__snake_case(				_lowerCAmelCase     ,   _lowerCAmelCase     ,   _lowerCAmelCase     ,   _lowerCAmelCase		)		-> Any:
      snake_case__  :    Optional[int]    						=      {}
      for qid, s in scores.items():
            snake_case__  :    Optional[Any]    						=      na_probs[qid] > na_prob_thresh
            if pred_na:
                  snake_case__  :    Optional[int]    						=      float(not qid_to_has_ans[qid]		)
            else:
                  snake_case__  :    Union[str, Any]    						=      s
      return new_scores





def 						__snake_case(				_lowerCAmelCase     ,   _lowerCAmelCase     ,   _lowerCAmelCase=None		)		-> List[str]:
      if not qid_list:
            snake_case__  :    str    						=      len(_lowerCAmelCase		)
            return collections.OrderedDict(
                [
                    ("""exact""", 100.0 * sum(exact_scores.values()		) / total),
                    ("""f1""", 100.0 * sum(fa_scores.values()		) / total),
                    ("""total""", total),
                ]		)
      else:
            snake_case__  :    int    						=      len(_lowerCAmelCase		)
            return collections.OrderedDict(
                [
                    ("""exact""", 100.0 * sum(exact_scores[k] for k in qid_list		) / total),
                    ("""f1""", 100.0 * sum(fa_scores[k] for k in qid_list		) / total),
                    ("""total""", total),
                ]		)





def 						__snake_case(				_lowerCAmelCase     ,   _lowerCAmelCase     ,   _lowerCAmelCase		)		-> Dict:
      for k in new_eval:
            snake_case__  :    str    						=      new_eval[k]





def 						__snake_case(				_lowerCAmelCase     ,   _lowerCAmelCase     ,   _lowerCAmelCase     ,   _lowerCAmelCase		)		-> int:
      plt.step(_lowerCAmelCase     ,   _lowerCAmelCase     ,   color="""b"""     ,   alpha=0.2     ,   where="""post"""		)
      plt.fill_between(_lowerCAmelCase     ,   _lowerCAmelCase     ,   step="""post"""     ,   alpha=0.2     ,   color="""b"""		)
      plt.xlabel("""Recall"""		)
      plt.ylabel("""Precision"""		)
      plt.xlim([0.0, 1.05]		)
      plt.ylim([0.0, 1.05]		)
      plt.title(_lowerCAmelCase		)
      plt.savefig(_lowerCAmelCase		)
      plt.clf()





def 						__snake_case(				_lowerCAmelCase     ,   _lowerCAmelCase     ,   _lowerCAmelCase     ,   _lowerCAmelCase     ,   _lowerCAmelCase=None     ,   _lowerCAmelCase=None		)		-> Any:
      snake_case__  :    Optional[int]    						=      sorted(_lowerCAmelCase     ,   key=lambda _lowerCAmelCase		: na_probs[k]		)
      snake_case__  :    str    						=      0.0
      snake_case__  :    Dict    						=      1.0
      snake_case__  :    List[str]    						=      0.0
      snake_case__  :    Dict    						=      [1.0]
      snake_case__  :    int    						=      [0.0]
      snake_case__  :    str    						=      0.0
      for i, qid in enumerate(_lowerCAmelCase		):
            if qid_to_has_ans[qid]:
                  true_pos += scores[qid]
            snake_case__  :    Dict    						=      true_pos / float(i + 1		)
            snake_case__  :    Union[str, Any]    						=      true_pos / float(_lowerCAmelCase		)
            if i == len(_lowerCAmelCase		) - 1 or na_probs[qid] != na_probs[qid_list[i + 1]]:
                  # i.e., if we can put a threshold after this point
                  avg_prec += cur_p * (cur_r - recalls[-1])
                  precisions.append(_lowerCAmelCase		)
                  recalls.append(_lowerCAmelCase		)
      if out_image:
            plot_pr_curve(_lowerCAmelCase     ,   _lowerCAmelCase     ,   _lowerCAmelCase     ,   _lowerCAmelCase		)
      return {"ap": 100.0 * avg_prec}





def 						__snake_case(				_lowerCAmelCase     ,   _lowerCAmelCase     ,   _lowerCAmelCase     ,   _lowerCAmelCase     ,   _lowerCAmelCase     ,   _lowerCAmelCase		)		-> Union[str, Any]:
      if out_image_dir and not os.path.exists(_lowerCAmelCase		):
            os.makedirs(_lowerCAmelCase		)
      snake_case__  :    Optional[Any]    						=      sum(1 for v in qid_to_has_ans.values() if v		)
      if num_true_pos == 0:
            return
      snake_case__  :    Any    						=      make_precision_recall_eval(
          _lowerCAmelCase     ,   _lowerCAmelCase     ,   _lowerCAmelCase     ,   _lowerCAmelCase     ,   out_image=os.path.join(_lowerCAmelCase     ,   """pr_exact.png"""		)     ,   title="""Precision-Recall curve for Exact Match score"""     ,   )
      snake_case__  :    Optional[Any]    						=      make_precision_recall_eval(
          _lowerCAmelCase     ,   _lowerCAmelCase     ,   _lowerCAmelCase     ,   _lowerCAmelCase     ,   out_image=os.path.join(_lowerCAmelCase     ,   """pr_f1.png"""		)     ,   title="""Precision-Recall curve for F1 score"""     ,   )
      snake_case__  :    Any    						=      {k: float(_lowerCAmelCase		) for k, v in qid_to_has_ans.items()}
      snake_case__  :    Union[str, Any]    						=      make_precision_recall_eval(
          _lowerCAmelCase     ,   _lowerCAmelCase     ,   _lowerCAmelCase     ,   _lowerCAmelCase     ,   out_image=os.path.join(_lowerCAmelCase     ,   """pr_oracle.png"""		)     ,   title="""Oracle Precision-Recall curve (binary task of HasAns vs. NoAns)"""     ,   )
      merge_eval(_lowerCAmelCase     ,   _lowerCAmelCase     ,   """pr_exact"""		)
      merge_eval(_lowerCAmelCase     ,   _lowerCAmelCase     ,   """pr_f1"""		)
      merge_eval(_lowerCAmelCase     ,   _lowerCAmelCase     ,   """pr_oracle"""		)





def 						__snake_case(				_lowerCAmelCase     ,   _lowerCAmelCase     ,   _lowerCAmelCase     ,   _lowerCAmelCase		)		-> Optional[int]:
      if not qid_list:
            return
      snake_case__  :    Optional[Any]    						=      [na_probs[k] for k in qid_list]
      snake_case__  :    Union[str, Any]    						=      np.ones_like(_lowerCAmelCase		) / float(len(_lowerCAmelCase		)		)
      plt.hist(_lowerCAmelCase     ,   weights=_lowerCAmelCase     ,   bins=20     ,   range=(0.0, 1.0)		)
      plt.xlabel("""Model probability of no-answer"""		)
      plt.ylabel("""Proportion of dataset"""		)
      plt.title(f"Histogram of no-answer probability: {name}"		)
      plt.savefig(os.path.join(_lowerCAmelCase     ,   f"na_prob_hist_{name}.png"		)		)
      plt.clf()





def 						__snake_case(				_lowerCAmelCase     ,   _lowerCAmelCase     ,   _lowerCAmelCase     ,   _lowerCAmelCase		)		-> Optional[int]:
      snake_case__  :    List[str]    						=      sum(1 for k in qid_to_has_ans if not qid_to_has_ans[k]		)
      snake_case__  :    Union[str, Any]    						=      num_no_ans
      snake_case__  :    Optional[int]    						=      cur_score
      snake_case__  :    Optional[Any]    						=      0.0
      snake_case__  :    Optional[int]    						=      sorted(_lowerCAmelCase     ,   key=lambda _lowerCAmelCase		: na_probs[k]		)
      for i, qid in enumerate(_lowerCAmelCase		):
            if qid not in scores:
                  continue
            if qid_to_has_ans[qid]:
                  snake_case__  :    List[str]    						=      scores[qid]
            else:
                  if preds[qid]:
                        snake_case__  :    Tuple    						=      -1
                  else:
                        snake_case__  :    List[Any]    						=      0
            cur_score += diff
            if cur_score > best_score:
                  snake_case__  :    Optional[Any]    						=      cur_score
                  snake_case__  :    Union[str, Any]    						=      na_probs[qid]
      return 100.0 * best_score / len(_lowerCAmelCase		), best_thresh





def 						__snake_case(				_lowerCAmelCase     ,   _lowerCAmelCase     ,   _lowerCAmelCase     ,   _lowerCAmelCase     ,   _lowerCAmelCase     ,   _lowerCAmelCase		)		-> Tuple:
      snake_case__						,				snake_case__  :    List[str]    						=      find_best_thresh(_lowerCAmelCase     ,   _lowerCAmelCase     ,   _lowerCAmelCase     ,   _lowerCAmelCase		)
      snake_case__						,				snake_case__  :    int    						=      find_best_thresh(_lowerCAmelCase     ,   _lowerCAmelCase     ,   _lowerCAmelCase     ,   _lowerCAmelCase		)
      snake_case__  :    List[Any]    						=      best_exact
      snake_case__  :    Dict    						=      exact_thresh
      snake_case__  :    List[Any]    						=      best_fa
      snake_case__  :    Dict    						=      fa_thresh





def 						__snake_case(				)		-> Optional[int]:
      with open(OPTS.data_file		) as f:
            snake_case__  :    Union[str, Any]    						=      json.load(_lowerCAmelCase		)
            snake_case__  :    Dict    						=      dataset_json["""data"""]
      with open(OPTS.pred_file		) as f:
            snake_case__  :    int    						=      json.load(_lowerCAmelCase		)
      if OPTS.na_prob_file:
            with open(OPTS.na_prob_file		) as f:
                  snake_case__  :    Tuple    						=      json.load(_lowerCAmelCase		)
      else:
            snake_case__  :    List[Any]    						=      {k: 0.0 for k in preds}
      snake_case__  :    List[Any]    						=      make_qid_to_has_ans(_lowerCAmelCase		)  # maps qid to True/False
      snake_case__  :    Optional[int]    						=      [k for k, v in qid_to_has_ans.items() if v]
      snake_case__  :    str    						=      [k for k, v in qid_to_has_ans.items() if not v]
      snake_case__						,				snake_case__  :    int    						=      get_raw_scores(_lowerCAmelCase     ,   _lowerCAmelCase		)
      snake_case__  :    Dict    						=      apply_no_ans_threshold(_lowerCAmelCase     ,   _lowerCAmelCase     ,   _lowerCAmelCase     ,   OPTS.na_prob_thresh		)
      snake_case__  :    Optional[Any]    						=      apply_no_ans_threshold(_lowerCAmelCase     ,   _lowerCAmelCase     ,   _lowerCAmelCase     ,   OPTS.na_prob_thresh		)
      snake_case__  :    List[Any]    						=      make_eval_dict(_lowerCAmelCase     ,   _lowerCAmelCase		)
      if has_ans_qids:
            snake_case__  :    Optional[Any]    						=      make_eval_dict(_lowerCAmelCase     ,   _lowerCAmelCase     ,   qid_list=_lowerCAmelCase		)
            merge_eval(_lowerCAmelCase     ,   _lowerCAmelCase     ,   """HasAns"""		)
      if no_ans_qids:
            snake_case__  :    str    						=      make_eval_dict(_lowerCAmelCase     ,   _lowerCAmelCase     ,   qid_list=_lowerCAmelCase		)
            merge_eval(_lowerCAmelCase     ,   _lowerCAmelCase     ,   """NoAns"""		)
      if OPTS.na_prob_file:
            find_all_best_thresh(_lowerCAmelCase     ,   _lowerCAmelCase     ,   _lowerCAmelCase     ,   _lowerCAmelCase     ,   _lowerCAmelCase     ,   _lowerCAmelCase		)
      if OPTS.na_prob_file and OPTS.out_image_dir:
            run_precision_recall_analysis(_lowerCAmelCase     ,   _lowerCAmelCase     ,   _lowerCAmelCase     ,   _lowerCAmelCase     ,   _lowerCAmelCase     ,   OPTS.out_image_dir		)
            histogram_na_prob(_lowerCAmelCase     ,   _lowerCAmelCase     ,   OPTS.out_image_dir     ,   """hasAns"""		)
            histogram_na_prob(_lowerCAmelCase     ,   _lowerCAmelCase     ,   OPTS.out_image_dir     ,   """noAns"""		)
      if OPTS.out_file:
            with open(OPTS.out_file     ,   """w"""		) as f:
                  json.dump(_lowerCAmelCase     ,   _lowerCAmelCase		)
      else:
            print(json.dumps(_lowerCAmelCase     ,   indent=2		)		)


if __name__ == "__main__":
       __a          =		parse_args()
       if OPTS.out_image_dir:
              import matplotlib

              matplotlib.use("Agg")
              import matplotlib.pyplot as plt
       main()





'''simple docstring'''





# Function to print upper half of diamond (pyramid)





def 						__snake_case(				_lowerCAmelCase		)		-> Any:
      for i in range(0     ,   _lowerCAmelCase		):
            for _ in range(0     ,   n - i - 1		):  # printing spaces
                  print(""" """     ,   end=""""""		)
            for _ in range(0     ,   i + 1		):  # printing stars
                  print("""* """     ,   end=""""""		)
            print()





def 						__snake_case(				_lowerCAmelCase		)		-> List[str]:
      for i in range(_lowerCAmelCase     ,   0     ,   -1		):
            for _ in range(_lowerCAmelCase     ,   0     ,   -1		):  # printing stars
                  print("""* """     ,   end=""""""		)
            print()
            for _ in range(n - i + 1     ,   0     ,   -1		):  # printing spaces
                  print(""" """     ,   end=""""""		)





def 						__snake_case(				_lowerCAmelCase		)		-> List[Any]:
      if n <= 0:
            print("""       ...       ....        nothing printing :("""		)
            return
      floyd(_lowerCAmelCase		)  # upper half
      reverse_floyd(_lowerCAmelCase		)  # lower half


if __name__ == "__main__":
       print(R"| /\ | |- |  |-  |--| |\  /| |-")
       print(R"|/  \| |- |_ |_  |__| | \/ | |_")
       __a          =		1
       while K:
              __a          =		int(input("enter the number and , and see the magic : "))
              print()
              pretty_print(user_number)
              __a          =		int(input("press 0 to exit... and 1 to continue..."))

       print("Good Bye...")
