






"""simple docstring"""
import datasets

from .evaluate import evaluate


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

lowerCamelCase_					=      '''\nThis metric wrap the official scoring script for version 1 of the Contract\nUnderstanding Atticus Dataset (CUAD).\nContract Understanding Atticus Dataset (CUAD) v1 is a corpus of more than 13,000 labels in 510\ncommercial legal contracts that have been manually labeled to identify 41 categories of important\nclauses that lawyers look for when reviewing contracts in connection with corporate transactions.\n'''

lowerCamelCase_					=      '''\nComputes CUAD scores (EM, F1, AUPR, Precision@80%Recall, and Precision@90%Recall).\nArgs:\n    predictions: List of question-answers dictionaries with the following key-values:\n        - \'id\': id of the question-answer pair as given in the references (see below)\n        - \'prediction_text\': list of possible texts for the answer, as a list of strings\n        depending on a threshold on the confidence probability of each prediction.\n    references: List of question-answers dictionaries with the following key-values:\n        - \'id\': id of the question-answer pair (see above),\n        - \'answers\': a Dict in the CUAD dataset format\n            {\n                \'text\': list of possible texts for the answer, as a list of strings\n                \'answer_start\': list of start positions for the answer, as a list of ints\n            }\n            Note that answer_start values are not taken into account to compute the metric.\nReturns:\n    \'exact_match\': Exact match (the normalized answer exactly match the gold answer)\n    \'f1\': The F-score of predicted tokens versus the gold answer\n    \'aupr\': Area Under the Precision-Recall curve\n    \'prec_at_80_recall\': Precision at 80% recall\n    \'prec_at_90_recall\': Precision at 90% recall\nExamples:\n    >>> 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\'}]\n    >>> 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\'}]\n    >>> cuad_metric = datasets.load_metric(\"cuad\")\n    >>> results = cuad_metric.compute(predictions=predictions, references=references)\n    >>> print(results)\n    {\'exact_match\': 100.0, \'f1\': 100.0, \'aupr\': 0.0, \'prec_at_80_recall\': 1.0, \'prec_at_90_recall\': 1.0}\n'''







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





	def      _SCREAMING_SNAKE_CASE      (      self					: str						)						->			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      _SCREAMING_SNAKE_CASE      (      self					: List[Any]	,	lowerCAmelCase_					: str	,	lowerCAmelCase_					: Tuple						)						->			Dict:
				UpperCAmelCase_     : Optional[Any]			     =					{prediction["id"]: prediction["prediction_text"] for prediction in predictions}
				UpperCAmelCase_     : Optional[Any]			     =					[
				    {
				        "paragraphs": [
				            {
				                "qas": [
				                    {
				                        "answers": [{"text": answer_text} for answer_text in ref["answers"]["text"]],
				                        "id": ref["id"],
				                    }
				                    for ref in references
				                ]
				            }
				        ]
				    }
				]
				UpperCAmelCase_     : int			     =					evaluate(dataset=__a	,	predictions=__a						)
				return score








import functools
import operator

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


_snake_case		=  logging.get_logger(__name__)

_snake_case		=  {
    "facebook/wav2vec2-base-960h": "https://huggingface.co/facebook/wav2vec2-base-960h/resolve/main/config.json",
    # See all Wav2Vec2 models at https://huggingface.co/models?filter=wav2vec2
}



