




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







def  lowerCAmelCase  (	UpperCAmelCase       )  ->Dict:






					"""simple docstring"""






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

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

					def remove_punc(UpperCAmelCase       ):
										__magic_name__					:							Union[str, Any]		   =							set(string.punctuation       )
										return "".join(ch for ch in text if ch not in exclude       )

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

					return white_space_fix(remove_articles(remove_punc(lower(UpperCAmelCase       )       )       )       )







def  lowerCAmelCase  (	UpperCAmelCase,	UpperCAmelCase       )  ->Optional[Any]:






					"""simple docstring"""






					__magic_name__					:							Dict		   =							normalize_answer(UpperCAmelCase       ).split()
					__magic_name__					:							str		   =							normalize_answer(UpperCAmelCase       ).split()
					__magic_name__					:							str		   =							Counter(UpperCAmelCase       ) & Counter(UpperCAmelCase       )
					__magic_name__					:							Optional[Any]		   =							sum(common.values()       )
					if num_same == 0:
										return 0
					__magic_name__					:							Dict		   =							1.0 * num_same / len(UpperCAmelCase       )
					__magic_name__					:							str		   =							1.0 * num_same / len(UpperCAmelCase       )
					__magic_name__					:							Union[str, Any]		   =							(2 * precision * recall) / (precision + recall)
					return fa







def  lowerCAmelCase  (	UpperCAmelCase,	UpperCAmelCase       )  ->Any:






					"""simple docstring"""






					return normalize_answer(UpperCAmelCase       ) == normalize_answer(UpperCAmelCase       )







def  lowerCAmelCase  (	UpperCAmelCase,	UpperCAmelCase,	UpperCAmelCase       )  ->List[Any]:






					"""simple docstring"""






					__magic_name__					:							Optional[int]		   =							[]
					for ground_truth in ground_truths:
										__magic_name__					:							Any		   =							metric_fn(UpperCAmelCase,	UpperCAmelCase       )
										scores_for_ground_truths.append(UpperCAmelCase       )
					return max(UpperCAmelCase       )







def  lowerCAmelCase  (	UpperCAmelCase,	UpperCAmelCase       )  ->Optional[int]:






					"""simple docstring"""






					__magic_name__					:							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:
																									__magic_name__					:							Optional[int]		   =							"Unanswered question " + qa["id"] + " will receive score 0."
																									print(UpperCAmelCase,	file=sys.stderr       )
																									continue
																				__magic_name__					:							Union[str, Any]		   =							[x["text"] for x in qa["answers"]]
																				__magic_name__					:							str		   =							predictions[qa["id"]]
																				exact_match += metric_max_over_ground_truths(UpperCAmelCase,	UpperCAmelCase,	UpperCAmelCase       )
																				fa += metric_max_over_ground_truths(UpperCAmelCase,	UpperCAmelCase,	UpperCAmelCase       )

					__magic_name__					:							List[str]		   =							1_00.0 * exact_match / total
					__magic_name__					:							str		   =							1_00.0 * fa / total

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


if __name__ == "__main__":
				lowercase_		=							"""1.1"""
				lowercase_		=							argparse.ArgumentParser(description='''Evaluation for SQuAD ''' + expected_version)
				parser.add_argument('''dataset_file''', help='''Dataset file''')
				parser.add_argument('''prediction_file''', help='''Prediction File''')
				lowercase_		=							parser.parse_args()
				with open(args.dataset_file) as dataset_file:
								lowercase_		=							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,
												)
								lowercase_		=							dataset_json["""data"""]
				with open(args.prediction_file) as prediction_file:
								lowercase_		=							json.load(prediction_file)
				print(json.dumps(evaluate(dataset, predictions)))











"""simple docstring"""







import argparse

import torch

from transformers import RoFormerConfig, RoFormerForMaskedLM, load_tf_weights_in_roformer
from transformers.utils import logging


logging.set_verbosity_info()





def 						lowercase__(A					,		A					,		A						)				->int:




						"""simple docstring"""



						lowercase__				:      List[str]=       RoFormerConfig.from_json_file(A						)
						print(f'''Building PyTorch model from configuration: {config}'''						)
						lowercase__				:      Tuple=       RoFormerForMaskedLM(A						)

						# Load weights from tf checkpoint
						load_tf_weights_in_roformer(A					,		A					,		A						)

						# Save pytorch-model
						print(f'''Save PyTorch model to {pytorch_dump_path}'''						)
						torch.save(model.state_dict()					,		A					,		_use_new_zipfile_serialization=A						)


if __name__ == "__main__":
			a :				List[str]      					=		argparse.ArgumentParser()
			# Required parameters
			parser.add_argument(
			    """--tf_checkpoint_path""", default=None, type=str, required=True, help="""Path to the TensorFlow checkpoint path."""
			)
			parser.add_argument(
			    """--bert_config_file""",
			    default=None,
			    type=str,
			    required=True,
			    help=(
			        """The config json file corresponding to the pre-trained BERT model. \n"""
			        """This specifies the model architecture."""
			    ),
			)
			parser.add_argument(
			    """--pytorch_dump_path""", default=None, type=str, required=True, help="""Path to the output PyTorch model."""
			)
			a :				str      					=		parser.parse_args()
			convert_tf_checkpoint_to_pytorch(args.tf_checkpoint_path, args.bert_config_file, args.pytorch_dump_path)






