


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

import datasets


A							:					int     						=     "\\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"

A							:					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"

A							:					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       (    _lowerCAmelCase      ,	_lowerCAmelCase )						->	List[Any]:


						'''simple docstring'''






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





def 	_lowerCAmelCase       (    _lowerCAmelCase      ,	_lowerCAmelCase )						->	Optional[Any]:


						'''simple docstring'''






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





def 	_lowerCAmelCase       (    _lowerCAmelCase      ,	_lowerCAmelCase )						->	int:


						'''simple docstring'''






						__snake_case				=		np.array(_lowerCAmelCase )
						__snake_case				=		np.array(_lowerCAmelCase )
						__snake_case				=		en_sentvecs.shape[0]

						# mean centering
						__snake_case				=		en_sentvecs - np.mean(_lowerCAmelCase      ,	axis=0 )
						__snake_case				=		in_sentvecs - np.mean(_lowerCAmelCase      ,	axis=0 )

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






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


					def 							SCREAMING_SNAKE_CASE_  (						self	:		str						)			->	List[str]:




											'''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 							SCREAMING_SNAKE_CASE_  (						self	:		Optional[int]     ,    SCREAMING_SNAKE_CASE	:		Optional[Any]     ,    SCREAMING_SNAKE_CASE	:		Optional[int]						)			->	List[Any]:




											'''simple docstring'''

											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 sklearn.metrics import mean_squared_error

import datasets


A							:					List[Any]     						=     '\\n@article{scikit-learn,\n title={Scikit-learn: Machine Learning in {P}ython},\n author={Pedregosa, F. and Varoquaux, G. and Gramfort, A. and Michel, V.\n         and Thirion, B. and Grisel, O. and Blondel, M. and Prettenhofer, P.\n         and Weiss, R. and Dubourg, V. and Vanderplas, J. and Passos, A. and\n         Cournapeau, D. and Brucher, M. and Perrot, M. and Duchesnay, E.},\n journal={Journal of Machine Learning Research},\n volume={12},\n pages={2825--2830},\n year={2011}\n}\n'

A							:					Optional[int]     						=     '\\nMean Squared Error(MSE) is the average of the square of difference between the predicted\nand actual values.\n'


A							:					str     						=     '\nArgs:\n    predictions: array-like of shape (n_samples,) or (n_samples, n_outputs)\n        Estimated target values.\n    references: array-like of shape (n_samples,) or (n_samples, n_outputs)\n        Ground truth (correct) target values.\n    sample_weight: array-like of shape (n_samples,), default=None\n        Sample weights.\n    multioutput: {"raw_values", "uniform_average"} or array-like of shape (n_outputs,), default="uniform_average"\n        Defines aggregating of multiple output values. Array-like value defines weights used to average errors.\n\n        "raw_values" : Returns a full set of errors in case of multioutput input.\n\n        "uniform_average" : Errors of all outputs are averaged with uniform weight.\n\n    squared : bool, default=True\n        If True returns MSE value, if False returns RMSE (Root Mean Squared Error) value.\n\nReturns:\n    mse : mean squared error.\nExamples:\n\n    >>> mse_metric = datasets.load_metric("mse")\n    >>> predictions = [2.5, 0.0, 2, 8]\n    >>> references = [3, -0.5, 2, 7]\n    >>> results = mse_metric.compute(predictions=predictions, references=references)\n    >>> print(results)\n    {\'mse\': 0.375}\n    >>> rmse_result = mse_metric.compute(predictions=predictions, references=references, squared=False)\n    >>> print(rmse_result)\n    {\'mse\': 0.6123724356957945}\n\n    If you\'re using multi-dimensional lists, then set the config as follows :\n\n    >>> mse_metric = datasets.load_metric("mse", "multilist")\n    >>> predictions = [[0.5, 1], [-1, 1], [7, -6]]\n    >>> references = [[0, 2], [-1, 2], [8, -5]]\n    >>> results = mse_metric.compute(predictions=predictions, references=references)\n    >>> print(results)\n    {\'mse\': 0.7083333333333334}\n    >>> results = mse_metric.compute(predictions=predictions, references=references, multioutput=\'raw_values\')\n    >>> print(results) # doctest: +NORMALIZE_WHITESPACE\n    {\'mse\': array([0.41666667, 1. ])}\n'






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


					def 							SCREAMING_SNAKE_CASE_  (						self	:		Dict						)			->	Union[str, Any]:




											'''simple docstring'''

											return datasets.MetricInfo(
											    description=_DESCRIPTION     ,    citation=_CITATION     ,    inputs_description=_KWARGS_DESCRIPTION     ,    features=datasets.Features(self._get_feature_types()						)     ,    reference_urls=[
											        "https://scikit-learn.org/stable/modules/generated/sklearn.metrics.mean_squared_error.html"
											    ]     ,    )


					def 							SCREAMING_SNAKE_CASE_  (						self	:		List[str]						)			->	Dict:




											'''simple docstring'''

											if self.config_name == "multilist":
																	return {
																	    "predictions": datasets.Sequence(datasets.Value("float"						)						),
																	    "references": datasets.Sequence(datasets.Value("float"						)						),
																	}
											else:
																	return {
																	    "predictions": datasets.Value("float"						),
																	    "references": datasets.Value("float"						),
																	}






					def 							SCREAMING_SNAKE_CASE_  (						self	:		Dict     ,    SCREAMING_SNAKE_CASE	:		int     ,    SCREAMING_SNAKE_CASE	:		List[Any]     ,    SCREAMING_SNAKE_CASE	:		str=None     ,    SCREAMING_SNAKE_CASE	:		int="uniform_average"     ,    SCREAMING_SNAKE_CASE	:		Optional[int]=True						)			->	Tuple:




											'''simple docstring'''

											__snake_case				=		mean_squared_error(
											    SCREAMING_SNAKE_CASE     ,    SCREAMING_SNAKE_CASE     ,    sample_weight=SCREAMING_SNAKE_CASE     ,    multioutput=SCREAMING_SNAKE_CASE     ,    squared=SCREAMING_SNAKE_CASE						)

											return {"mse": mse}