class   UpperCAmelCase_    (       a):
							lowerCamelCase__   			=		'wav2vec2'







							def __init__(   self,			__a=32,			__a=768,			__a=12,			__a=12,			__a=3072,			__a="gelu",			__a=0.1,			__a=0.1,			__a=0.1,			__a=0.0,			__a=0.0,			__a=0.1,			__a=0.1,			__a=0.02,			__a=1E-5,			__a="group",			__a="gelu",			__a=(512, 512, 512, 512, 512, 512, 512),			__a=(5, 2, 2, 2, 2, 2, 2),			__a=(10, 3, 3, 3, 3, 2, 2),			__a=False,			__a=128,			__a=16,			__a=False,			__a=True,			__a=0.05,			__a=10,			__a=2,			__a=0.0,			__a=10,			__a=0,			__a=320,			__a=2,			__a=0.1,			__a=100,			__a=256,			__a=256,			__a=0.1,			__a="sum",			__a=False,			__a=False,			__a=256,			__a=(512, 512, 512, 512, 1500),			__a=(5, 3, 3, 1, 1),			__a=(1, 2, 3, 1, 1),			__a=512,			__a=0,			__a=1,			__a=2,			__a=False,			__a=3,			__a=2,			__a=3,			__a=None,			__a=None,			**__a,			):

														'''simple docstring'''

														super().__init__(**__a,			pad_token_id=__a,			bos_token_id=__a,			eos_token_id=__a)
														_lowerCAmelCase     :							str    =    hidden_size
														_lowerCAmelCase     :							Optional[int]    =    feat_extract_norm
														_lowerCAmelCase     :							Union[str, Any]    =    feat_extract_activation
														_lowerCAmelCase     :							Optional[Any]    =    list(__a)
														_lowerCAmelCase     :							List[str]    =    list(__a)
														_lowerCAmelCase     :							str    =    list(__a)
														_lowerCAmelCase     :							List[str]    =    conv_bias
														_lowerCAmelCase     :							str    =    num_conv_pos_embeddings
														_lowerCAmelCase     :							List[Any]    =    num_conv_pos_embedding_groups
														_lowerCAmelCase     :							str    =    len(self.conv_dim)
														_lowerCAmelCase     :							List[str]    =    num_hidden_layers
														_lowerCAmelCase     :							str    =    intermediate_size
														_lowerCAmelCase     :							Any    =    hidden_act
														_lowerCAmelCase     :							int    =    num_attention_heads
														_lowerCAmelCase     :							Optional[Any]    =    hidden_dropout
														_lowerCAmelCase     :							List[str]    =    attention_dropout
														_lowerCAmelCase     :							Tuple    =    activation_dropout
														_lowerCAmelCase     :							int    =    feat_proj_dropout
														_lowerCAmelCase     :							List[str]    =    final_dropout
														_lowerCAmelCase     :							int    =    layerdrop
														_lowerCAmelCase     :							int    =    layer_norm_eps
														_lowerCAmelCase     :							Union[str, Any]    =    initializer_range
														_lowerCAmelCase     :							str    =    vocab_size
														_lowerCAmelCase     :							Optional[Any]    =    do_stable_layer_norm
														_lowerCAmelCase     :							Any    =    use_weighted_layer_sum

														if (
														    (len(self.conv_stride) != self.num_feat_extract_layers)
														    or (len(self.conv_kernel) != self.num_feat_extract_layers)
														    or (len(self.conv_dim) != self.num_feat_extract_layers)
														):
																					raise ValueError(
																					    "Configuration for convolutional layers is incorrect. It is required that `len(config.conv_dim)` =="
																					    " `len(config.conv_stride)` == `len(config.conv_kernel)`, but is `len(config.conv_dim) ="
																					    f" {len(self.conv_dim)}`, `len(config.conv_stride) = {len(self.conv_stride)}`,"
																					    f" `len(config.conv_kernel) = {len(self.conv_kernel)}`.")

														# fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
														_lowerCAmelCase     :							str    =    apply_spec_augment
														_lowerCAmelCase     :							Optional[Any]    =    mask_time_prob
														_lowerCAmelCase     :							Optional[int]    =    mask_time_length
														_lowerCAmelCase     :							List[str]    =    mask_time_min_masks
														_lowerCAmelCase     :							Optional[int]    =    mask_feature_prob
														_lowerCAmelCase     :							Optional[int]    =    mask_feature_length
														_lowerCAmelCase     :							List[str]    =    mask_feature_min_masks

														# parameters for pretraining with codevector quantized representations
														_lowerCAmelCase     :							Union[str, Any]    =    num_codevectors_per_group
														_lowerCAmelCase     :							str    =    num_codevector_groups
														_lowerCAmelCase     :							Optional[int]    =    contrastive_logits_temperature
														_lowerCAmelCase     :							Optional[int]    =    feat_quantizer_dropout
														_lowerCAmelCase     :							Optional[int]    =    num_negatives
														_lowerCAmelCase     :							Union[str, Any]    =    codevector_dim
														_lowerCAmelCase     :							Any    =    proj_codevector_dim
														_lowerCAmelCase     :							Optional[int]    =    diversity_loss_weight

														# ctc loss
														_lowerCAmelCase     :							Tuple    =    ctc_loss_reduction
														_lowerCAmelCase     :							Tuple    =    ctc_zero_infinity

														# adapter
														_lowerCAmelCase     :							List[Any]    =    add_adapter
														_lowerCAmelCase     :							List[str]    =    adapter_kernel_size
														_lowerCAmelCase     :							str    =    adapter_stride
														_lowerCAmelCase     :							List[str]    =    num_adapter_layers
														_lowerCAmelCase     :							str    =    output_hidden_size or hidden_size
														_lowerCAmelCase     :							Tuple    =    adapter_attn_dim

														# SequenceClassification-specific parameter. Feel free to ignore for other classes.
														_lowerCAmelCase     :							str    =    classifier_proj_size

														# XVector-specific parameters. Feel free to ignore for other classes.
														_lowerCAmelCase     :							str    =    list(__a)
														_lowerCAmelCase     :							Union[str, Any]    =    list(__a)
														_lowerCAmelCase     :							List[str]    =    list(__a)
														_lowerCAmelCase     :							Tuple    =    xvector_output_dim







							@property
							def    snake_case__      (   self):

														'''simple docstring'''

														return functools.reduce(operator.mul,			self.conv_stride,			1)
