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

def 					SCREAMING_SNAKE_CASE  (   __UpperCamelCase			:    Optional[int]							)			->							List[Any]:

				"""simple docstring"""







				def remove_articles(__UpperCamelCase			:    List[str]							):
								return re.sub(R'''\b(a|an|the)\b'''				,    ''' '''				,    __lowerCamelCase							)

				def white_space_fix(__UpperCamelCase			:    Tuple							):
								return " ".join(text.split()							)

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

				def lower(__UpperCamelCase			:    Optional[Any]							):
								return text.lower()

				return white_space_fix(remove_articles(remove_punc(lower(__lowerCamelCase							)							)							)							)

def 					SCREAMING_SNAKE_CASE  (   __UpperCamelCase			:    Optional[int]				,    __UpperCamelCase			:    Optional[int]							)			->							Optional[Any]:

				"""simple docstring"""







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

def 					SCREAMING_SNAKE_CASE  (   __UpperCamelCase			:    Union[str, Any]				,    __UpperCamelCase			:    int							)			->							Optional[Any]:

				"""simple docstring"""







				return normalize_answer(__lowerCamelCase							) == normalize_answer(__lowerCamelCase							)

def 					SCREAMING_SNAKE_CASE  (   __UpperCamelCase			:    Any				,    __UpperCamelCase			:    str				,    __UpperCamelCase			:    Optional[int]							)			->							int:

				"""simple docstring"""







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

def 					SCREAMING_SNAKE_CASE  (   __UpperCamelCase			:    str				,    __UpperCamelCase			:    List[str]							)			->							List[str]:

				"""simple docstring"""







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

				A__	:						Union[str, Any]								=				1_0_0.0 * exact_match / total
				A__	:						List[Any]								=				1_0_0.0 * fa / total

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


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



from typing import Callable, Optional, Union

from ...configuration_utils import PretrainedConfig
from ...utils import logging


SCREAMING_SNAKE_CASE__       			=				logging.get_logger(__name__)

SCREAMING_SNAKE_CASE__       			=				{
    """microsoft/prophetnet-large-uncased""": (
        """https://huggingface.co/microsoft/prophetnet-large-uncased/resolve/main/config.json"""
    ),
}







class     __lowerCamelCase     (  snake_case_     ):


							"""simple docstring"""

							lowerCAmelCase__          =				"prophetnet"
							lowerCAmelCase__          =				["past_key_values"]
							lowerCAmelCase__          =				{
							    "num_attention_heads": "num_encoder_attention_heads",
							}




							def __init__(  self						,       UpperCAmelCase = 0.1						,       UpperCAmelCase = "gelu"						,       UpperCAmelCase = 30522						,       UpperCAmelCase = 1024						,       UpperCAmelCase = 4096						,       UpperCAmelCase = 12						,       UpperCAmelCase = 16						,       UpperCAmelCase = 4096						,       UpperCAmelCase = 12						,       UpperCAmelCase = 16						,       UpperCAmelCase = 0.1						,       UpperCAmelCase = 0.1						,       UpperCAmelCase = 512						,       UpperCAmelCase = 0.02						,       UpperCAmelCase = True						,       UpperCAmelCase = True						,       UpperCAmelCase = 0						,       UpperCAmelCase = 2						,       UpperCAmelCase = 32						,       UpperCAmelCase = 128						,       UpperCAmelCase = False						,       UpperCAmelCase = 0.0						,       UpperCAmelCase = True						,       UpperCAmelCase = 0						,       UpperCAmelCase = 1						,       UpperCAmelCase = 2						,       **UpperCAmelCase						,       )     ->       Dict:






								'''simple docstring'''






								lowercase_			 = vocab_size
								lowercase_			 = hidden_size
								lowercase_			 = encoder_ffn_dim
								lowercase_			 = num_encoder_layers
								lowercase_			 = num_encoder_attention_heads
								lowercase_			 = decoder_ffn_dim
								lowercase_			 = num_decoder_layers
								lowercase_			 = num_decoder_attention_heads
								lowercase_			 = max_position_embeddings
								lowercase_			 = init_std  # Normal(0, this parameter)
								lowercase_			 = activation_function

								# parameters for prophetnet
								lowercase_			 = ngram
								lowercase_			 = num_buckets
								lowercase_			 = relative_max_distance
								lowercase_			 = disable_ngram_loss
								lowercase_			 = eps

								# 3 Types of Dropout
								lowercase_			 = attention_dropout
								lowercase_			 = activation_dropout
								lowercase_			 = dropout

								lowercase_			 = use_cache

								super().__init__(
								    pad_token_id=UpperCAmelCase						,       bos_token_id=UpperCAmelCase						,       eos_token_id=UpperCAmelCase						,       is_encoder_decoder=UpperCAmelCase						,       add_cross_attention=UpperCAmelCase						,       decoder_start_token_id=UpperCAmelCase						,       **UpperCAmelCase						,       )




							@property
							def 				A__      (  self  )     ->       int:






								'''simple docstring'''






								return self.num_encoder_layers + self.num_decoder_layers




							@num_hidden_layers.setter
							def 				A__      (  self						,       UpperCAmelCase  )     ->       Any:






								'''simple docstring'''






								raise NotImplementedError(
								    "This model does not support the setting of `num_hidden_layers`. Please set `num_encoder_layers` and"
								    " `num_decoder_layers`."  )

