import datasets

from .evaluate import evaluate


__a  :     List[Any]       =  """\
@inproceedings{Rajpurkar2016SQuAD10,
  title={SQuAD: 100, 000+ Questions for Machine Comprehension of Text},
  author={Pranav Rajpurkar and Jian Zhang and Konstantin Lopyrev and Percy Liang},
  booktitle={EMNLP},
  year={2016}
}
"""

__a  :     List[Any]       =  """
This metric wrap the official scoring script for version 1 of the Stanford Question Answering Dataset (SQuAD).

Stanford Question Answering Dataset (SQuAD) is a reading comprehension dataset, consisting of questions posed by
crowdworkers on a set of Wikipedia articles, where the answer to every question is a segment of text, or span,
from the corresponding reading passage, or the question might be unanswerable.
"""

__a  :     Tuple       =  """
Computes SQuAD scores (F1 and EM).
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': the text of the answer
    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 SQuAD 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
Examples:

    >>> predictions = [{'prediction_text': '1976', 'id': '56e10a3be3433e1400422b22'}]
    >>> references = [{'answers': {'answer_start': [97], 'text': ['1976']}, 'id': '56e10a3be3433e1400422b22'}]
    >>> squad_metric = datasets.load_metric(\"squad\")
    >>> results = squad_metric.compute(predictions=predictions, references=references)
    >>> print(results)
    {'exact_match': 100.0, 'f1': 100.0}
"""




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


			"""simple docstring"""






			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					Optional[Any]:

							'''simple docstring'''


							return datasets.MetricInfo(
							    description=_DESCRIPTION      ,   citation=_CITATION      ,   inputs_description=_KWARGS_DESCRIPTION      ,   features=datasets.Features(
							        {
							            '''predictions''': {'''id''': datasets.Value('''string'''						), '''prediction_text''': datasets.Value('''string'''						)},
							            '''references''': {
							                '''id''': datasets.Value('''string'''						),
							                '''answers''': datasets.features.Sequence(
							                    {
							                        '''text''': datasets.Value('''string'''						),
							                        '''answer_start''': datasets.Value('''int32'''						),
							                    }						),
							            },
							        }						)      ,   codebase_urls=['''https://rajpurkar.github.io/SQuAD-explorer/''']      ,   reference_urls=['''https://rajpurkar.github.io/SQuAD-explorer/''']      ,   )





			def        _SCREAMING_SNAKE_CASE			(   self      ,   lowerCAmelCase__      ,   lowerCAmelCase__						)     ->					int:

							'''simple docstring'''


							__lowercase 			=							{prediction['''id''']: prediction['''prediction_text'''] for prediction in predictions}
							__lowercase 			=							[
							    {
							        '''paragraphs''': [
							            {
							                '''qas''': [
							                    {
							                        '''answers''': [{'''text''': answer_text} for answer_text in ref['''answers''']['''text''']],
							                        '''id''': ref['''id'''],
							                    }
							                    for ref in references
							                ]
							            }
							        ]
							    }
							]
							__lowercase 			=							evaluate(dataset=lowerCAmelCase__      ,   predictions=lowerCAmelCase__						)
							return score
import functools
import operator

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


__a  :     str       =  logging.get_logger(__name__)

__a  :     int       =  {
    """microsoft/wavlm-base""": """https://huggingface.co/microsoft/wavlm-base/resolve/main/config.json""",
    # See all WavLM models at https://huggingface.co/models?filter=wavlm
}




