




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

import datasets


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

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

lowercase__  		=		"""
Compute IndicGLUE evaluation metric associated to each IndicGLUE dataset.
Args:
    predictions: list of predictions to score (as int64),
        except for 'cvit-mkb-clsr' where each prediction is a vector (of float32).
    references: list of ground truth labels corresponding to the predictions (as int64),
        except for 'cvit-mkb-clsr' where each reference is a vector (of float32).
Returns: depending on the IndicGLUE subset, one or several of:
    \"accuracy\": Accuracy
    \"f1\": F1 score
    \"precision\": Precision@10
Examples:

    >>> 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\"]
    >>> references = [0, 1]
    >>> predictions = [0, 1]
    >>> results = indic_glue_metric.compute(predictions=predictions, references=references)
    >>> print(results)
    {'accuracy': 1.0}

    >>> indic_glue_metric = datasets.load_metric('indic_glue', 'wiki-ner')
    >>> references = [0, 1]
    >>> predictions = [0, 1]
    >>> results = indic_glue_metric.compute(predictions=predictions, references=references)
    >>> print(results)
    {'accuracy': 1.0, 'f1': 1.0}

    >>> indic_glue_metric = datasets.load_metric('indic_glue', 'cvit-mkb-clsr')
    >>> references = [[0.5, 0.5, 0.5], [0.1, 0.2, 0.3]]
    >>> predictions = [[0.5, 0.5, 0.5], [0.1, 0.2, 0.3]]
    >>> results = indic_glue_metric.compute(predictions=predictions, references=references)
    >>> print(results)
    {'precision@10': 1.0}

"""







def   _snake_case    (       lowercase__							,					lowercase__	):
				return float((preds == labels).mean()	)







def   _snake_case    (       lowercase__							,					lowercase__	):
				_lowerCamelCase  :    Tuple					=					simple_accuracy(lowercase__							,					lowercase__	)
				_lowerCamelCase  :    Any					=					float(fa_score(y_true=lowercase__							,					y_pred=lowercase__	)	)
				return {
				    "accuracy": acc,
				    "f1": fa,
				}







def   _snake_case    (       lowercase__							,					lowercase__	):
				_lowerCamelCase  :    Optional[int]					=					np.array(lowercase__	)
				_lowerCamelCase  :    Any					=					np.array(lowercase__	)
				_lowerCamelCase  :    Any					=					en_sentvecs.shape[0]

				# mean centering
				_lowerCamelCase  :    Any					=					en_sentvecs - np.mean(lowercase__							,					axis=0	)
				_lowerCamelCase  :    List[str]					=					in_sentvecs - np.mean(lowercase__							,					axis=0	)

				_lowerCamelCase  :    Union[str, Any]					=					cdist(lowercase__							,					lowercase__							,					'cosine'	)
				_lowerCamelCase  :    List[str]					=					np.array(range(lowercase__	)	)
				_lowerCamelCase  :    str					=					sim.argsort(axis=1	)[:, :10]
				_lowerCamelCase  :    Tuple					=					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		):






			'''simple docstring'''



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






from typing import Mapping

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


lowercase__  		=		logging.get_logger(__name__)

lowercase__  		=		{
    """google/umt5-small""": """https://huggingface.co/google/umt5-small/resolve/main/config.json""",
    # See all umt5 models at https://huggingface.co/models?filter=umt5
}






