





'''simple docstring'''






from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


A_		:  Dict		 =						logging.get_logger(__name__)

A_		:  Optional[Any]		 =						{
    "xlm-mlm-en-2048": "https://huggingface.co/xlm-mlm-en-2048/resolve/main/config.json",
    "xlm-mlm-ende-1024": "https://huggingface.co/xlm-mlm-ende-1024/resolve/main/config.json",
    "xlm-mlm-enfr-1024": "https://huggingface.co/xlm-mlm-enfr-1024/resolve/main/config.json",
    "xlm-mlm-enro-1024": "https://huggingface.co/xlm-mlm-enro-1024/resolve/main/config.json",
    "xlm-mlm-tlm-xnli15-1024": "https://huggingface.co/xlm-mlm-tlm-xnli15-1024/resolve/main/config.json",
    "xlm-mlm-xnli15-1024": "https://huggingface.co/xlm-mlm-xnli15-1024/resolve/main/config.json",
    "xlm-clm-enfr-1024": "https://huggingface.co/xlm-clm-enfr-1024/resolve/main/config.json",
    "xlm-clm-ende-1024": "https://huggingface.co/xlm-clm-ende-1024/resolve/main/config.json",
    "xlm-mlm-17-1280": "https://huggingface.co/xlm-mlm-17-1280/resolve/main/config.json",
    "xlm-mlm-100-1280": "https://huggingface.co/xlm-mlm-100-1280/resolve/main/config.json",
}
class 					__snake_case  (					__SCREAMING_SNAKE_CASE							):






   '''simple docstring'''





   lowerCamelCase__    							=      '''xlm'''
   lowerCamelCase__    							=      {
       '''hidden_size''': '''emb_dim''',
       '''num_attention_heads''': '''n_heads''',
       '''num_hidden_layers''': '''n_layers''',
       '''n_words''': '''vocab_size''',  # For backward compatibility
   }

   def __init__(							self	,		__SCREAMING_SNAKE_CASE=3_0_1_4_5	,		__SCREAMING_SNAKE_CASE=2_0_4_8	,		__SCREAMING_SNAKE_CASE=1_2	,		__SCREAMING_SNAKE_CASE=1_6	,		__SCREAMING_SNAKE_CASE=0.1	,		__SCREAMING_SNAKE_CASE=0.1	,		__SCREAMING_SNAKE_CASE=True	,		__SCREAMING_SNAKE_CASE=False	,		__SCREAMING_SNAKE_CASE=False	,		__SCREAMING_SNAKE_CASE=False	,		__SCREAMING_SNAKE_CASE=1	,		__SCREAMING_SNAKE_CASE=True	,		__SCREAMING_SNAKE_CASE=5_1_2	,		__SCREAMING_SNAKE_CASE=2_0_4_8**-0.5	,		__SCREAMING_SNAKE_CASE=1e-1_2	,		__SCREAMING_SNAKE_CASE=0.02	,		__SCREAMING_SNAKE_CASE=0	,		__SCREAMING_SNAKE_CASE=1	,		__SCREAMING_SNAKE_CASE=2	,		__SCREAMING_SNAKE_CASE=3	,		__SCREAMING_SNAKE_CASE=5	,		__SCREAMING_SNAKE_CASE=True	,		__SCREAMING_SNAKE_CASE="first"	,		__SCREAMING_SNAKE_CASE=True	,		__SCREAMING_SNAKE_CASE=None	,		__SCREAMING_SNAKE_CASE=True	,		__SCREAMING_SNAKE_CASE=0.1	,		__SCREAMING_SNAKE_CASE=5	,		__SCREAMING_SNAKE_CASE=5	,		__SCREAMING_SNAKE_CASE=0	,		__SCREAMING_SNAKE_CASE=0	,		__SCREAMING_SNAKE_CASE=2	,		__SCREAMING_SNAKE_CASE=0	,		**__SCREAMING_SNAKE_CASE	,		):
    snake_case__     :					Tuple    =  vocab_size
    snake_case__     :					Any    =  emb_dim
    snake_case__     :					str    =  n_layers
    snake_case__     :					Dict    =  n_heads
    snake_case__     :					Union[str, Any]    =  dropout
    snake_case__     :					Union[str, Any]    =  attention_dropout
    snake_case__     :					str    =  gelu_activation
    snake_case__     :					List[str]    =  sinusoidal_embeddings
    snake_case__     :					Optional[Any]    =  causal
    snake_case__     :					int    =  asm
    snake_case__     :					List[str]    =  n_langs
    snake_case__     :					Any    =  use_lang_emb
    snake_case__     :					List[str]    =  layer_norm_eps
    snake_case__     :					Optional[Any]    =  bos_index
    snake_case__     :					Optional[int]    =  eos_index
    snake_case__     :					str    =  pad_index
    snake_case__     :					Optional[Any]    =  unk_index
    snake_case__     :					Tuple    =  mask_index
    snake_case__     :					Tuple    =  is_encoder
    snake_case__     :					Any    =  max_position_embeddings
    snake_case__     :					Tuple    =  embed_init_std
    snake_case__     :					int    =  init_std
    snake_case__     :					List[str]    =  summary_type
    snake_case__     :					List[str]    =  summary_use_proj
    snake_case__     :					int    =  summary_activation
    snake_case__     :					Union[str, Any]    =  summary_proj_to_labels
    snake_case__     :					Tuple    =  summary_first_dropout
    snake_case__     :					List[Any]    =  start_n_top
    snake_case__     :					Tuple    =  end_n_top
    snake_case__     :					Union[str, Any]    =  mask_token_id
    snake_case__     :					Dict    =  lang_id

    if "n_words" in kwargs:
     snake_case__     :					str    =  kwargs["""n_words"""]

    super().__init__(pad_token_id=__SCREAMING_SNAKE_CASE	,		bos_token_id=__SCREAMING_SNAKE_CASE	,		**__SCREAMING_SNAKE_CASE       )



