


import itertools
import json
import os
import unittest

from transformers import AddedToken, LongformerTokenizer, LongformerTokenizerFast
from transformers.models.longformer.tokenization_longformer import VOCAB_FILES_NAMES
from transformers.testing_utils import require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin
@require_tokenizers
class        _lowercase      (			A__						,			unittest.TestCase       ):






				'''simple docstring'''



				SCREAMING_SNAKE_CASE__				:			Optional[Any]						=		LongformerTokenizer
				SCREAMING_SNAKE_CASE__				:			Optional[Any]						=		True
				SCREAMING_SNAKE_CASE__				:			List[Any]						=		LongformerTokenizerFast
				SCREAMING_SNAKE_CASE__				:			List[str]						=		True


				def 		__magic_name__(       self			:List[str]	)		->			Union[str, Any]:
										super().setUp()

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

										__SCREAMING_SNAKE_CASE						:     Tuple					=		os.path.join(self.tmpdirname			,			VOCAB_FILES_NAMES['''vocab_file''']	)
										__SCREAMING_SNAKE_CASE						:     Tuple					=		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 		__magic_name__(       self			:Dict			,			**lowerCAmelCase__			:Any	)		->			Optional[int]:
										kwargs.update(self.special_tokens_map	)
										return self.tokenizer_class.from_pretrained(self.tmpdirname			,			**lowerCAmelCase__	)


				def 		__magic_name__(       self			:int			,			**lowerCAmelCase__			:List[Any]	)		->			str:
										kwargs.update(self.special_tokens_map	)
										return self.rust_tokenizer_class.from_pretrained(self.tmpdirname			,			**lowerCAmelCase__	)


				def 		__magic_name__(       self			:Tuple			,			lowerCAmelCase__			:int	)		->			int:
										__SCREAMING_SNAKE_CASE						:     Optional[Any]					=		'''lower newer'''
										__SCREAMING_SNAKE_CASE						:     Union[str, Any]					=		'''lower newer'''
										return input_text, output_text


				def 		__magic_name__(       self			:List[Any]	)		->			List[str]:
										__SCREAMING_SNAKE_CASE						:     List[str]					=		self.tokenizer_class(self.vocab_file			,			self.merges_file			,			**self.special_tokens_map	)
										__SCREAMING_SNAKE_CASE						:     str					=		'''lower newer'''
										__SCREAMING_SNAKE_CASE						:     int					=		['''l''', '''o''', '''w''', '''er''', '''\u0120''', '''n''', '''e''', '''w''', '''er''']
										__SCREAMING_SNAKE_CASE						:     Optional[int]					=		tokenizer.tokenize(lowerCAmelCase__	)  # , add_prefix_space=True)
										self.assertListEqual(lowerCAmelCase__			,			lowerCAmelCase__	)

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


				def 		__magic_name__(       self			:Optional[int]	)		->			List[Any]:
										__SCREAMING_SNAKE_CASE						:     Optional[Any]					=		self.get_tokenizer()

										self.assertListEqual(tokenizer.encode('''Hello world!'''			,			add_special_tokens=lowerCAmelCase__	)			,			[0, 31_414, 232, 328, 2]	)
										self.assertListEqual(
										    tokenizer.encode('''Hello world! cécé herlolip 418'''			,			add_special_tokens=lowerCAmelCase__	)			,			[0, 31_414, 232, 328, 740, 1_140, 12_695, 69, 46_078, 1_588, 2]			,			)


				@slow
				def 		__magic_name__(       self			:Union[str, Any]	)		->			List[Any]:
										__SCREAMING_SNAKE_CASE						:     Any					=		self.tokenizer_class.from_pretrained('''allenai/longformer-base-4096'''	)

										__SCREAMING_SNAKE_CASE						:     int					=		tokenizer.encode('''sequence builders'''			,			add_special_tokens=lowerCAmelCase__	)
										__SCREAMING_SNAKE_CASE						:     Union[str, Any]					=		tokenizer.encode('''multi-sequence build'''			,			add_special_tokens=lowerCAmelCase__	)

										__SCREAMING_SNAKE_CASE						:     int					=		tokenizer.encode(
										    '''sequence builders'''			,			add_special_tokens=lowerCAmelCase__			,			add_prefix_space=lowerCAmelCase__	)
										__SCREAMING_SNAKE_CASE						:     List[Any]					=		tokenizer.encode(
										    '''sequence builders'''			,			'''multi-sequence build'''			,			add_special_tokens=lowerCAmelCase__			,			add_prefix_space=lowerCAmelCase__	)

										__SCREAMING_SNAKE_CASE						:     int					=		tokenizer.build_inputs_with_special_tokens(lowerCAmelCase__	)
										__SCREAMING_SNAKE_CASE						:     str					=		tokenizer.build_inputs_with_special_tokens(lowerCAmelCase__			,			lowerCAmelCase__	)

										assert encoded_sentence == encoded_text_from_decode
										assert encoded_pair == encoded_pair_from_decode


				def 		__magic_name__(       self			:Tuple	)		->			Tuple:
										__SCREAMING_SNAKE_CASE						:     List[str]					=		self.get_tokenizer()

										__SCREAMING_SNAKE_CASE						:     Optional[int]					=		'''Encode this sequence.'''
										__SCREAMING_SNAKE_CASE						:     List[str]					=		tokenizer.byte_encoder[''' '''.encode('''utf-8'''	)[0]]

										# Testing encoder arguments
										__SCREAMING_SNAKE_CASE						:     int					=		tokenizer.encode(lowerCAmelCase__			,			add_special_tokens=lowerCAmelCase__			,			add_prefix_space=lowerCAmelCase__	)
										__SCREAMING_SNAKE_CASE						:     Tuple					=		tokenizer.convert_ids_to_tokens(encoded[0]	)[0]
										self.assertNotEqual(lowerCAmelCase__			,			lowerCAmelCase__	)

										__SCREAMING_SNAKE_CASE						:     Tuple					=		tokenizer.encode(lowerCAmelCase__			,			add_special_tokens=lowerCAmelCase__			,			add_prefix_space=lowerCAmelCase__	)
										__SCREAMING_SNAKE_CASE						:     int					=		tokenizer.convert_ids_to_tokens(encoded[0]	)[0]
										self.assertEqual(lowerCAmelCase__			,			lowerCAmelCase__	)

										tokenizer.add_special_tokens({'''bos_token''': '''<s>'''}	)
										__SCREAMING_SNAKE_CASE						:     List[str]					=		tokenizer.encode(lowerCAmelCase__			,			add_special_tokens=lowerCAmelCase__	)
										__SCREAMING_SNAKE_CASE						:     str					=		tokenizer.convert_ids_to_tokens(encoded[1]	)[0]
										self.assertNotEqual(lowerCAmelCase__			,			lowerCAmelCase__	)

										# Testing spaces after special tokens
										__SCREAMING_SNAKE_CASE						:     Optional[Any]					=		'''<mask>'''
										tokenizer.add_special_tokens(
										    {'''mask_token''': AddedToken(lowerCAmelCase__			,			lstrip=lowerCAmelCase__			,			rstrip=lowerCAmelCase__	)}	)  # mask token has a left space
										__SCREAMING_SNAKE_CASE						:     str					=		tokenizer.convert_tokens_to_ids(lowerCAmelCase__	)

										__SCREAMING_SNAKE_CASE						:     Dict					=		'''Encode <mask> sequence'''
										__SCREAMING_SNAKE_CASE						:     Any					=		'''Encode <mask>sequence'''

										__SCREAMING_SNAKE_CASE						:     Optional[Any]					=		tokenizer.encode(lowerCAmelCase__	)
										__SCREAMING_SNAKE_CASE						:     Tuple					=		encoded.index(lowerCAmelCase__	)
										__SCREAMING_SNAKE_CASE						:     List[Any]					=		tokenizer.convert_ids_to_tokens(encoded[mask_loc + 1]	)[0]
										self.assertEqual(lowerCAmelCase__			,			lowerCAmelCase__	)

										__SCREAMING_SNAKE_CASE						:     List[Any]					=		tokenizer.encode(lowerCAmelCase__	)
										__SCREAMING_SNAKE_CASE						:     Dict					=		encoded.index(lowerCAmelCase__	)
										__SCREAMING_SNAKE_CASE						:     Dict					=		tokenizer.convert_ids_to_tokens(encoded[mask_loc + 1]	)[0]
										self.assertNotEqual(lowerCAmelCase__			,			lowerCAmelCase__	)


				def 		__magic_name__(       self			:Optional[Any]	)		->			List[Any]:
										pass


				def 		__magic_name__(       self			:int	)		->			Any:
										for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
																with self.subTest(f'''{tokenizer.__class__.__name__} ({pretrained_name})'''	):
																						__SCREAMING_SNAKE_CASE						:     Tuple					=		self.rust_tokenizer_class.from_pretrained(lowerCAmelCase__			,			**lowerCAmelCase__	)
																						__SCREAMING_SNAKE_CASE						:     Union[str, Any]					=		self.tokenizer_class.from_pretrained(lowerCAmelCase__			,			**lowerCAmelCase__	)
																						__SCREAMING_SNAKE_CASE						:     List[Any]					=		'''A, <mask> AllenNLP sentence.'''
																						__SCREAMING_SNAKE_CASE						:     str					=		tokenizer_r.encode_plus(lowerCAmelCase__			,			add_special_tokens=lowerCAmelCase__			,			return_token_type_ids=lowerCAmelCase__	)
																						__SCREAMING_SNAKE_CASE						:     Tuple					=		tokenizer_p.encode_plus(lowerCAmelCase__			,			add_special_tokens=lowerCAmelCase__			,			return_token_type_ids=lowerCAmelCase__	)

																						# token_type_ids should put 0 everywhere
																						self.assertEqual(sum(tokens_r['''token_type_ids''']	)			,			sum(tokens_p['''token_type_ids''']	)	)

																						# attention_mask should put 1 everywhere, so sum over length should be 1
																						self.assertEqual(
																						    sum(tokens_r['''attention_mask''']	) / len(tokens_r['''attention_mask''']	)			,			sum(tokens_p['''attention_mask''']	) / len(tokens_p['''attention_mask''']	)			,			)

																						__SCREAMING_SNAKE_CASE						:     str					=		tokenizer_r.convert_ids_to_tokens(tokens_r['''input_ids''']	)
																						__SCREAMING_SNAKE_CASE						:     Optional[int]					=		tokenizer_p.convert_ids_to_tokens(tokens_p['''input_ids''']	)

																						# Rust correctly handles the space before the mask while python doesnt
																						self.assertSequenceEqual(tokens_p['''input_ids''']			,			[0, 250, 6, 50_264, 3_823, 487, 21_992, 3_645, 4, 2]	)
																						self.assertSequenceEqual(tokens_r['''input_ids''']			,			[0, 250, 6, 50_264, 3_823, 487, 21_992, 3_645, 4, 2]	)

																						self.assertSequenceEqual(
																						    lowerCAmelCase__			,			['''<s>''', '''A''', ''',''', '''<mask>''', '''ĠAllen''', '''N''', '''LP''', '''Ġsentence''', '''.''', '''</s>''']	)
																						self.assertSequenceEqual(
																						    lowerCAmelCase__			,			['''<s>''', '''A''', ''',''', '''<mask>''', '''ĠAllen''', '''N''', '''LP''', '''Ġsentence''', '''.''', '''</s>''']	)


				def 		__magic_name__(       self			:Optional[int]	)		->			Any:
										for trim_offsets, add_prefix_space in itertools.product([True, False]			,			repeat=2	):
																__SCREAMING_SNAKE_CASE						:     Any					=		self.rust_tokenizer_class.from_pretrained(
																    self.tmpdirname			,			use_fast=lowerCAmelCase__			,			add_prefix_space=lowerCAmelCase__			,			trim_offsets=lowerCAmelCase__	)

																__SCREAMING_SNAKE_CASE						:     Dict					=		json.loads(tokenizer_r.backend_tokenizer.pre_tokenizer.__getstate__()	)
																__SCREAMING_SNAKE_CASE						:     List[Any]					=		json.loads(tokenizer_r.backend_tokenizer.post_processor.__getstate__()	)

																self.assertEqual(pre_tokenizer_state['''add_prefix_space''']			,			lowerCAmelCase__	)

																self.assertEqual(post_processor_state['''add_prefix_space''']			,			lowerCAmelCase__	)
																self.assertEqual(post_processor_state['''trim_offsets''']			,			lowerCAmelCase__	)



				def 		__magic_name__(       self			:Any	)		->			List[Any]:
										# Test which aims to verify that the offsets are well adapted to the argument `add_prefix_space` and
										# `trim_offsets`
										for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
																with self.subTest(f'''{tokenizer.__class__.__name__} ({pretrained_name})'''	):
																						__SCREAMING_SNAKE_CASE						:     Optional[Any]					=		'''hello'''  # `hello` is a token in the vocabulary of `pretrained_name`
																						__SCREAMING_SNAKE_CASE						:     Optional[int]					=		f'''{text_of_1_token} {text_of_1_token}'''

																						__SCREAMING_SNAKE_CASE						:     List[Any]					=		self.rust_tokenizer_class.from_pretrained(
																						    lowerCAmelCase__			,			use_fast=lowerCAmelCase__			,			add_prefix_space=lowerCAmelCase__			,			trim_offsets=lowerCAmelCase__	)
																						__SCREAMING_SNAKE_CASE						:     str					=		tokenizer_r(lowerCAmelCase__			,			return_offsets_mapping=lowerCAmelCase__			,			add_special_tokens=lowerCAmelCase__	)
																						self.assertEqual(encoding.offset_mapping[0]			,			(0, len(lowerCAmelCase__	))	)
																						self.assertEqual(
																						    encoding.offset_mapping[1]			,			(len(lowerCAmelCase__	) + 1, len(lowerCAmelCase__	) + 1 + len(lowerCAmelCase__	))			,			)

																						__SCREAMING_SNAKE_CASE						:     str					=		self.rust_tokenizer_class.from_pretrained(
																						    lowerCAmelCase__			,			use_fast=lowerCAmelCase__			,			add_prefix_space=lowerCAmelCase__			,			trim_offsets=lowerCAmelCase__	)
																						__SCREAMING_SNAKE_CASE						:     List[Any]					=		tokenizer_r(lowerCAmelCase__			,			return_offsets_mapping=lowerCAmelCase__			,			add_special_tokens=lowerCAmelCase__	)
																						self.assertEqual(encoding.offset_mapping[0]			,			(0, len(lowerCAmelCase__	))	)
																						self.assertEqual(
																						    encoding.offset_mapping[1]			,			(len(lowerCAmelCase__	) + 1, len(lowerCAmelCase__	) + 1 + len(lowerCAmelCase__	))			,			)

																						__SCREAMING_SNAKE_CASE						:     Dict					=		self.rust_tokenizer_class.from_pretrained(
																						    lowerCAmelCase__			,			use_fast=lowerCAmelCase__			,			add_prefix_space=lowerCAmelCase__			,			trim_offsets=lowerCAmelCase__	)
																						__SCREAMING_SNAKE_CASE						:     Dict					=		tokenizer_r(lowerCAmelCase__			,			return_offsets_mapping=lowerCAmelCase__			,			add_special_tokens=lowerCAmelCase__	)
																						self.assertEqual(encoding.offset_mapping[0]			,			(0, len(lowerCAmelCase__	))	)
																						self.assertEqual(
																						    encoding.offset_mapping[1]			,			(len(lowerCAmelCase__	), len(lowerCAmelCase__	) + 1 + len(lowerCAmelCase__	))			,			)

																						__SCREAMING_SNAKE_CASE						:     List[Any]					=		self.rust_tokenizer_class.from_pretrained(
																						    lowerCAmelCase__			,			use_fast=lowerCAmelCase__			,			add_prefix_space=lowerCAmelCase__			,			trim_offsets=lowerCAmelCase__	)
																						__SCREAMING_SNAKE_CASE						:     Union[str, Any]					=		tokenizer_r(lowerCAmelCase__			,			return_offsets_mapping=lowerCAmelCase__			,			add_special_tokens=lowerCAmelCase__	)
																						self.assertEqual(encoding.offset_mapping[0]			,			(0, len(lowerCAmelCase__	))	)
																						self.assertEqual(
																						    encoding.offset_mapping[1]			,			(len(lowerCAmelCase__	), len(lowerCAmelCase__	) + 1 + len(lowerCAmelCase__	))			,			)

																						__SCREAMING_SNAKE_CASE						:     List[Any]					=		f''' {text}'''

																						# tokenizer_r = self.rust_tokenizer_class.from_pretrained(
																						#     pretrained_name, use_fast=True, add_prefix_space=True, trim_offsets=True
																						# )
																						# encoding = tokenizer_r(text, return_offsets_mapping=True, add_special_tokens=False)
																						# self.assertEqual(encoding.offset_mapping[0], (1, 1 + len(text_of_1_token)))
																						# self.assertEqual(
																						#     encoding.offset_mapping[1],
																						#     (1 + len(text_of_1_token) + 1, 1 + len(text_of_1_token) + 1 + len(text_of_1_token)),
																						# )

																						__SCREAMING_SNAKE_CASE						:     Optional[Any]					=		self.rust_tokenizer_class.from_pretrained(
																						    lowerCAmelCase__			,			use_fast=lowerCAmelCase__			,			add_prefix_space=lowerCAmelCase__			,			trim_offsets=lowerCAmelCase__	)
																						__SCREAMING_SNAKE_CASE						:     Optional[Any]					=		tokenizer_r(lowerCAmelCase__			,			return_offsets_mapping=lowerCAmelCase__			,			add_special_tokens=lowerCAmelCase__	)
																						self.assertEqual(encoding.offset_mapping[0]			,			(1, 1 + len(lowerCAmelCase__	))	)
																						self.assertEqual(
																						    encoding.offset_mapping[1]			,			(1 + len(lowerCAmelCase__	) + 1, 1 + len(lowerCAmelCase__	) + 1 + len(lowerCAmelCase__	))			,			)

																						__SCREAMING_SNAKE_CASE						:     Tuple					=		self.rust_tokenizer_class.from_pretrained(
																						    lowerCAmelCase__			,			use_fast=lowerCAmelCase__			,			add_prefix_space=lowerCAmelCase__			,			trim_offsets=lowerCAmelCase__	)
																						__SCREAMING_SNAKE_CASE						:     List[Any]					=		tokenizer_r(lowerCAmelCase__			,			return_offsets_mapping=lowerCAmelCase__			,			add_special_tokens=lowerCAmelCase__	)
																						self.assertEqual(encoding.offset_mapping[0]			,			(0, 1 + len(lowerCAmelCase__	))	)
																						self.assertEqual(
																						    encoding.offset_mapping[1]			,			(1 + len(lowerCAmelCase__	), 1 + len(lowerCAmelCase__	) + 1 + len(lowerCAmelCase__	))			,			)

																						__SCREAMING_SNAKE_CASE						:     Dict					=		self.rust_tokenizer_class.from_pretrained(
																						    lowerCAmelCase__			,			use_fast=lowerCAmelCase__			,			add_prefix_space=lowerCAmelCase__			,			trim_offsets=lowerCAmelCase__	)
																						__SCREAMING_SNAKE_CASE						:     Any					=		tokenizer_r(lowerCAmelCase__			,			return_offsets_mapping=lowerCAmelCase__			,			add_special_tokens=lowerCAmelCase__	)
																						self.assertEqual(encoding.offset_mapping[0]			,			(0, 1 + len(lowerCAmelCase__	))	)
																						self.assertEqual(
																						    encoding.offset_mapping[1]			,			(1 + len(lowerCAmelCase__	), 1 + len(lowerCAmelCase__	) + 1 + len(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"]'''	)
