



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

import datasets


__snake_case    :		Tuple     ='\\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'

__snake_case    :		str     ='\\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'

__snake_case    :		Tuple     ='\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_		:		Union[str, Any]	,lowerCamelCase_		:		Any):





				'''simple docstring'''

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






def      lowerCAmelCase__		(   lowerCamelCase_		:		str	,lowerCamelCase_		:		Optional[int]):





				'''simple docstring'''

				lowerCAmelCase__					:    Optional[int]												=					simple_accuracy(lowerCamelCase_	,lowerCamelCase_)
				lowerCAmelCase__					:    Any												=					float(fa_score(y_true=lowerCamelCase_	,y_pred=lowerCamelCase_))
				return {
				    "accuracy": acc,
				    "f1": fa,
				}






def      lowerCAmelCase__		(   lowerCamelCase_		:		Optional[int]	,lowerCamelCase_		:		Tuple):





				'''simple docstring'''

				lowerCAmelCase__					:    List[Any]												=					np.array(lowerCamelCase_)
				lowerCAmelCase__					:    List[Any]												=					np.array(lowerCamelCase_)
				lowerCAmelCase__					:    Any												=					en_sentvecs.shape[0]

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

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




		'''simple docstring'''



		def 		lowerCAmelCase__				(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 		lowerCAmelCase__				(self		,__lowerCamelCase		,__lowerCamelCase			)					->      Optional[Any]:

						"""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 ...configuration_utils import PretrainedConfig
from ...utils import logging


__snake_case    :		Any  =logging.get_logger(__name__)

__snake_case    :		Tuple  ={
    'sayakpaul/vit-msn-base': 'https://huggingface.co/sayakpaul/vit-msn-base/resolve/main/config.json',
    # See all ViT MSN models at https://huggingface.co/models?filter=vit_msn
}



class 	lowerCamelCase__      (							lowerCamelCase__):




		'''simple docstring'''



		snake_case_     ="""vit_msn"""



		def __init__(self		,__lowerCamelCase=7_68		,__lowerCamelCase=12		,__lowerCamelCase=12		,__lowerCamelCase=30_72		,__lowerCamelCase="gelu"		,__lowerCamelCase=0.0		,__lowerCamelCase=0.0		,__lowerCamelCase=0.02		,__lowerCamelCase=1e-06		,__lowerCamelCase=2_24		,__lowerCamelCase=16		,__lowerCamelCase=3		,__lowerCamelCase=True		,**__lowerCamelCase		,)					->      Any:

						"""simple docstring"""






						super().__init__(**__lowerCamelCase			)

						lowerCAmelCase__					:    List[Any]												=					hidden_size
						lowerCAmelCase__					:    str												=					num_hidden_layers
						lowerCAmelCase__					:    List[str]												=					num_attention_heads
						lowerCAmelCase__					:    Optional[int]												=					intermediate_size
						lowerCAmelCase__					:    List[Any]												=					hidden_act
						lowerCAmelCase__					:    Tuple												=					hidden_dropout_prob
						lowerCAmelCase__					:    List[Any]												=					attention_probs_dropout_prob
						lowerCAmelCase__					:    int												=					initializer_range
						lowerCAmelCase__					:    Union[str, Any]												=					layer_norm_eps
						lowerCAmelCase__					:    List[str]												=					image_size
						lowerCAmelCase__					:    str												=					patch_size
						lowerCAmelCase__					:    Optional[int]												=					num_channels
						lowerCAmelCase__					:    int												=					qkv_bias

