import numpy as np
from scipy.spatial.distance import cdist
from sklearn.metrics import fa_score

import datasets


lowerCAmelCase__     						=			'\\n    @inproceedings{kakwani2020indicnlpsuite,\n    title={{IndicNLPSuite: Monolingual Corpora, Evaluation Benchmarks and Pre-trained Multilingual Language Models for Indian Languages}},\n    author={Divyanshu Kakwani and Anoop Kunchukuttan and Satish Golla and Gokul N.C. and Avik Bhattacharyya and Mitesh M. Khapra and Pratyush Kumar},\n    year={2020},\n    booktitle={Findings of EMNLP},\n}\n'

lowerCAmelCase__     						=			'\\n    IndicGLUE is a natural language understanding benchmark for Indian languages. It contains a wide\n    variety of tasks and covers 11 major Indian languages - as, bn, gu, hi, kn, ml, mr, or, pa, ta, te.\n'

lowerCAmelCase__     						=			'\nCompute IndicGLUE evaluation metric associated to each IndicGLUE dataset.\nArgs:\n    predictions: list of predictions to score (as int64),\n        except for \'cvit-mkb-clsr\' where each prediction is a vector (of float32).\n    references: list of ground truth labels corresponding to the predictions (as int64),\n        except for \'cvit-mkb-clsr\' where each reference is a vector (of float32).\nReturns: depending on the IndicGLUE subset, one or several of:\n    \"accuracy\": Accuracy\n    \"f1\": F1 score\n    \"precision\": Precision@10\nExamples:\n\n    >>> indic_glue_metric = datasets.load_metric(\'indic_glue\', \'wnli\')  # \'wnli\' or any of [\"copa\", \"sna\", \"csqa\", \"wstp\", \"inltkh\", \"bbca\", \"iitp-mr\", \"iitp-pr\", \"actsa-sc\", \"md\"]\n    >>> references = [0, 1]\n    >>> predictions = [0, 1]\n    >>> results = indic_glue_metric.compute(predictions=predictions, references=references)\n    >>> print(results)\n    {\'accuracy\': 1.0}\n\n    >>> indic_glue_metric = datasets.load_metric(\'indic_glue\', \'wiki-ner\')\n    >>> references = [0, 1]\n    >>> predictions = [0, 1]\n    >>> results = indic_glue_metric.compute(predictions=predictions, references=references)\n    >>> print(results)\n    {\'accuracy\': 1.0, \'f1\': 1.0}\n\n    >>> indic_glue_metric = datasets.load_metric(\'indic_glue\', \'cvit-mkb-clsr\')\n    >>> references = [[0.5, 0.5, 0.5], [0.1, 0.2, 0.3]]\n    >>> predictions = [[0.5, 0.5, 0.5], [0.1, 0.2, 0.3]]\n    >>> results = indic_glue_metric.compute(predictions=predictions, references=references)\n    >>> print(results)\n    {\'precision@10\': 1.0}\n\n'






def 				__lowerCamelCase		(						lowerCAmelCase__     ,  lowerCAmelCase__     ):
       return float((preds == labels).mean()     )






def 				__lowerCamelCase		(						lowerCAmelCase__     ,  lowerCAmelCase__     ):
       lowerCAmelCase__					     = simple_accuracy(a__     ,  a__     )
       lowerCAmelCase__					     = float(fa_score(y_true=a__     ,  y_pred=a__     )     )
       return {
           "accuracy": acc,
           "f1": fa,
       }