class 					__snake_case  (					__SCREAMING_SNAKE_CASE							):






   '''simple docstring'''





   @property
   def 		__UpperCamelCase						(							self       ):
    if self.task == "multiple-choice":
     snake_case__     :					Any    =  {0: """batch""", 1: """choice""", 2: """sequence"""}
    else:
     snake_case__     :					int    =  {0: """batch""", 1: """sequence"""}
    return OrderedDict(
        [
            ("""input_ids""", dynamic_axis),
            ("""attention_mask""", dynamic_axis),
            ("""token_type_ids""", dynamic_axis),
        ]       )












import datasets

from .evaluate import evaluate


snake_case__   :						int													=   """\
@article{hendrycks2021cuad,
      title={CUAD: An Expert-Annotated NLP Dataset for Legal Contract Review},
      author={Dan Hendrycks and Collin Burns and Anya Chen and Spencer Ball},
      journal={arXiv preprint arXiv:2103.06268},
      year={2021}
}
"""

snake_case__   :						Union[str, Any]													=   """
This metric wrap the official scoring script for version 1 of the Contract
Understanding Atticus Dataset (CUAD).
Contract Understanding Atticus Dataset (CUAD) v1 is a corpus of more than 13,000 labels in 510
commercial legal contracts that have been manually labeled to identify 41 categories of important
clauses that lawyers look for when reviewing contracts in connection with corporate transactions.
"""

snake_case__   :						Any													=   """
Computes CUAD scores (EM, F1, AUPR, Precision@80%Recall, and Precision@90%Recall).
Args:
    predictions: List of question-answers dictionaries with the following key-values:
        - 'id': id of the question-answer pair as given in the references (see below)
        - 'prediction_text': list of possible texts for the answer, as a list of strings
        depending on a threshold on the confidence probability of each prediction.
    references: List of question-answers dictionaries with the following key-values:
        - 'id': id of the question-answer pair (see above),
        - 'answers': a Dict in the CUAD dataset format
            {
                'text': list of possible texts for the answer, as a list of strings
                'answer_start': list of start positions for the answer, as a list of ints
            }
            Note that answer_start values are not taken into account to compute the metric.
Returns:
    'exact_match': Exact match (the normalized answer exactly match the gold answer)
    'f1': The F-score of predicted tokens versus the gold answer
    'aupr': Area Under the Precision-Recall curve
    'prec_at_80_recall': Precision at 80% recall
    'prec_at_90_recall': Precision at 90% recall
Examples:
    >>> predictions = [{'prediction_text': ['The seller:', 'The buyer/End-User: Shenzhen LOHAS Supply Chain Management Co., Ltd.'], 'id': 'LohaCompanyltd_20191209_F-1_EX-10.16_11917878_EX-10.16_Supply Agreement__Parties'}]
    >>> references = [{'answers': {'answer_start': [143, 49], 'text': ['The seller:', 'The buyer/End-User: Shenzhen LOHAS Supply Chain Management Co., Ltd.']}, 'id': 'LohaCompanyltd_20191209_F-1_EX-10.16_11917878_EX-10.16_Supply Agreement__Parties'}]
    >>> cuad_metric = datasets.load_metric(\"cuad\")
    >>> results = cuad_metric.compute(predictions=predictions, references=references)
    >>> print(results)
    {'exact_match': 100.0, 'f1': 100.0, 'aupr': 0.0, 'prec_at_80_recall': 1.0, 'prec_at_90_recall': 1.0}
"""


@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION    ,							_KWARGS_DESCRIPTION     )
class     _a							(	datasets.Metric     ):






  """simple docstring"""





  def  _UpperCAmelCase  (  self			)      ->			Optional[int]:
     return datasets.MetricInfo(
         description=_DESCRIPTION		,		citation=_CITATION		,		inputs_description=_KWARGS_DESCRIPTION		,		features=datasets.Features(
             {
                 'predictions': {
                     'id': datasets.Value('string'			),
                     'prediction_text': datasets.features.Sequence(datasets.Value('string'			)			),
                 },
                 'references': {
                     'id': datasets.Value('string'			),
                     'answers': datasets.features.Sequence(
                         {
                             'text': datasets.Value('string'			),
                             'answer_start': datasets.Value('int32'			),
                         }			),
                 },
             }			)		,		codebase_urls=['https://www.atticusprojectai.org/cuad']		,		reference_urls=['https://www.atticusprojectai.org/cuad']		,		)




  def  _UpperCAmelCase  (  self		,		_UpperCAmelCase		,		_UpperCAmelCase			)      ->			Dict:
     UpperCamelCase_						=  {prediction['id']: prediction['prediction_text'] for prediction in predictions}
     UpperCamelCase_						=  [
         {
             'paragraphs': [
                 {
                     'qas': [
                         {
                             'answers': [{'text': answer_text} for answer_text in ref['answers']['text']],
                             'id': ref['id'],
                         }
                         for ref in references
                     ]
                 }
             ]
         }
     ]
     UpperCamelCase_						=  evaluate(dataset=_UpperCAmelCase		,		predictions=_UpperCAmelCase			)
     return score