class    _UpperCamelCase      (						_UpperCAmelCase ):


			"""simple docstring"""






			__a  : Any			 =						'''wavlm'''





			def __init__(   self      ,   lowerCAmelCase__=32      ,   lowerCAmelCase__=7_68      ,   lowerCAmelCase__=12      ,   lowerCAmelCase__=12      ,   lowerCAmelCase__=30_72      ,   lowerCAmelCase__="gelu"      ,   lowerCAmelCase__=0.1      ,   lowerCAmelCase__=0.1      ,   lowerCAmelCase__=0.1      ,   lowerCAmelCase__=0.0      ,   lowerCAmelCase__=0.1      ,   lowerCAmelCase__=0.1      ,   lowerCAmelCase__=0.02      ,   lowerCAmelCase__=1E-5      ,   lowerCAmelCase__="group"      ,   lowerCAmelCase__="gelu"      ,   lowerCAmelCase__=(5_12, 5_12, 5_12, 5_12, 5_12, 5_12, 5_12)      ,   lowerCAmelCase__=(5, 2, 2, 2, 2, 2, 2)      ,   lowerCAmelCase__=(10, 3, 3, 3, 3, 2, 2)      ,   lowerCAmelCase__=False      ,   lowerCAmelCase__=1_28      ,   lowerCAmelCase__=16      ,   lowerCAmelCase__=3_20      ,   lowerCAmelCase__=8_00      ,   lowerCAmelCase__=False      ,   lowerCAmelCase__=True      ,   lowerCAmelCase__=0.05      ,   lowerCAmelCase__=10      ,   lowerCAmelCase__=2      ,   lowerCAmelCase__=0.0      ,   lowerCAmelCase__=10      ,   lowerCAmelCase__=3_20      ,   lowerCAmelCase__=2      ,   lowerCAmelCase__=0.1      ,   lowerCAmelCase__=1_00      ,   lowerCAmelCase__=2_56      ,   lowerCAmelCase__=2_56      ,   lowerCAmelCase__=0.1      ,   lowerCAmelCase__="mean"      ,   lowerCAmelCase__=False      ,   lowerCAmelCase__=False      ,   lowerCAmelCase__=2_56      ,   lowerCAmelCase__=(5_12, 5_12, 5_12, 5_12, 15_00)      ,   lowerCAmelCase__=(5, 3, 3, 1, 1)      ,   lowerCAmelCase__=(1, 2, 3, 1, 1)      ,   lowerCAmelCase__=5_12      ,   lowerCAmelCase__=80      ,   lowerCAmelCase__=0      ,   lowerCAmelCase__=1      ,   lowerCAmelCase__=2      ,   lowerCAmelCase__=False      ,   lowerCAmelCase__=3      ,   lowerCAmelCase__=2      ,   lowerCAmelCase__=3      ,   lowerCAmelCase__=None      ,   **lowerCAmelCase__      ,   )     ->					Tuple:

							'''simple docstring'''


							super().__init__(**lowerCAmelCase__      ,   pad_token_id=lowerCAmelCase__      ,   bos_token_id=lowerCAmelCase__      ,   eos_token_id=lowerCAmelCase__						)
							__lowercase 			=							hidden_size
							__lowercase 			=							feat_extract_norm
							__lowercase 			=							feat_extract_activation
							__lowercase 			=							list(lowerCAmelCase__						)
							__lowercase 			=							list(lowerCAmelCase__						)
							__lowercase 			=							list(lowerCAmelCase__						)
							__lowercase 			=							conv_bias
							__lowercase 			=							num_buckets
							__lowercase 			=							max_bucket_distance
							__lowercase 			=							num_conv_pos_embeddings
							__lowercase 			=							num_conv_pos_embedding_groups
							__lowercase 			=							len(self.conv_dim						)
							__lowercase 			=							num_hidden_layers
							__lowercase 			=							intermediate_size
							__lowercase 			=							hidden_act
							__lowercase 			=							num_attention_heads
							__lowercase 			=							hidden_dropout
							__lowercase 			=							attention_dropout
							__lowercase 			=							activation_dropout
							__lowercase 			=							feat_proj_dropout
							__lowercase 			=							final_dropout
							__lowercase 			=							layerdrop
							__lowercase 			=							layer_norm_eps
							__lowercase 			=							initializer_range
							__lowercase 			=							num_ctc_classes
							__lowercase 			=							vocab_size
							__lowercase 			=							do_stable_layer_norm
							__lowercase 			=							use_weighted_layer_sum
							__lowercase 			=							classifier_proj_size

							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
							__lowercase 			=							apply_spec_augment
							__lowercase 			=							mask_time_prob
							__lowercase 			=							mask_time_length
							__lowercase 			=							mask_time_min_masks
							__lowercase 			=							mask_feature_prob
							__lowercase 			=							mask_feature_length

							# parameters for pretraining with codevector quantized representations
							__lowercase 			=							num_codevectors_per_group
							__lowercase 			=							num_codevector_groups
							__lowercase 			=							contrastive_logits_temperature
							__lowercase 			=							num_negatives
							__lowercase 			=							codevector_dim
							__lowercase 			=							proj_codevector_dim
							__lowercase 			=							diversity_loss_weight

							# ctc loss
							__lowercase 			=							ctc_loss_reduction
							__lowercase 			=							ctc_zero_infinity

							# adapter
							__lowercase 			=							add_adapter
							__lowercase 			=							adapter_kernel_size
							__lowercase 			=							adapter_stride
							__lowercase 			=							num_adapter_layers
							__lowercase 			=							output_hidden_size or hidden_size

							# SequenceClassification-specific parameter. Feel free to ignore for other classes.
							__lowercase 			=							classifier_proj_size

							# XVector-specific parameters. Feel free to ignore for other classes.
							__lowercase 			=							list(lowerCAmelCase__						)
							__lowercase 			=							list(lowerCAmelCase__						)
							__lowercase 			=							list(lowerCAmelCase__						)
							__lowercase 			=							xvector_output_dim





			@property
			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					int:

							'''simple docstring'''


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