





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

import datasets


__UpperCAmelCase					:     List[Any]	      =	'\\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					:     Dict	      =	'\\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					:     Optional[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 						lowerCamelCase_	(		UpperCamelCase_			,					UpperCamelCase_       ):
      return float((preds == labels).mean()       )




def 						lowerCamelCase_	(		UpperCamelCase_			,					UpperCamelCase_       ):
      _a							:  List[str]				= simple_accuracy(__SCREAMING_SNAKE_CASE			,					__SCREAMING_SNAKE_CASE       )
      _a							:  Dict				= float(fa_score(y_true=__SCREAMING_SNAKE_CASE			,					y_pred=__SCREAMING_SNAKE_CASE       )       )
      return {
          "accuracy": acc,
          "f1": fa,
      }




def 						lowerCamelCase_	(		UpperCamelCase_			,					UpperCamelCase_       ):
      _a							:  Any				= np.array(__SCREAMING_SNAKE_CASE       )
      _a							:  Dict				= np.array(__SCREAMING_SNAKE_CASE       )
      _a							:  Tuple				= en_sentvecs.shape[0]

      # mean centering
      _a							:  Tuple				= en_sentvecs - np.mean(__SCREAMING_SNAKE_CASE			,					axis=0       )
      _a							:  Optional[int]				= in_sentvecs - np.mean(__SCREAMING_SNAKE_CASE			,					axis=0       )

      _a							:  Optional[int]				= cdist(__SCREAMING_SNAKE_CASE			,					__SCREAMING_SNAKE_CASE			,					'''cosine'''       )
      _a							:  int				= np.array(range(__SCREAMING_SNAKE_CASE       )       )
      _a							:  Union[str, Any]				= sim.argsort(axis=1       )[:, :10]
      _a							:  Optional[int]				= np.any(preds == actual[:, None]			,					axis=1       )
      return float(matches.mean()       )





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







  def      snake_case_							(     self						:   int       )    ->		Any:
        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						:   List[str]  ,					__snake_case						:   Dict  ,					__snake_case						:   Union[str, Any]       )    ->		Union[str, Any]:
        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"]'''       )











'''simple docstring'''






import json
from typing import List, Optional, Tuple

from tokenizers import pre_tokenizers, processors

from ...tokenization_utils_base import AddedToken, BatchEncoding
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_mvp import MvpTokenizer


A_			      =		logging.get_logger(__name__)


A_			      =		{"vocab_file": "vocab.json", "merges_file": "merges.txt", "tokenizer_file": "tokenizer.json"}

# See all MVP models at https://huggingface.co/models?filter=mvp
A_			      =		{
    "vocab_file": {
        "RUCAIBox/mvp": "https://huggingface.co/RUCAIBox/mvp/resolve/main/vocab.json",
    },
    "added_tokens.json": {
        "RUCAIBox/mvp": "https://huggingface.co/RUCAIBox/mvp/resolve/main/added_tokens.json",
    },
    "merges_file": {
        "RUCAIBox/mvp": "https://huggingface.co/RUCAIBox/mvp/resolve/main/merges.txt",
    },
    "tokenizer_file": {
        "RUCAIBox/mvp": "https://huggingface.co/RUCAIBox/mvp/resolve/main/tokenizer.json",
    },
}

A_			      =		{
    "RUCAIBox/mvp": 1024,
}