class lowerCAmelCase__			(  lowercase		):






			'''simple docstring'''



			lowerCamelCase__   =    """umt5"""
			lowerCamelCase__   =    ["""past_key_values"""]
			def __init__(						self						,   lowercase=250112						,   lowercase=512						,   lowercase=64						,   lowercase=1024						,   lowercase=8						,   lowercase=None						,   lowercase=6						,   lowercase=32						,   lowercase=128						,   lowercase=0.1						,   lowercase=1E-6						,   lowercase=1.0						,   lowercase="gated-gelu"						,   lowercase=True						,   lowercase=True						,   lowercase="T5Tokenizer"						,   lowercase=True						,   lowercase=0						,   lowercase=1						,   lowercase=0						,   **lowercase						,   ):
							super().__init__(
							    is_encoder_decoder=lowercase						,   tokenizer_class=lowercase						,   tie_word_embeddings=lowercase						,   pad_token_id=lowercase						,   eos_token_id=lowercase						,   decoder_start_token_id=lowercase						,   **lowercase						,   )
							_lowerCamelCase  :    Union[str, Any]					=					vocab_size
							_lowerCamelCase  :    Optional[Any]					=					d_model
							_lowerCamelCase  :    Optional[Any]					=					d_kv
							_lowerCamelCase  :    Optional[int]					=					d_ff
							_lowerCamelCase  :    List[str]					=					num_layers
							_lowerCamelCase  :    Union[str, Any]					=					(
							    num_decoder_layers if num_decoder_layers is not None else self.num_layers
							)  # default = symmetry
							_lowerCamelCase  :    List[str]					=					num_heads
							_lowerCamelCase  :    int					=					relative_attention_num_buckets
							_lowerCamelCase  :    Union[str, Any]					=					relative_attention_max_distance
							_lowerCamelCase  :    int					=					dropout_rate
							_lowerCamelCase  :    List[Any]					=					layer_norm_epsilon
							_lowerCamelCase  :    Union[str, Any]					=					initializer_factor
							_lowerCamelCase  :    List[Any]					=					feed_forward_proj
							_lowerCamelCase  :    Dict					=					use_cache

							_lowerCamelCase  :    Dict					=					self.feed_forward_proj.split('-'						)
							_lowerCamelCase  :    List[str]					=					act_info[-1]
							_lowerCamelCase  :    int					=					act_info[0] == 'gated'

							if len(lowercase						) > 1 and act_info[0] != "gated" or len(lowercase						) > 2:
											raise ValueError(
											    F'''`feed_forward_proj`: {feed_forward_proj} is not a valid activation function of the dense layer.'''
											    'Please make sure `feed_forward_proj` is of the format `gated-{ACT_FN}` or `{ACT_FN}`, e.g. '
											    '\'gated-gelu\' or \'relu\''						)

							if feed_forward_proj == "gated-gelu":
											_lowerCamelCase  :    Optional[int]					=					'gelu_new'
			@property
			def       A_					(						self						):
							return self.d_model
			@property
			def       A_					(						self						):
							return self.num_heads






			@property
			def       A_					(						self						):
							return self.num_layers






class lowerCAmelCase__			(  lowercase		):






			'''simple docstring'''



			@property
			# Copied from transformers.models.t5.configuration_t5.T5OnnxConfig.inputs
			def       A_					(						self						):
							_lowerCamelCase  :    Tuple					=					{
							    'input_ids': {0: 'batch', 1: 'encoder_sequence'},
							    'attention_mask': {0: 'batch', 1: 'encoder_sequence'},
							}
							if self.use_past:
											_lowerCamelCase  :    Optional[int]					=					'past_encoder_sequence + sequence'
											_lowerCamelCase  :    int					=					{0: 'batch'}
											_lowerCamelCase  :    List[str]					=					{0: 'batch', 1: 'past_decoder_sequence + sequence'}
							else:
											_lowerCamelCase  :    Dict					=					{0: 'batch', 1: 'decoder_sequence'}
											_lowerCamelCase  :    str					=					{0: 'batch', 1: 'decoder_sequence'}

							if self.use_past:
											self.fill_with_past_key_values_(lowercase						,   direction='inputs'						)

							return common_inputs
			@property
			# Copied from transformers.models.t5.configuration_t5.T5OnnxConfig.default_onnx_opset
			def       A_					(						self						):
							return 13






			@property
			def       A_					(						self						):
							return 5E-4