






"""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       __A		(   datasets.Metric			):

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









import functools
import operator

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


__a							     =					logging.get_logger(__name__)

__a							     =					{
    '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     __a(	_a  ):






    """simple docstring"""





    lowerCAmelCase         = '''wav2vec2'''





    def __init__( self  ,_SCREAMING_SNAKE_CASE=32  ,_SCREAMING_SNAKE_CASE=768  ,_SCREAMING_SNAKE_CASE=12  ,_SCREAMING_SNAKE_CASE=12  ,_SCREAMING_SNAKE_CASE=3_072  ,_SCREAMING_SNAKE_CASE="gelu"  ,_SCREAMING_SNAKE_CASE=0.1  ,_SCREAMING_SNAKE_CASE=0.1  ,_SCREAMING_SNAKE_CASE=0.1  ,_SCREAMING_SNAKE_CASE=0.0  ,_SCREAMING_SNAKE_CASE=0.0  ,_SCREAMING_SNAKE_CASE=0.1  ,_SCREAMING_SNAKE_CASE=0.1  ,_SCREAMING_SNAKE_CASE=0.02  ,_SCREAMING_SNAKE_CASE=1e-5  ,_SCREAMING_SNAKE_CASE="group"  ,_SCREAMING_SNAKE_CASE="gelu"  ,_SCREAMING_SNAKE_CASE=(512, 512, 512, 512, 512, 512, 512)  ,_SCREAMING_SNAKE_CASE=(5, 2, 2, 2, 2, 2, 2)  ,_SCREAMING_SNAKE_CASE=(10, 3, 3, 3, 3, 2, 2)  ,_SCREAMING_SNAKE_CASE=False  ,_SCREAMING_SNAKE_CASE=128  ,_SCREAMING_SNAKE_CASE=16  ,_SCREAMING_SNAKE_CASE=False  ,_SCREAMING_SNAKE_CASE=True  ,_SCREAMING_SNAKE_CASE=0.05  ,_SCREAMING_SNAKE_CASE=10  ,_SCREAMING_SNAKE_CASE=2  ,_SCREAMING_SNAKE_CASE=0.0  ,_SCREAMING_SNAKE_CASE=10  ,_SCREAMING_SNAKE_CASE=0  ,_SCREAMING_SNAKE_CASE=320  ,_SCREAMING_SNAKE_CASE=2  ,_SCREAMING_SNAKE_CASE=0.1  ,_SCREAMING_SNAKE_CASE=100  ,_SCREAMING_SNAKE_CASE=256  ,_SCREAMING_SNAKE_CASE=256  ,_SCREAMING_SNAKE_CASE=0.1  ,_SCREAMING_SNAKE_CASE="sum"  ,_SCREAMING_SNAKE_CASE=False  ,_SCREAMING_SNAKE_CASE=False  ,_SCREAMING_SNAKE_CASE=256  ,_SCREAMING_SNAKE_CASE=(512, 512, 512, 512, 1_500)  ,_SCREAMING_SNAKE_CASE=(5, 3, 3, 1, 1)  ,_SCREAMING_SNAKE_CASE=(1, 2, 3, 1, 1)  ,_SCREAMING_SNAKE_CASE=512  ,_SCREAMING_SNAKE_CASE=0  ,_SCREAMING_SNAKE_CASE=1  ,_SCREAMING_SNAKE_CASE=2  ,_SCREAMING_SNAKE_CASE=False  ,_SCREAMING_SNAKE_CASE=3  ,_SCREAMING_SNAKE_CASE=2  ,_SCREAMING_SNAKE_CASE=3  ,_SCREAMING_SNAKE_CASE=None  ,_SCREAMING_SNAKE_CASE=None  ,**_SCREAMING_SNAKE_CASE  ,)					->						Optional[int]:
         super().__init__(**_SCREAMING_SNAKE_CASE  ,pad_token_id=_SCREAMING_SNAKE_CASE  ,bos_token_id=_SCREAMING_SNAKE_CASE  ,eos_token_id=_SCREAMING_SNAKE_CASE    )
         UpperCAmelCase_     :				int  =     hidden_size
         UpperCAmelCase_     :				Tuple  =     feat_extract_norm
         UpperCAmelCase_     :				List[Any]  =     feat_extract_activation
         UpperCAmelCase_     :				str  =     list(_SCREAMING_SNAKE_CASE    )
         UpperCAmelCase_     :				Any  =     list(_SCREAMING_SNAKE_CASE    )
         UpperCAmelCase_     :				Tuple  =     list(_SCREAMING_SNAKE_CASE    )
         UpperCAmelCase_     :				Dict  =     conv_bias
         UpperCAmelCase_     :				str  =     num_conv_pos_embeddings
         UpperCAmelCase_     :				Any  =     num_conv_pos_embedding_groups
         UpperCAmelCase_     :				Tuple  =     len(self.conv_dim    )
         UpperCAmelCase_     :				Union[str, Any]  =     num_hidden_layers
         UpperCAmelCase_     :				Dict  =     intermediate_size
         UpperCAmelCase_     :				Any  =     hidden_act
         UpperCAmelCase_     :				Any  =     num_attention_heads
         UpperCAmelCase_     :				str  =     hidden_dropout
         UpperCAmelCase_     :				int  =     attention_dropout
         UpperCAmelCase_     :				Tuple  =     activation_dropout
         UpperCAmelCase_     :				List[str]  =     feat_proj_dropout
         UpperCAmelCase_     :				int  =     final_dropout
         UpperCAmelCase_     :				Union[str, Any]  =     layerdrop
         UpperCAmelCase_     :				Optional[Any]  =     layer_norm_eps
         UpperCAmelCase_     :				str  =     initializer_range
         UpperCAmelCase_     :				List[str]  =     vocab_size
         UpperCAmelCase_     :				Optional[int]  =     do_stable_layer_norm
         UpperCAmelCase_     :				Optional[int]  =     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
         UpperCAmelCase_     :				Optional[int]  =     apply_spec_augment
         UpperCAmelCase_     :				Tuple  =     mask_time_prob
         UpperCAmelCase_     :				Optional[Any]  =     mask_time_length
         UpperCAmelCase_     :				Union[str, Any]  =     mask_time_min_masks
         UpperCAmelCase_     :				Optional[Any]  =     mask_feature_prob
         UpperCAmelCase_     :				str  =     mask_feature_length
         UpperCAmelCase_     :				Dict  =     mask_feature_min_masks

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

         # ctc loss
         UpperCAmelCase_     :				List[Any]  =     ctc_loss_reduction
         UpperCAmelCase_     :				List[str]  =     ctc_zero_infinity

         # adapter
         UpperCAmelCase_     :				Optional[Any]  =     add_adapter
         UpperCAmelCase_     :				Any  =     adapter_kernel_size
         UpperCAmelCase_     :				Optional[int]  =     adapter_stride
         UpperCAmelCase_     :				List[Any]  =     num_adapter_layers
         UpperCAmelCase_     :				Optional[Any]  =     output_hidden_size or hidden_size
         UpperCAmelCase_     :				Optional[int]  =     adapter_attn_dim

         # SequenceClassification-specific parameter. Feel free to ignore for other classes.
         UpperCAmelCase_     :				List[str]  =     classifier_proj_size

         # XVector-specific parameters. Feel free to ignore for other classes.
         UpperCAmelCase_     :				List[str]  =     list(_SCREAMING_SNAKE_CASE    )
         UpperCAmelCase_     :				int  =     list(_SCREAMING_SNAKE_CASE    )
         UpperCAmelCase_     :				Dict  =     list(_SCREAMING_SNAKE_CASE    )
         UpperCAmelCase_     :				Any  =     xvector_output_dim





    @property
    def 				a__ ( self    )					->						Any:
         return functools.reduce(operator.mul  ,self.conv_stride  ,1    )