code: 
  
  
  
  
  
  import datasets
  
  from .evaluate import (
      apply_no_ans_threshold,
      find_all_best_thresh,
      get_raw_scores,
      make_eval_dict,
      make_qid_to_has_ans,
      merge_eval,
  )
  
  
  _UpperCamelCase       = '''\
  @inproceedings{Rajpurkar2016SQuAD10,
    title={SQuAD: 100, 000+ Questions for Machine Comprehension of Text},
    author={Pranav Rajpurkar and Jian Zhang and Konstantin Lopyrev and Percy Liang},
    booktitle={EMNLP},
    year={2016}
  }
  '''
  
  _UpperCamelCase       = '''
  This metric wrap the official scoring script for version 2 of the Stanford Question
  Answering Dataset (SQuAD).
  
  Stanford Question Answering Dataset (SQuAD) is a reading comprehension dataset, consisting of questions posed by
  crowdworkers on a set of Wikipedia articles, where the answer to every question is a segment of text, or span,
  from the corresponding reading passage, or the question might be unanswerable.
  
  SQuAD2.0 combines the 100,000 questions in SQuAD1.1 with over 50,000 unanswerable questions
  written adversarially by crowdworkers to look similar to answerable ones.
  To do well on SQuAD2.0, systems must not only answer questions when possible, but also
  determine when no answer is supported by the paragraph and abstain from answering.
  '''
  
  _UpperCamelCase       = '''
  Computes SQuAD v2 scores (F1 and EM).
  Args:
      predictions: List of triple for question-answers to score with the following elements:
          - the question-answer \'id\' field as given in the references (see below)
          - the text of the answer
          - the probability that the question has no answer
      references: List of question-answers dictionaries with the following key-values:
              - \'id\': id of the question-answer pair (see above),
              - \'answers\': a list of Dict {\'text\': text of the answer as a string}
      no_answer_threshold: float
          Probability threshold to decide that a question has no answer.
  Returns:
      \'exact\': Exact match (the normalized answer exactly match the gold answer)
      \'f1\': The F-score of predicted tokens versus the gold answer
      \'total\': Number of score considered
      \'HasAns_exact\': Exact match (the normalized answer exactly match the gold answer)
      \'HasAns_f1\': The F-score of predicted tokens versus the gold answer
      \'HasAns_total\': Number of score considered
      \'NoAns_exact\': Exact match (the normalized answer exactly match the gold answer)
      \'NoAns_f1\': The F-score of predicted tokens versus the gold answer
      \'NoAns_total\': Number of score considered
      \'best_exact\': Best exact match (with varying threshold)
      \'best_exact_thresh\': No-answer probability threshold associated to the best exact match
      \'best_f1\': Best F1 (with varying threshold)
      \'best_f1_thresh\': No-answer probability threshold associated to the best F1
  Examples:
  
      >>> predictions = [{\'prediction_text\': \'1976\', \'id\': \'56e10a3be3433e1400422b22\', \'no_answer_probability\': 0.}]
      >>> references = [{\'answers\': {\'answer_start\': [97], \'text\': [\'1976\']}, \'id\': \'56e10a3be3433e1400422b22\'}]
      >>> squad_v2_metric = datasets.load_metric("squad_v2")
      >>> results = squad_v2_metric.compute(predictions=predictions, references=references)
      >>> print(results)
      {\'exact\': 100.0, \'f1\': 100.0, \'total\': 1, \'HasAns_exact\': 100.0, \'HasAns_f1\': 100.0, \'HasAns_total\': 1, \'best_exact\': 100.0, \'best_exact_thresh\': 0.0, \'best_f1\': 100.0, \'best_f1_thresh\': 0.0}
  '''
  
  
  
  
  @datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION ,   _KWARGS_DESCRIPTION    )
  class 				_lowerCamelCase (    datasets.Metric    ):
  
  
  
        """simple docstring"""
  
  
  
  
  
  
        def 						UpperCAmelCase		( self   )       ->   Optional[Any]:
  
  
  
  
  
  
          '''simple docstring'''
  
  
  
  
  
  
          return datasets.MetricInfo(
              description=_DESCRIPTION				,						citation=_CITATION				,						inputs_description=_KWARGS_DESCRIPTION				,						features=datasets.Features(
                  {
                      "predictions": {
                          "id": datasets.Value("string"   ),
                          "prediction_text": datasets.Value("string"   ),
                          "no_answer_probability": datasets.Value("float32"   ),
                      },
                      "references": {
                          "id": datasets.Value("string"   ),
                          "answers": datasets.features.Sequence(
                              {"text": datasets.Value("string"   ), "answer_start": datasets.Value("int32"   )}   ),
                      },
                  }   )				,						codebase_urls=["https://rajpurkar.github.io/SQuAD-explorer/"]				,						reference_urls=["https://rajpurkar.github.io/SQuAD-explorer/"]				,						)
  
  
  
  
  
  
  
        def 						UpperCAmelCase		( self				,						UpperCAmelCase				,						UpperCAmelCase				,						UpperCAmelCase=1.0   )       ->   Tuple:
  
  
  
  
  
  
          '''simple docstring'''
  
  
  
  
  
  
          __snake_case   :				int        =       {p["id"]: p["no_answer_probability"] for p in predictions}
          __snake_case   :				Optional[Any]        =       [{"paragraphs": [{"qas": references}]}]
          __snake_case   :				Union[str, Any]        =       {p["id"]: p["prediction_text"] for p in predictions}
  
          __snake_case   :				List[str]        =       make_qid_to_has_ans(UpperCAmelCase   )  # maps qid to True/False
          __snake_case   :				Dict        =       [k for k, v in qid_to_has_ans.items() if v]
          __snake_case   :				Tuple        =       [k for k, v in qid_to_has_ans.items() if not v]
  
          __snake_case    ,   __snake_case   :				Any        =       get_raw_scores(UpperCAmelCase				,						UpperCAmelCase   )
          __snake_case   :				Optional[Any]        =       apply_no_ans_threshold(UpperCAmelCase				,						UpperCAmelCase				,						UpperCAmelCase				,						UpperCAmelCase   )
          __snake_case   :				Optional[Any]        =       apply_no_ans_threshold(UpperCAmelCase				,						UpperCAmelCase				,						UpperCAmelCase				,						UpperCAmelCase   )
          __snake_case   :				Optional[Any]        =       make_eval_dict(UpperCAmelCase				,						UpperCAmelCase   )
  
          if has_ans_qids:
            __snake_case   :				List[str]        =       make_eval_dict(UpperCAmelCase				,						UpperCAmelCase				,						qid_list=UpperCAmelCase   )
            merge_eval(UpperCAmelCase				,						UpperCAmelCase				,						"HasAns"   )
          if no_ans_qids:
            __snake_case   :				Any        =       make_eval_dict(UpperCAmelCase				,						UpperCAmelCase				,						qid_list=UpperCAmelCase   )
            merge_eval(UpperCAmelCase				,						UpperCAmelCase				,						"NoAns"   )
          find_all_best_thresh(UpperCAmelCase				,						UpperCAmelCase				,						UpperCAmelCase				,						UpperCAmelCase				,						UpperCAmelCase				,						UpperCAmelCase   )
          return dict(UpperCAmelCase   )
  
  