def 				__lowerCamelCase		(						lowerCAmelCase__     ,  lowerCAmelCase__     ):
       lowerCAmelCase__					     = np.array(a__     )
       lowerCAmelCase__					     = np.array(a__     )
       lowerCAmelCase__					     = en_sentvecs.shape[0]

       # mean centering
       lowerCAmelCase__					     = en_sentvecs - np.mean(a__     ,  axis=0     )
       lowerCAmelCase__					     = in_sentvecs - np.mean(a__     ,  axis=0     )

       lowerCAmelCase__					     = cdist(a__     ,  a__     ,  'cosine'     )
       lowerCAmelCase__					     = np.array(range(a__     )     )
       lowerCAmelCase__					     = sim.argsort(axis=1     )[:, :1_0]
       lowerCAmelCase__					     = np.any(preds == actual[:, None]     ,  axis=1     )
       return float(matches.mean()     )



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






 '''simple docstring'''






 def 		__snake_case						(      self :  Union[str, Any]):







        '''simple docstring'''



        if self.config_name not in [
            "wnli",
            "copa",
            "sna",
            "csqa",
            "wstp",
            "inltkh",
            "bbca",
            "cvit-mkb-clsr",
            "iitp-mr",
            "iitp-pr",
            "actsa-sc",
            "md",
            "wiki-ner",
        ]:
               raise KeyError(
                   'You should supply a configuration name selected in '
                   '[\"wnli\", \"copa\", \"sna\", \"csqa\", \"wstp\", \"inltkh\", \"bbca\", '
                   '\"cvit-mkb-clsr\", \"iitp-mr\", \"iitp-pr\", \"actsa-sc\", \"md\", '
                   '\"wiki-ner\"]')
        return datasets.MetricInfo(
            description=_DESCRIPTION      ,   citation=_CITATION      ,   inputs_description=_KWARGS_DESCRIPTION      ,   features=datasets.Features(
                {
                    'predictions': datasets.Value('int64')
                    if self.config_name != 'cvit-mkb-clsr'
                    else datasets.Sequence(datasets.Value('float32')),
                    'references': datasets.Value('int64')
                    if self.config_name != 'cvit-mkb-clsr'
                    else datasets.Sequence(datasets.Value('float32')),
                })      ,   codebase_urls=[]      ,   reference_urls=[]      ,   format='numpy' if self.config_name != 'cvit-mkb-clsr' else None      ,   )




 def 		__snake_case						(      self :  str      ,   lowercase__ :  str      ,   lowercase__ :  str):







        '''simple docstring'''



        if self.config_name == "cvit-mkb-clsr":
               return {"precision@10": precision_at_aa(__lowerCAmelCase      ,   __lowerCAmelCase)}
        elif self.config_name in ["wiki-ner"]:
               return acc_and_fa(__lowerCAmelCase      ,   __lowerCAmelCase)
        elif self.config_name in [
            "wnli",
            "copa",
            "sna",
            "csqa",
            "wstp",
            "inltkh",
            "bbca",
            "iitp-mr",
            "iitp-pr",
            "actsa-sc",
            "md",
        ]:
               return {"accuracy": simple_accuracy(__lowerCAmelCase      ,   __lowerCAmelCase)}
        else:
               raise KeyError(
                   'You should supply a configuration name selected in '
                   '[\"wnli\", \"copa\", \"sna\", \"csqa\", \"wstp\", \"inltkh\", \"bbca\", '
                   '\"cvit-mkb-clsr\", \"iitp-mr\", \"iitp-pr\", \"actsa-sc\", \"md\", '
                   '\"wiki-ner\"]')

from collections import OrderedDict
from typing import Mapping

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


lowerCAmelCase__     						=			logging.get_logger(__name__)

lowerCAmelCase__     						=			{
    'facebook/xlm-roberta-xl': 'https://huggingface.co/facebook/xlm-roberta-xl/resolve/main/config.json',
    'facebook/xlm-roberta-xxl': 'https://huggingface.co/facebook/xlm-roberta-xxl/resolve/main/config.json',
    # See all XLM-RoBERTa-XL models at https://huggingface.co/models?filter=xlm-roberta-xl
}
class     a_			(						SCREAMING_SNAKE_CASE						):






 '''simple docstring'''






 UpperCAmelCase_     			= 'xlm-roberta-xl'




 def __init__(      self :  int      ,   lowercase__ :  Optional[int]=250_880      ,   lowercase__ :  Union[str, Any]=2_560      ,   lowercase__ :  int=36      ,   lowercase__ :  int=32      ,   lowercase__ :  List[Any]=10_240      ,   lowercase__ :  Union[str, Any]="gelu"      ,   lowercase__ :  Dict=0.1      ,   lowercase__ :  Any=0.1      ,   lowercase__ :  Any=514      ,   lowercase__ :  Optional[int]=1      ,   lowercase__ :  Any=0.02      ,   lowercase__ :  List[str]=1e-05      ,   lowercase__ :  Dict=1      ,   lowercase__ :  Union[str, Any]=0      ,   lowercase__ :  Dict=2      ,   lowercase__ :  str="absolute"      ,   lowercase__ :  Dict=True      ,   lowercase__ :  List[Any]=None      ,   **lowercase__ :  Optional[Any]      ,   ):







        '''simple docstring'''



        super().__init__(pad_token_id=lowercase__      ,   bos_token_id=lowercase__      ,   eos_token_id=lowercase__      ,   **lowercase__)
        lowerCAmelCase__					     = vocab_size
        lowerCAmelCase__					     = hidden_size
        lowerCAmelCase__					     = num_hidden_layers
        lowerCAmelCase__					     = num_attention_heads
        lowerCAmelCase__					     = hidden_act
        lowerCAmelCase__					     = intermediate_size
        lowerCAmelCase__					     = hidden_dropout_prob
        lowerCAmelCase__					     = attention_probs_dropout_prob
        lowerCAmelCase__					     = max_position_embeddings
        lowerCAmelCase__					     = type_vocab_size
        lowerCAmelCase__					     = initializer_range
        lowerCAmelCase__					     = layer_norm_eps
        lowerCAmelCase__					     = position_embedding_type
        lowerCAmelCase__					     = use_cache
        lowerCAmelCase__					     = classifier_dropout






class     a_			(						SCREAMING_SNAKE_CASE						):






 '''simple docstring'''






 @property
 def 		__snake_case						(      self :  int):







        '''simple docstring'''



        if self.task == "multiple-choice":
               lowerCAmelCase__					     = {0: 'batch', 1: 'choice', 2: 'sequence'}
        else:
               lowerCAmelCase__					     = {0: 'batch', 1: 'sequence'}
        return OrderedDict(
            [
                ('input_ids', dynamic_axis),
                ('attention_mask', dynamic_axis),
            ])