class        lowercase_      (						lowerCAmelCase_							):
     A_											=			VOCAB_FILES_NAMES
     A_											=			PRETRAINED_VOCAB_FILES_MAP
     A_											=			PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
     A_											=			["input_ids", "attention_mask"]
     A_											=			MvpTokenizer





     def __init__(     self     :					Optional[int]     ,							__lowerCamelCase     :					Tuple=None     ,							__lowerCamelCase     :					Tuple=None     ,							__lowerCamelCase     :					List[str]=None     ,							__lowerCamelCase     :					Optional[int]="replace"     ,							__lowerCamelCase     :					int="<s>"     ,							__lowerCamelCase     :					Dict="</s>"     ,							__lowerCamelCase     :					int="</s>"     ,							__lowerCamelCase     :					int="<s>"     ,							__lowerCamelCase     :					int="<unk>"     ,							__lowerCamelCase     :					List[str]="<pad>"     ,							__lowerCamelCase     :					int="<mask>"     ,							__lowerCamelCase     :					int=False     ,							__lowerCamelCase     :					List[str]=True     ,							**__lowerCamelCase     :					Dict     ,							):
           super().__init__(
               __lowerCamelCase     ,							__lowerCamelCase     ,							tokenizer_file=__lowerCamelCase     ,							errors=__lowerCamelCase     ,							bos_token=__lowerCamelCase     ,							eos_token=__lowerCamelCase     ,							sep_token=__lowerCamelCase     ,							cls_token=__lowerCamelCase     ,							unk_token=__lowerCamelCase     ,							pad_token=__lowerCamelCase     ,							mask_token=__lowerCamelCase     ,							add_prefix_space=__lowerCamelCase     ,							trim_offsets=__lowerCamelCase     ,							**__lowerCamelCase     ,							)

           snake_case__       :   Any	      =    json.loads(self.backend_tokenizer.pre_tokenizer.__getstate__()			)
           if pre_tok_state.get('add_prefix_space'     ,							__lowerCamelCase			) != add_prefix_space:
                 snake_case__       :   str	      =    getattr(__lowerCamelCase     ,							pre_tok_state.pop('type'			)			)
                 snake_case__       :   int	      =    add_prefix_space
                 snake_case__       :   List[str]	      =    pre_tok_class(**__lowerCamelCase			)

           snake_case__       :   Tuple	      =    add_prefix_space

           # the pre_tokenizer is already updated in the GPT2TokenizerFast `__init__`
           snake_case__       :   Dict	      =    'post_processor'
           snake_case__       :   Optional[int]	      =    getattr(self.backend_tokenizer     ,							__lowerCamelCase     ,							__lowerCamelCase			)
           if tokenizer_component_instance:
                 snake_case__       :   List[Any]	      =    json.loads(tokenizer_component_instance.__getstate__()			)

                 # The lists 'sep' and 'cls' must be cased in tuples for the object `post_processor_class`
                 if "sep" in state:
                       snake_case__       :   int	      =    tuple(state['sep']			)
                 if "cls" in state:
                       snake_case__       :   Union[str, Any]	      =    tuple(state['cls']			)

                 snake_case__       :   Dict	      =    False

                 if state.get('add_prefix_space'     ,							__lowerCamelCase			) != add_prefix_space:
                       snake_case__       :   List[Any]	      =    add_prefix_space
                       snake_case__       :   List[str]	      =    True

                 if state.get('trim_offsets'     ,							__lowerCamelCase			) != trim_offsets:
                       snake_case__       :   str	      =    trim_offsets
                       snake_case__       :   List[Any]	      =    True

                 if changes_to_apply:
                       snake_case__       :   Optional[int]	      =    getattr(__lowerCamelCase     ,							state.pop('type'			)			)
                       snake_case__       :   str	      =    component_class(**__lowerCamelCase			)
                       setattr(self.backend_tokenizer     ,							__lowerCamelCase     ,							__lowerCamelCase			)





     @property
     def 			_lowerCAmelCase      (     self     :					str			):
           if self._mask_token is None:
                 if self.verbose:
                       logger.error('Using mask_token, but it is not set yet.'			)
                 return None
           return str(self._mask_token			)





     @mask_token.setter
     def 			_lowerCAmelCase      (     self     :					Tuple     ,							__lowerCamelCase     :					Optional[Any]			):
           snake_case__       :   str	      =    AddedToken(__lowerCamelCase     ,							lstrip=__lowerCamelCase     ,							rstrip=__lowerCamelCase			) if isinstance(__lowerCamelCase     ,							__lowerCamelCase			) else value
           snake_case__       :   Optional[int]	      =    value





     def 			_lowerCAmelCase      (     self     :					List[str]     ,							*__lowerCamelCase     :					List[str]     ,							**__lowerCamelCase     :					List[Any]			):
           snake_case__       :   Optional[int]	      =    kwargs.get('is_split_into_words'     ,							__lowerCamelCase			)

           if is_split_into_words and not self.add_prefix_space:
                 raise ValueError(
                     F"You need to instantiate {self.__class__.__name__} with add_prefix_space=True "
                     'to use it with pretokenized inputs.'			)

           return super()._batch_encode_plus(*__lowerCamelCase     ,							**__lowerCamelCase			)





     def 			_lowerCAmelCase      (     self     :					List[str]     ,							*__lowerCamelCase     :					Optional[Any]     ,							**__lowerCamelCase     :					Dict			):
           snake_case__       :   Tuple	      =    kwargs.get('is_split_into_words'     ,							__lowerCamelCase			)

           if is_split_into_words and not self.add_prefix_space:
                 raise ValueError(
                     F"You need to instantiate {self.__class__.__name__} with add_prefix_space=True "
                     'to use it with pretokenized inputs.'			)

           return super()._encode_plus(*__lowerCamelCase     ,							**__lowerCamelCase			)





     def 			_lowerCAmelCase      (     self     :					Union[str, Any]     ,							__lowerCamelCase     :					str     ,							__lowerCamelCase     :					Optional[str] = None			):
           snake_case__       :   List[str]	      =    self._tokenizer.model.save(__lowerCamelCase     ,							name=__lowerCamelCase			)
           return tuple(__lowerCamelCase			)





     def 			_lowerCAmelCase      (     self     :					List[str]     ,							__lowerCamelCase     :					Tuple     ,							__lowerCamelCase     :					Optional[int]=None			):
           snake_case__       :   Optional[Any]	      =    [self.bos_token_id] + token_ids_a + [self.eos_token_id]
           if token_ids_a is None:
                 return output

           return output + [self.eos_token_id] + token_ids_a + [self.eos_token_id]





     def 			_lowerCAmelCase      (     self     :					Dict     ,							__lowerCamelCase     :					List[int]     ,							__lowerCamelCase     :					Optional[List[int]] = None			):
           snake_case__       :   Dict	      =    [self.sep_token_id]
           snake_case__       :   List[Any]	      =    [self.cls_token_id]

           if token_ids_a is None:
                 return len(cls + token_ids_a + sep			) * [0]
           return len(cls + token_ids_a + sep + sep + token_ids_a + sep			) * [0]
