
'''simple docstring'''
import json
import os
import unittest

from transformers import DebertaTokenizer, DebertaTokenizerFast
from transformers.models.deberta.tokenization_deberta import VOCAB_FILES_NAMES
from transformers.testing_utils import slow

from ...test_tokenization_common import TokenizerTesterMixin


class 			_lowerCAmelCase    (    A__     ,							unittest.TestCase      ):







							'''simple docstring'''

							lowerCAmelCase_											=						DebertaTokenizer
							lowerCAmelCase_											=						True
							lowerCAmelCase_											=						DebertaTokenizerFast

							def        lowercase							(self  )     ->   str:
														super().setUp()

														# Adapted from Sennrich et al. 2015 and https://github.com/rsennrich/subword-nmt
														_snake_case   =  [
														    '''l''',
														    '''o''',
														    '''w''',
														    '''e''',
														    '''r''',
														    '''s''',
														    '''t''',
														    '''i''',
														    '''d''',
														    '''n''',
														    '''\u0120''',
														    '''\u0120l''',
														    '''\u0120n''',
														    '''\u0120lo''',
														    '''\u0120low''',
														    '''er''',
														    '''\u0120lowest''',
														    '''\u0120newer''',
														    '''\u0120wider''',
														    '''[UNK]''',
														]
														_snake_case   =  dict(zip(lowerCAmelCase__  ,  range(len(lowerCAmelCase__  )  )  )  )
														_snake_case   =  ['''#version: 0.2''', '''\u0120 l''', '''\u0120l o''', '''\u0120lo w''', '''e r''', '''''']
														_snake_case   =  {'''unk_token''': '''[UNK]'''}

														_snake_case   =  os.path.join(self.tmpdirname  ,  VOCAB_FILES_NAMES["""vocab_file"""]  )
														_snake_case   =  os.path.join(self.tmpdirname  ,  VOCAB_FILES_NAMES["""merges_file"""]  )
														with open(self.vocab_file  ,  """w"""  ,  encoding="""utf-8"""  ) as fp:
																					fp.write(json.dumps(lowerCAmelCase__  ) + """\n"""  )
														with open(self.merges_file  ,  """w"""  ,  encoding="""utf-8"""  ) as fp:
																					fp.write("""\n""".join(lowerCAmelCase__  )  )

							def        lowercase							(self  ,  **UpperCAmelCase  )     ->   Union[str, Any]:
														kwargs.update(self.special_tokens_map  )
														return self.tokenizer_class.from_pretrained(self.tmpdirname  ,  **lowerCAmelCase__  )

							def        lowercase							(self  ,  UpperCAmelCase  )     ->   Union[str, Any]:
														_snake_case   =  '''lower newer'''
														_snake_case   =  '''lower newer'''
														return input_text, output_text

							def        lowercase							(self  )     ->   Optional[int]:
														_snake_case   =  self.get_tokenizer()
														_snake_case   =  '''lower newer'''
														_snake_case   =  ['''l''', '''o''', '''w''', '''er''', '''\u0120''', '''n''', '''e''', '''w''', '''er''']
														_snake_case   =  tokenizer.tokenize(lowerCAmelCase__  )
														self.assertListEqual(lowerCAmelCase__  ,  lowerCAmelCase__  )

														_snake_case   =  tokens + [tokenizer.unk_token]
														_snake_case   =  [0, 1, 2, 15, 10, 9, 3, 2, 15, 19]
														self.assertListEqual(tokenizer.convert_tokens_to_ids(lowerCAmelCase__  )  ,  lowerCAmelCase__  )

							def        lowercase							(self  )     ->   Union[str, Any]:
														_snake_case   =  self.get_tokenizer()
														_snake_case   =  tokenizer("""Hello"""  ,  """World"""  )
														_snake_case   =  [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1]
														self.assertListEqual(tokd["""token_type_ids"""]  ,  lowerCAmelCase__  )

							@slow
							def        lowercase							(self  )     ->   List[Any]:
														_snake_case   =  self.tokenizer_class.from_pretrained("""microsoft/deberta-base"""  )

														_snake_case   =  tokenizer.encode("""sequence builders"""  ,  add_special_tokens=lowerCAmelCase__  )
														_snake_case   =  tokenizer.encode("""multi-sequence build"""  ,  add_special_tokens=lowerCAmelCase__  )

														_snake_case   =  tokenizer.encode(
														    """sequence builders"""  ,  add_special_tokens=lowerCAmelCase__  ,  add_prefix_space=lowerCAmelCase__  )
														_snake_case   =  tokenizer.encode(
														    """sequence builders"""  ,  """multi-sequence build"""  ,  add_special_tokens=lowerCAmelCase__  ,  add_prefix_space=lowerCAmelCase__  )

														_snake_case   =  tokenizer.build_inputs_with_special_tokens(lowerCAmelCase__  )
														_snake_case   =  tokenizer.build_inputs_with_special_tokens(lowerCAmelCase__  ,  lowerCAmelCase__  )

														assert encoded_sentence == encoded_text_from_decode
														assert encoded_pair == encoded_pair_from_decode





							@slow
							def        lowercase							(self  )     ->   Dict:
														_snake_case   =  [self.tokenizer_class]
														if self.test_rust_tokenizer:
																					tokenizer_classes.append(self.rust_tokenizer_class  )

														for tokenizer_class in tokenizer_classes:
																					_snake_case   =  tokenizer_class.from_pretrained("""microsoft/deberta-base"""  )

																					_snake_case   =  [
																					    '''ALBERT: A Lite BERT for Self-supervised Learning of Language Representations''',
																					    '''ALBERT incorporates two parameter reduction techniques''',
																					    '''The first one is a factorized embedding parameterization. By decomposing the large vocabulary'''
																					    ''' embedding matrix into two small matrices, we separate the size of the hidden layers from the size of'''
																					    ''' vocabulary embedding.''',
																					]

																					_snake_case   =  tokenizer(lowerCAmelCase__  ,  padding=lowerCAmelCase__  )
																					_snake_case   =  [tokenizer.decode(lowerCAmelCase__  ,  skip_special_tokens=lowerCAmelCase__  ) for seq in encoding['''input_ids''']]

																					# fmt: off
																					_snake_case   =  {
																					    '''input_ids''': [
																					        [1, 2118, 11126, 565, 35, 83, 25191, 163, 18854, 13, 12156, 12, 16101, 25376, 13807, 9, 22205, 27893, 1635, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
																					        [1, 2118, 11126, 565, 24536, 80, 43797, 4878, 7373, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
																					        [1, 133, 78, 65, 16, 10, 3724, 1538, 33183, 11303, 43797, 1938, 4, 870, 24165, 29105, 5, 739, 32644, 33183, 11303, 36173, 88, 80, 650, 7821, 45940, 6, 52, 2559, 5, 1836, 9, 5, 7397, 13171, 31, 5, 1836, 9, 32644, 33183, 11303, 4, 2]
																					    ],
																					    '''token_type_ids''': [
																					        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
																					        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
																					        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
																					    ],
																					    '''attention_mask''': [
																					        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
																					        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
																					        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
																					    ]
																					}
																					# fmt: on

																					_snake_case   =  [
																					    '''ALBERT: A Lite BERT for Self-supervised Learning of Language Representations''',
																					    '''ALBERT incorporates two parameter reduction techniques''',
																					    '''The first one is a factorized embedding parameterization. By decomposing the large vocabulary'''
																					    ''' embedding matrix into two small matrices, we separate the size of the hidden layers from the size of'''
																					    ''' vocabulary embedding.''',
																					]

																					self.assertDictEqual(encoding.data  ,  lowerCAmelCase__  )

																					for expected, decoded in zip(lowerCAmelCase__  ,  lowerCAmelCase__  ):
																												self.assertEqual(lowerCAmelCase__  ,  lowerCAmelCase__  )



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

import datasets


__lowerCAmelCase	: Optional[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'

__lowerCAmelCase	: Optional[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'

__lowerCAmelCase	: Dict  				='\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							(      lowercase__    ,       lowercase__      ):
						return float((preds == labels).mean()      )


def        _UpperCamelCase							(      lowercase__    ,       lowercase__      ):
						__SCREAMING_SNAKE_CASE						:     Optional[Any]					=		simple_accuracy(lowercase__    ,       lowercase__      )
						__SCREAMING_SNAKE_CASE						:     List[str]					=		float(fa_score(y_true=lowercase__    ,       y_pred=lowercase__      )      )
						return {
						    "accuracy": acc,
						    "f1": fa,
						}


def        _UpperCamelCase							(      lowercase__    ,       lowercase__      ):
						__SCREAMING_SNAKE_CASE						:     Optional[int]					=		np.array(lowercase__      )
						__SCREAMING_SNAKE_CASE						:     str					=		np.array(lowercase__      )
						__SCREAMING_SNAKE_CASE						:     str					=		en_sentvecs.shape[0]

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

						__SCREAMING_SNAKE_CASE						:     str					=		cdist(lowercase__    ,       lowercase__    ,       '''cosine'''      )
						__SCREAMING_SNAKE_CASE						:     int					=		np.array(range(lowercase__      )      )
						__SCREAMING_SNAKE_CASE						:     Optional[Any]					=		sim.argsort(axis=1      )[:, :10]
						__SCREAMING_SNAKE_CASE						:     str					=		np.any(preds == actual[:, None]    ,       axis=1      )
						return float(matches.mean()      )
@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION						,			_KWARGS_DESCRIPTION       )
class        _lowercase      (			datasets.Metric       ):






				'''simple docstring'''



				def 		__magic_name__(       self			:Tuple	)		->			Tuple:
										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 		__magic_name__(       self			:List[str]			,			lowerCAmelCase__			:Optional[Any]			,			lowerCAmelCase__			:Tuple	)		->			str:
										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"]'''	)
