

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

import datasets


UpperCamelCase__  :      Dict			=    "\\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"

UpperCamelCase__  :      List[Any]			=    "\\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"

UpperCamelCase__  :      Union[str, Any]			=    "\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 					_UpperCAmelCase       (  _SCREAMING_SNAKE_CASE					:		List[str] ,   _SCREAMING_SNAKE_CASE					:		int       ):





    """simple docstring"""


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


def 					_UpperCAmelCase       (  _SCREAMING_SNAKE_CASE					:		int ,   _SCREAMING_SNAKE_CASE					:		str       ):





    """simple docstring"""


    SCREAMING_SNAKE_CASE_									=						simple_accuracy(_SCREAMING_SNAKE_CASE ,   _SCREAMING_SNAKE_CASE       )
    SCREAMING_SNAKE_CASE_									=						float(fa_score(y_true=_SCREAMING_SNAKE_CASE ,   y_pred=_SCREAMING_SNAKE_CASE       )       )
    return {
        "accuracy": acc,
        "f1": fa,
    }


def 					_UpperCAmelCase       (  _SCREAMING_SNAKE_CASE					:		Optional[Any] ,   _SCREAMING_SNAKE_CASE					:		Tuple       ):





    """simple docstring"""


    SCREAMING_SNAKE_CASE_									=						np.array(_SCREAMING_SNAKE_CASE       )
    SCREAMING_SNAKE_CASE_									=						np.array(_SCREAMING_SNAKE_CASE       )
    SCREAMING_SNAKE_CASE_									=						en_sentvecs.shape[0]

    # mean centering
    SCREAMING_SNAKE_CASE_									=						en_sentvecs - np.mean(_SCREAMING_SNAKE_CASE ,   axis=0       )
    SCREAMING_SNAKE_CASE_									=						in_sentvecs - np.mean(_SCREAMING_SNAKE_CASE ,   axis=0       )

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





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

  def 						lowerCAmelCase__     (					self):
      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 						lowerCAmelCase__     (					self						,		_A						,		_A):
      if self.config_name == "cvit-mkb-clsr":
          return {"precision@10": precision_at_aa(_A						,		_A)}
      elif self.config_name in ["wiki-ner"]:
          return acc_and_fa(_A						,		_A)
      elif self.config_name in [
          "wnli",
          "copa",
          "sna",
          "csqa",
          "wstp",
          "inltkh",
          "bbca",
          "iitp-mr",
          "iitp-pr",
          "actsa-sc",
          "md",
      ]:
          return {"accuracy": simple_accuracy(_A						,		_A)}
      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 typing import List

import numpy as np


def 					_UpperCAmelCase       (  _SCREAMING_SNAKE_CASE					:		dict       ):





    """simple docstring"""


    SCREAMING_SNAKE_CASE_									=						{key: len(_SCREAMING_SNAKE_CASE       ) for key, value in gen_kwargs.items() if isinstance(_SCREAMING_SNAKE_CASE ,   _SCREAMING_SNAKE_CASE       )}
    if len(set(lists_lengths.values()       )       ) > 1:
        raise RuntimeError(
            (
                'Sharding is ambiguous for this dataset: '
                + 'we found several data sources lists of different lengths, and we don\'t know over which list we should parallelize:\n'
                + '\n'.join(f"""\t- key {key} has length {length}""" for key, length in lists_lengths.items()       )
                + '\nTo fix this, check the \'gen_kwargs\' and make sure to use lists only for data sources, '
                + 'and use tuples otherwise. In the end there should only be one single list, or several lists with the same length.'
            )       )
    SCREAMING_SNAKE_CASE_									=						max(lists_lengths.values() ,   default=0       )
    return max(1 ,   _SCREAMING_SNAKE_CASE       )


def 					_UpperCAmelCase       (  _SCREAMING_SNAKE_CASE					:		int ,   _SCREAMING_SNAKE_CASE					:		int       ):





    """simple docstring"""


    SCREAMING_SNAKE_CASE_									=						[]
    for group_idx in range(_SCREAMING_SNAKE_CASE       ):
        SCREAMING_SNAKE_CASE_									=						num_shards // max_num_jobs + (group_idx < (num_shards % max_num_jobs))
        if num_shards_to_add == 0:
            break
        SCREAMING_SNAKE_CASE_									=						shards_indices_per_group[-1].stop if shards_indices_per_group else 0
        SCREAMING_SNAKE_CASE_									=						range(_SCREAMING_SNAKE_CASE ,   start + num_shards_to_add       )
        shards_indices_per_group.append(_SCREAMING_SNAKE_CASE       )
    return shards_indices_per_group


def 					_UpperCAmelCase       (  _SCREAMING_SNAKE_CASE					:		dict ,   _SCREAMING_SNAKE_CASE					:		int       ):





    """simple docstring"""


    SCREAMING_SNAKE_CASE_									=						_number_of_shards_in_gen_kwargs(_SCREAMING_SNAKE_CASE       )
    if num_shards == 1:
        return [dict(_SCREAMING_SNAKE_CASE       )]
    else:
        SCREAMING_SNAKE_CASE_									=						_distribute_shards(num_shards=_SCREAMING_SNAKE_CASE ,   max_num_jobs=_SCREAMING_SNAKE_CASE       )
        return [
            {
                key: [value[shard_idx] for shard_idx in shard_indices_per_group[group_idx]]
                if isinstance(_SCREAMING_SNAKE_CASE ,   _SCREAMING_SNAKE_CASE       )
                else value
                for key, value in gen_kwargs.items()
            }
            for group_idx in range(len(_SCREAMING_SNAKE_CASE       )       )
        ]


def 					_UpperCAmelCase       (  _SCREAMING_SNAKE_CASE					:		List[dict]       ):





    """simple docstring"""


    return {
        key: [value for gen_kwargs in gen_kwargs_list for value in gen_kwargs[key]]
        if isinstance(gen_kwargs_list[0][key] ,   _SCREAMING_SNAKE_CASE       )
        else gen_kwargs_list[0][key]
        for key in gen_kwargs_list[0]
    }





def 					_UpperCAmelCase       (  _SCREAMING_SNAKE_CASE					:		np.random.Generator ,   _SCREAMING_SNAKE_CASE					:		dict       ):





    """simple docstring"""


    SCREAMING_SNAKE_CASE_									=						{len(_SCREAMING_SNAKE_CASE       ) for value in gen_kwargs.values() if isinstance(_SCREAMING_SNAKE_CASE ,   _SCREAMING_SNAKE_CASE       )}
    SCREAMING_SNAKE_CASE_									=						{}
    for size in list_sizes:
        SCREAMING_SNAKE_CASE_									=						list(range(_SCREAMING_SNAKE_CASE       )       )
        rng.shuffle(indices_per_size[size]       )
    # Now let's copy the gen_kwargs and shuffle the lists based on their sizes
    SCREAMING_SNAKE_CASE_									=						dict(_SCREAMING_SNAKE_CASE       )
    for key, value in shuffled_kwargs.items():
        if isinstance(_SCREAMING_SNAKE_CASE ,   _SCREAMING_SNAKE_CASE       ):
            SCREAMING_SNAKE_CASE_									=						[value[i] for i in indices_per_size[len(_SCREAMING_SNAKE_CASE       )]]
    return shuffled_kwargs