style_context: 
  
  
  
  
  
  import subprocess
  from argparse import ArgumentParser
  from typing import List, Union
  
  from huggingface_hub.hf_api import HfFolder, create_repo, whoami
  from requests.exceptions import HTTPError
  
  from . import BaseTransformersCLICommand
  
  
  
  
  class 				_lowerCamelCase (    a    ):
  
  
  
        """simple docstring"""
  
  
  
  
  
  
        @staticmethod
        def 						UpperCAmelCase		( UpperCAmelCase   )       ->   Any:
  
  
  
  
  
  
          '''simple docstring'''
  
  
  
  
  
  
          __snake_case   :				Dict        =       parser.add_parser("login"				,						help="Log in using the same credentials as on huggingface.co"   )
          login_parser.set_defaults(func=lambda UpperCAmelCase   : LoginCommand(UpperCAmelCase   )   )
          __snake_case   :				int        =       parser.add_parser("whoami"				,						help="Find out which huggingface.co account you are logged in as."   )
          whoami_parser.set_defaults(func=lambda UpperCAmelCase   : WhoamiCommand(UpperCAmelCase   )   )
          __snake_case   :				int        =       parser.add_parser("logout"				,						help="Log out"   )
          logout_parser.set_defaults(func=lambda UpperCAmelCase   : LogoutCommand(UpperCAmelCase   )   )
  
          # new system: git-based repo system
          __snake_case   :				Union[str, Any]        =       parser.add_parser(
              "repo"				,						help="Deprecated: use `huggingface-cli` instead. Commands to interact with your huggingface.co repos."				,						)
          __snake_case   :				List[str]        =       repo_parser.add_subparsers(
              help="Deprecated: use `huggingface-cli` instead. huggingface.co repos related commands"   )
          __snake_case   :				int        =       repo_subparsers.add_parser(
              "create"				,						help="Deprecated: use `huggingface-cli` instead. Create a new repo on huggingface.co"   )
          repo_create_parser.add_argument(
              "name"				,						type=UpperCAmelCase				,						help="Name for your model's repo. Will be namespaced under your username to build the model id."				,						)
          repo_create_parser.add_argument("--organization"				,						type=UpperCAmelCase				,						help="Optional: organization namespace."   )
          repo_create_parser.add_argument("-y"				,						"--yes"				,						action="store_true"				,						help="Optional: answer Yes to the prompt"   )
          repo_create_parser.set_defaults(func=lambda UpperCAmelCase   : RepoCreateCommand(UpperCAmelCase   )   )
  
  
  
  
  class 				_lowerCamelCase :
  
  
  
        """simple docstring"""
  
  
  
  
  
  
        UpperCAmelCase_						:      Tuple       ="\u001b[1m"
        UpperCAmelCase_						:      int       ="\u001b[31m"
        UpperCAmelCase_						:      Optional[Any]       ="\u001b[90m"
        UpperCAmelCase_						:      Optional[Any]       ="\u001b[0m"
  
  
  
  
  
  
  
        @classmethod
        def 						UpperCAmelCase		( cls				,						UpperCAmelCase   )       ->   Union[str, Any]:
  
  
  
  
  
  
          '''simple docstring'''
  
  
  
  
  
  
          return F"""{cls._bold}{s}{cls._reset}"""
  
  
  
  
  
  
  
        @classmethod
        def 						UpperCAmelCase		( cls				,						UpperCAmelCase   )       ->   Optional[int]:
  
  
  
  
  
  
          '''simple docstring'''
  
  
  
  
  
  
          return F"""{cls._bold}{cls._red}{s}{cls._reset}"""
  
  
  
  
  
  
  
        @classmethod
        def 						UpperCAmelCase		( cls				,						UpperCAmelCase   )       ->   List[str]:
  
  
  
  
  
  
          '''simple docstring'''
  
  
  
  
  
  
          return F"""{cls._gray}{s}{cls._reset}"""
  
  
  
  
  
  
  
  def       lowerCAmelCase__(	lowercase       :    List[List[Union[str, int]]]   ,     lowercase       :    List[str]				) ->    str:
    __snake_case   :				Dict        =       [max(len(str(lowercase				)				) for x in col				) for col in zip(*lowercase   ,     lowercase				)]
    __snake_case   :				str        =       ("{{:{}}} " * len(lowercase				)).format(*lowercase				)
    __snake_case   :				Tuple        =       []
    lines.append(row_format.format(*lowercase				)				)
    lines.append(row_format.format(*["-" * w for w in col_widths]				)				)
    for row in rows:
      lines.append(row_format.format(*lowercase				)				)
    return "\n".join(lowercase				)
  
  
  
  
  class 				_lowerCamelCase :
  
  
  
        """simple docstring"""
  
  
  
  
  
  
        def __init__( self				,						UpperCAmelCase   )       ->   Dict:
  
  
  
  
  
  
          '''simple docstring'''
  
  
  
  
  
  
          __snake_case   :				List[str]        =       args
  
  
  
  
  class 				_lowerCamelCase (    a    ):
  
  
  
        """simple docstring"""
  
  
  
  
  
  
        def 						UpperCAmelCase		( self   )       ->   Union[str, Any]:
  
  
  
  
  
  
          '''simple docstring'''
  
  
  
  
  
  
          print(
              ANSI.red(
                  "ERROR! `huggingface-cli login` uses an outdated login mechanism "
                  "that is not compatible with the Hugging Face Hub backend anymore. "
                  "Please use `huggingface-cli login instead."   )   )
  
  
  
  
  class 				_lowerCamelCase (    a    ):
  
  
  
        """simple docstring"""
  
  
  
  
  
  
        def 						UpperCAmelCase		( self   )       ->   str:
  
  
  
  
  
  
          '''simple docstring'''
  
  
  
  
  
  
          print(
              ANSI.red(
                  "WARNING! `transformers-cli whoami` is deprecated and will be removed in v5. Please use "
                  "`huggingface-cli whoami` instead."   )   )
          __snake_case   :				Optional[Any]        =       HfFolder.get_token()
          if token is None:
            print("Not logged in"   )
            exit()
          try:
            __snake_case    ,   __snake_case   :				Tuple        =       whoami(UpperCAmelCase   )
            print(UpperCAmelCase   )
            if orgs:
              print(ANSI.bold("orgs: "   )				,						",".join(UpperCAmelCase   )   )
          except HTTPError as e:
            print(UpperCAmelCase   )
            print(ANSI.red(e.response.text   )   )
            exit(1   )
  
  
  
  
  class 				_lowerCamelCase (    a    ):
  
  
  
        """simple docstring"""
  
  
  
  
  
  
        def 						UpperCAmelCase		( self   )       ->   List[str]:
  
  
  
  
  
  
          '''simple docstring'''
  
  
  
  
  
  
          print(
              ANSI.red(
                  "ERROR! `transformers-cli logout` uses an outdated logout mechanism "
                  "that is not compatible with the Hugging Face Hub backend anymore. "
                  "Please use `huggingface-cli logout instead."   )   )
  
  
  
  
  class 				_lowerCamelCase (    a    ):
  
  
  
        """simple docstring"""
  
  
  
  
  
  
        def 						UpperCAmelCase		( self   )       ->   Tuple:
  
  
  
  
  
  
          '''simple docstring'''
  
  
  
  
  
  
          print(
              ANSI.red(
                  "WARNING! Managing repositories through transformers-cli is deprecated. "
                  "Please use `huggingface-cli` instead."   )   )
          __snake_case   :				Dict        =       HfFolder.get_token()
          if token is None:
            print("Not logged in"   )
            exit(1   )
          try:
            __snake_case   :				Optional[int]        =       subprocess.check_output(["git", "--version"]   ).decode("utf-8"   )
            print(ANSI.gray(stdout.strip()   )   )
          except FileNotFoundError:
            print("Looks like you do not have git installed, please install."   )
  
          try:
            __snake_case   :				Union[str, Any]        =       subprocess.check_output(["git-lfs", "--version"]   ).decode("utf-8"   )
            print(ANSI.gray(stdout.strip()   )   )
          except FileNotFoundError:
            print(
                ANSI.red(
                    "Looks like you do not have git-lfs installed, please install."
                    " You can install from https://git-lfs.github.com/."
                    " Then run `git lfs install` (you only have to do this once)."   )   )
          print(""   )
  
          __snake_case    ,   __snake_case   :				Any        =       whoami(UpperCAmelCase   )
          __snake_case   :				List[str]        =       self.args.organization if self.args.organization is not None else user
          __snake_case   :				Any        =       F"""{namespace}/{self.args.name}"""
          print(F"""You are about to create {ANSI.bold(UpperCAmelCase   )}"""   )
  
          if not self.args.yes:
            __snake_case   :				Optional[int]        =       input("Proceed? [Y/n] "   ).lower()
            if not (choice == "" or choice == "y" or choice == "yes"):
              print("Abort"   )
              exit()
          try:
            __snake_case   :				List[str]        =       create_repo(UpperCAmelCase				,						name=self.args.name				,						organization=self.args.organization   )
          except HTTPError as e:
            print(UpperCAmelCase   )
            print(ANSI.red(e.response.text   )   )
            exit(1   )
          print("\nYour repo now lives at:"   )
          print(F"""  {ANSI.bold(UpperCAmelCase   )}"""   )
          print("\nYou can clone it locally with the command below, and commit/push as usual."   )
          print(F"""\n  git clone {url}"""   )
          print(""   )
  
  