


'''simple docstring'''

import os
import tempfile
import unittest
from typing import List

from transformers.models.esm.tokenization_esm import VOCAB_FILES_NAMES, EsmTokenizer
from transformers.testing_utils import require_tokenizers
from transformers.tokenization_utils import PreTrainedTokenizer
from transformers.tokenization_utils_base import PreTrainedTokenizerBase







@require_tokenizers
class 			UpperCAmelCase			(							unittest.TestCase):
 _lowerCamelCase			:       Optional[int]            =       EsmTokenizer

 def 		lowercase_    (			self			:						int       ):





    """simple docstring"""



    super().setUp()
    UpperCamelCase__			    =    tempfile.mkdtemp()
    # fmt: off
    UpperCamelCase__			    =    ["<cls>", "<pad>", "<eos>", "<unk>", "L", "A", "G", "V", "S", "E", "R", "T", "I", "D", "P", "K", "Q", "N", "F", "Y", "M", "H", "W", "C", "X", "B", "U", "Z", "O", ".", "-", "<null_1>", "<mask>"]  # noqa: E501
    # fmt: on
    UpperCamelCase__			    =    os.path.join(self.tmpdirname,       VOCAB_FILES_NAMES["vocab_file"]       )
    with open(self.vocab_file,       "w",       encoding="utf-8"       ) as vocab_writer:
       vocab_writer.write("".join([x + "\n" for x in vocab_tokens]       )       )

 def 		lowercase_    (			self			:						Optional[int],       **a_			:						Dict       ):





    """simple docstring"""



    return [self.get_tokenizer(**a_       )]

 def 		lowercase_    (			self			:						List[Any],       **a_			:						Dict       ):





    """simple docstring"""



    return self.tokenizer_class.from_pretrained(self.tmpdirname,       **a_       )

 def 		lowercase_    (			self			:						int       ):





    """simple docstring"""



    UpperCamelCase__			    =    self.tokenizer_class(self.vocab_file       )

    UpperCamelCase__			    =    tokenizer.tokenize("LAGVS"       )
    self.assertListEqual(a_,       ["L", "A", "G", "V", "S"]       )
    self.assertListEqual(tokenizer.convert_tokens_to_ids(a_       ),       [4, 5, 6, 7, 8]       )

 def 		lowercase_    (			self			:						Union[str, Any]       ):





    """simple docstring"""



    UpperCamelCase__			    =    self.tokenizer_class(self.vocab_file       )

    UpperCamelCase__			    =    "LAGVS"
    self.assertListEqual(tokenizer.encode(a_       ),       [0, 4, 5, 6, 7, 8, 2]       )

 def 		lowercase_    (			self			:						List[str]       ):





    """simple docstring"""



    UpperCamelCase__			    =    self.tokenizer_class(self.vocab_file       )

    UpperCamelCase__			    =    ["LAGVS", "WCB"]
    UpperCamelCase__			    =    tokenizer(a_,       padding=a_       )["input_ids"]

    self.assertListEqual(a_,       [[0, 4, 5, 6, 7, 8, 2], [0, 22, 23, 25, 2]]       )

 def 		lowercase_    (			self			:						int       ):





    """simple docstring"""



    UpperCamelCase__			    =    self.tokenizer_class(self.vocab_file       )

    UpperCamelCase__			    =    ["LAGVS", "WCB"]
    UpperCamelCase__			    =    tokenizer(a_,       padding=a_       )["input_ids"]

    self.assertListEqual(a_,       [[0, 4, 5, 6, 7, 8, 2], [0, 22, 23, 25, 2, 1, 1]]       )

 def 		lowercase_    (			self			:						Tuple       ):





    """simple docstring"""



    UpperCamelCase__			    =    self.get_tokenizers(fast=a_       )
    for tokenizer in tokenizers:
       with self.subTest(f'{tokenizer.__class__.__name__}'       ):
          UpperCamelCase__			    =    "<unk>"
          UpperCamelCase__			    =    "<mask>"

          UpperCamelCase__			    =    tokenizer.tokenize(a_       )
          UpperCamelCase__			    =    tokenizer.tokenize(a_       )

          self.assertEqual(len(a_       ),       1       )
          self.assertEqual(len(a_       ),       1       )
          self.assertEqual(token_a[0],       a_       )
          self.assertEqual(token_a[0],       a_       )







