






import functools
import operator

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


__lowerCamelCase	:		Tuple										=   logging.get_logger(__name__)

__lowerCamelCase	:		Optional[int]										=   {
    """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  _lowercase   (   _A						):
      _a							:						int										=							'wav2vec2'
      def __init__(     self				,			a=3_2				,			a=7_6_8				,			a=1_2				,			a=1_2				,			a=3_0_7_2				,			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=(5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2)				,			a=(5, 2, 2, 2, 2, 2, 2)				,			a=(1_0, 3, 3, 3, 3, 2, 2)				,			a=False				,			a=1_2_8				,			a=1_6				,			a=False				,			a=True				,			a=0.05				,			a=1_0				,			a=2				,			a=0.0				,			a=1_0				,			a=0				,			a=3_2_0				,			a=2				,			a=0.1				,			a=1_0_0				,			a=2_5_6				,			a=2_5_6				,			a=0.1				,			a="sum"				,			a=False				,			a=False				,			a=2_5_6				,			a=(5_1_2, 5_1_2, 5_1_2, 5_1_2, 1_5_0_0)				,			a=(5, 3, 3, 1, 1)				,			a=(1, 2, 3, 1, 1)				,			a=5_1_2				,			a=0				,			a=1				,			a=2				,			a=False				,			a=3				,			a=2				,			a=3				,			a=None				,			a=None				,			**a				,			):
       super().__init__(**a				,			pad_token_id=a				,			bos_token_id=a				,			eos_token_id=a   )
       snake_case__  :    str							       =hidden_size
       snake_case__  :    int							       =feat_extract_norm
       snake_case__  :    List[str]							       =feat_extract_activation
       snake_case__  :    int							       =list(a   )
       snake_case__  :    Tuple							       =list(a   )
       snake_case__  :    Any							       =list(a   )
       snake_case__  :    Dict							       =conv_bias
       snake_case__  :    List[Any]							       =num_conv_pos_embeddings
       snake_case__  :    int							       =num_conv_pos_embedding_groups
       snake_case__  :    Union[str, Any]							       =len(self.conv_dim   )
       snake_case__  :    Optional[Any]							       =num_hidden_layers
       snake_case__  :    Tuple							       =intermediate_size
       snake_case__  :    List[str]							       =hidden_act
       snake_case__  :    Optional[int]							       =num_attention_heads
       snake_case__  :    Tuple							       =hidden_dropout
       snake_case__  :    str							       =attention_dropout
       snake_case__  :    Tuple							       =activation_dropout
       snake_case__  :    Optional[Any]							       =feat_proj_dropout
       snake_case__  :    List[Any]							       =final_dropout
       snake_case__  :    Dict							       =layerdrop
       snake_case__  :    Any							       =layer_norm_eps
       snake_case__  :    Optional[Any]							       =initializer_range
       snake_case__  :    Dict							       =vocab_size
       snake_case__  :    Optional[Any]							       =do_stable_layer_norm
       snake_case__  :    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
       snake_case__  :    Dict							       =apply_spec_augment
       snake_case__  :    Optional[Any]							       =mask_time_prob
       snake_case__  :    Dict							       =mask_time_length
       snake_case__  :    str							       =mask_time_min_masks
       snake_case__  :    int							       =mask_feature_prob
       snake_case__  :    List[str]							       =mask_feature_length
       snake_case__  :    Union[str, Any]							       =mask_feature_min_masks

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

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

       # adapter
       snake_case__  :    Any							       =add_adapter
       snake_case__  :    int							       =adapter_kernel_size
       snake_case__  :    Any							       =adapter_stride
       snake_case__  :    Tuple							       =num_adapter_layers
       snake_case__  :    Tuple							       =output_hidden_size or hidden_size
       snake_case__  :    str							       =adapter_attn_dim

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

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



      @property
      def 						lowercase__					(     self   ):
       return functools.reduce(operator.mul				,			self.conv_stride				,			1   )













from scipy.stats import pearsonr, spearmanr
from sklearn.metrics import fa_score, matthews_corrcoef

import datasets


__lowerCamelCase	:		Any										=   """\
@inproceedings{wang2019glue,
  title={{GLUE}: A Multi-Task Benchmark and Analysis Platform for Natural Language Understanding},
  author={Wang, Alex and Singh, Amanpreet and Michael, Julian and Hill, Felix and Levy, Omer and Bowman, Samuel R.},
  note={In the Proceedings of ICLR.},
  year={2019}
}
"""

__lowerCamelCase	:		str										=   """\
GLUE, the General Language Understanding Evaluation benchmark
(https://gluebenchmark.com/) is a collection of resources for training,
evaluating, and analyzing natural language understanding systems.
"""

__lowerCamelCase	:		str										=   """
Compute GLUE evaluation metric associated to each GLUE dataset.
Args:
    predictions: list of predictions to score.
        Each translation should be tokenized into a list of tokens.
    references: list of lists of references for each translation.
        Each reference should be tokenized into a list of tokens.
Returns: depending on the GLUE subset, one or several of:
    \"accuracy\": Accuracy
    \"f1\": F1 score
    \"pearson\": Pearson Correlation
    \"spearmanr\": Spearman Correlation
    \"matthews_correlation\": Matthew Correlation
Examples:

    >>> glue_metric = datasets.load_metric('glue', 'sst2')  # 'sst2' or any of [\"mnli\", \"mnli_mismatched\", \"mnli_matched\", \"qnli\", \"rte\", \"wnli\", \"hans\"]
    >>> references = [0, 1]
    >>> predictions = [0, 1]
    >>> results = glue_metric.compute(predictions=predictions, references=references)
    >>> print(results)
    {'accuracy': 1.0}

    >>> glue_metric = datasets.load_metric('glue', 'mrpc')  # 'mrpc' or 'qqp'
    >>> references = [0, 1]
    >>> predictions = [0, 1]
    >>> results = glue_metric.compute(predictions=predictions, references=references)
    >>> print(results)
    {'accuracy': 1.0, 'f1': 1.0}

    >>> glue_metric = datasets.load_metric('glue', 'stsb')
    >>> references = [0., 1., 2., 3., 4., 5.]
    >>> predictions = [0., 1., 2., 3., 4., 5.]
    >>> results = glue_metric.compute(predictions=predictions, references=references)
    >>> print({\"pearson\": round(results[\"pearson\"], 2), \"spearmanr\": round(results[\"spearmanr\"], 2)})
    {'pearson': 1.0, 'spearmanr': 1.0}

    >>> glue_metric = datasets.load_metric('glue', 'cola')
    >>> references = [0, 1]
    >>> predictions = [0, 1]
    >>> results = glue_metric.compute(predictions=predictions, references=references)
    >>> print(results)
    {'matthews_correlation': 1.0}
"""







def 			A__							(      _a  :					int		,  _a  :					str	):





 '''simple docstring'''







 return float((preds == labels).mean()	)







def 			A__							(      _a  :					Optional[Any]		,  _a  :					Any	):





 '''simple docstring'''







 snake_case__  :    str							       =simple_accuracy(_a		,  _a	)
 snake_case__  :    str							       =float(fa_score(y_true=_a		,  y_pred=_a	)	)
 return {
     "accuracy": acc,
     "f1": fa,
 }







def 			A__							(      _a  :					int		,  _a  :					Optional[int]	):





 '''simple docstring'''







 snake_case__  :    str							       =float(pearsonr(_a		,  _a	)[0]	)
 snake_case__  :    Optional[int]							       =float(spearmanr(_a		,  _a	)[0]	)
 return {
     "pearson": pearson_corr,
     "spearmanr": spearman_corr,
 }







@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION						,				_KWARGS_DESCRIPTION						)
class  _lowercase   (   datasets.Metric						):
      def 						lowercase__					(     self   ):
       if self.config_name not in [
           "sst2",
           "mnli",
           "mnli_mismatched",
           "mnli_matched",
           "cola",
           "stsb",
           "mrpc",
           "qqp",
           "qnli",
           "rte",
           "wnli",
           "hans",
       ]:
        raise KeyError(
            """You should supply a configuration name selected in """
            """[\"sst2\", \"mnli\", \"mnli_mismatched\", \"mnli_matched\", """
            """\"cola\", \"stsb\", \"mrpc\", \"qqp\", \"qnli\", \"rte\", \"wnli\", \"hans\"]"""   )
       return datasets.MetricInfo(
           description=_DESCRIPTION				,			citation=_CITATION				,			inputs_description=_KWARGS_DESCRIPTION				,			features=datasets.Features(
               {
                   """predictions""": datasets.Value("""int64""" if self.config_name != """stsb""" else """float32"""   ),
                   """references""": datasets.Value("""int64""" if self.config_name != """stsb""" else """float32"""   ),
               }   )				,			codebase_urls=[]				,			reference_urls=[]				,			format="""numpy"""				,			)



      def 						lowercase__					(     self				,			a				,			a   ):
       if self.config_name == "cola":
        return {"matthews_correlation": matthews_corrcoef(a				,			a   )}
       elif self.config_name == "stsb":
        return pearson_and_spearman(a				,			a   )
       elif self.config_name in ["mrpc", "qqp"]:
        return acc_and_fa(a				,			a   )
       elif self.config_name in ["sst2", "mnli", "mnli_mismatched", "mnli_matched", "qnli", "rte", "wnli", "hans"]:
        return {"accuracy": simple_accuracy(a				,			a   )}
       else:
        raise KeyError(
            """You should supply a configuration name selected in """
            """[\"sst2\", \"mnli\", \"mnli_mismatched\", \"mnli_matched\", """
            """\"cola\", \"stsb\", \"mrpc\", \"qqp\", \"qnli\", \"rte\", \"wnli\", \"hans\"]"""   )