"""simple docstring"""





import argparse
import json
import re
import string
import sys
from collections import Counter






def 							A(    snake_case_						):
       """simple docstring"""





       def remove_articles(snake_case_						):
              return re.sub(r"\b(a|an|the)\b"		,  " "		,  snake_case_						)

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

       def remove_punc(snake_case_						):
              lowercase__:							str         =     set(string.punctuation						)
              return "".join(ch for ch in text if ch not in exclude						)

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

       return white_space_fix(remove_articles(remove_punc(lower(snake_case_						)						)						)						)






def 							A(    snake_case_		,  snake_case_						):
       """simple docstring"""





       lowercase__:							Dict         =     normalize_answer(snake_case_						).split()
       lowercase__:							List[str]         =     normalize_answer(snake_case_						).split()
       lowercase__:							Optional[int]         =     Counter(snake_case_						) & Counter(snake_case_						)
       lowercase__:							Any         =     sum(common.values()						)
       if num_same == 0:
              return 0
       lowercase__:							Any         =     1.0 * num_same / len(snake_case_						)
       lowercase__:							List[Any]         =     1.0 * num_same / len(snake_case_						)
       lowercase__:							int         =     (2 * precision * recall) / (precision + recall)
       return fa






def 							A(    snake_case_		,  snake_case_						):
       """simple docstring"""





       return normalize_answer(snake_case_						) == normalize_answer(snake_case_						)






def 							A(    snake_case_		,  snake_case_		,  snake_case_						):
       """simple docstring"""





       lowercase__:							int         =     []
       for ground_truth in ground_truths:
              lowercase__:							str         =     metric_fn(snake_case_		,  snake_case_						)
              scores_for_ground_truths.append(snake_case_						)
       return max(snake_case_						)






def 							A(    snake_case_		,  snake_case_						):
       """simple docstring"""





       lowercase__:							Optional[int]         =     0
       for article in dataset:
              for paragraph in article["paragraphs"]:
                     for qa in paragraph["qas"]:
                            total += 1
                            if qa["id"] not in predictions:
                                   lowercase__:							Union[str, Any]         =     "Unanswered question " + qa["id"] + " will receive score 0."
                                   print(snake_case_		,  file=sys.stderr						)
                                   continue
                            lowercase__:							List[Any]         =     [x["text"] for x in qa["answers"]]
                            lowercase__:							Optional[Any]         =     predictions[qa["id"]]
                            exact_match += metric_max_over_ground_truths(snake_case_		,  snake_case_		,  snake_case_						)
                            fa += metric_max_over_ground_truths(snake_case_		,  snake_case_		,  snake_case_						)

       lowercase__:							Union[str, Any]         =     1_00.0 * exact_match / total
       lowercase__:							str         =     1_00.0 * fa / total

       return {"exact_match": exact_match, "f1": fa}


if __name__ == "__main__":
  UpperCamelCase					=     """1.1"""
  UpperCamelCase					=     argparse.ArgumentParser(description="""Evaluation for SQuAD """ + expected_version)
  parser.add_argument("""dataset_file""", help="""Dataset file""")
  parser.add_argument("""prediction_file""", help="""Prediction File""")
  UpperCamelCase					=     parser.parse_args()
  with open(args.dataset_file) as dataset_file:
    UpperCamelCase					=     json.load(dataset_file)
    if dataset_json["version"] != expected_version:
      print(
          """Evaluation expects v-""" + expected_version + """, but got dataset with v-""" + dataset_json["""version"""],
          file=sys.stderr,
      )
    UpperCamelCase					=     dataset_json["""data"""]
  with open(args.prediction_file) as prediction_file:
    UpperCamelCase					=     json.load(prediction_file)
  print(json.dumps(evaluate(dataset, predictions)))






