

import datasets


a__												=						'''\
@InProceedings{conneau2018xnli,
  author = "Conneau, Alexis
                 and Rinott, Ruty
                 and Lample, Guillaume
                 and Williams, Adina
                 and Bowman, Samuel R.
                 and Schwenk, Holger
                 and Stoyanov, Veselin",
  title = "XNLI: Evaluating Cross-lingual Sentence Representations",
  booktitle = "Proceedings of the 2018 Conference on Empirical Methods
               in Natural Language Processing",
  year = "2018",
  publisher = "Association for Computational Linguistics",
  location = "Brussels, Belgium",
}
'''

a__												=						'''\
XNLI is a subset of a few thousand examples from MNLI which has been translated
into a 14 different languages (some low-ish resource). As with MNLI, the goal is
to predict textual entailment (does sentence A imply/contradict/neither sentence
B) and is a classification task (given two sentences, predict one of three
labels).
'''

a__												=						'''
Computes XNLI score which is just simple accuracy.
Args:
    predictions: Predicted labels.
    references: Ground truth labels.
Returns:
    \'accuracy\': accuracy
Examples:

    >>> predictions = [0, 1]
    >>> references = [0, 1]
    >>> xnli_metric = datasets.load_metric("xnli")
    >>> results = xnli_metric.compute(predictions=predictions, references=references)
    >>> print(results)
    {\'accuracy\': 1.0}
'''



def   __UpperCAmelCase					(      __a :     Optional[int]						,__a :     int      )     ->	Optional[int]:

					"""simple docstring"""

					return (preds == labels).mean()







@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION							,			_KWARGS_DESCRIPTION  )
class 							UpperCAmelCase_						(     datasets.Metric  ):
							"""simple docstring"""







							def 							__lowercase							(     self			)       ->       List[Any]:
												return datasets.MetricInfo(
												    description=_DESCRIPTION			,				citation=_CITATION			,				inputs_description=_KWARGS_DESCRIPTION			,				features=datasets.Features(
												        {
												            '''predictions''': datasets.Value('''int64''' if self.config_name != '''sts-b''' else '''float32'''			),
												            '''references''': datasets.Value('''int64''' if self.config_name != '''sts-b''' else '''float32'''			),
												        }			)			,				codebase_urls=[]			,				reference_urls=[]			,				format='''numpy'''			,				)




							def 							__lowercase							(     self			,				_a			,				_a			)       ->       Optional[Any]:
												return {"accuracy": simple_accuracy(_a			,				_a			)}






import json
import os
import unittest

from transformers import MgpstrTokenizer
from transformers.models.mgp_str.tokenization_mgp_str import VOCAB_FILES_NAMES
from transformers.testing_utils import require_tokenizers

from ...test_tokenization_common import TokenizerTesterMixin

@require_tokenizers
class 							UpperCAmelCase_						(     __lowercase							,			unittest.TestCase  ):
							"""simple docstring"""







							UpperCAmelCase__			:		List[Any]             =       MgpstrTokenizer
							UpperCAmelCase__			:		int             =       False
							UpperCAmelCase__			:		Union[str, Any]             =       {}
							UpperCAmelCase__			:		List[Any]             =       False


							def 							__lowercase							(     self			)       ->       Any:
												super().setUp()

												# fmt: off
												_a      :       Tuple   =						['''[GO]''', '''[s]''', '''0''', '''1''', '''2''', '''3''', '''4''', '''5''', '''6''', '''7''', '''8''', '''9''', '''a''', '''b''', '''c''', '''d''', '''e''', '''f''', '''g''', '''h''', '''i''', '''j''', '''k''', '''l''', '''m''', '''n''', '''o''', '''p''', '''q''', '''r''', '''s''', '''t''', '''u''', '''v''', '''w''', '''x''', '''y''', '''z''']
												# fmt: on
												_a      :       Optional[int]   =						dict(zip(_a			,				range(len(_a			)			)			)			)

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


							def 							__lowercase							(     self			,				**_a			)       ->       Dict:
												return MgpstrTokenizer.from_pretrained(self.tmpdirname			,				**_a			)


							def 							__lowercase							(     self			,				_a			)       ->       Tuple:
												_a      :       List[str]   =						'''tester'''
												_a      :       Optional[Any]   =						'''tester'''
												return input_text, output_text


							@unittest.skip('''MGP-STR always lower cases letters.'''			)
							def 							__lowercase							(     self			)       ->       Any:
												pass


							def 							__lowercase							(     self			)       ->       Any:
												_a      :       Union[str, Any]   =						self.get_tokenizers(do_lower_case=_a			)
												for tokenizer in tokenizers:
																	with self.subTest(F"""{tokenizer.__class__.__name__}"""			):
																						_a      :       int   =						'''[SPECIAL_TOKEN]'''

																						tokenizer.add_special_tokens({'''cls_token''': special_token}			)
																						_a      :       Tuple   =						tokenizer.encode([special_token]			,				add_special_tokens=_a			)
																						self.assertEqual(len(_a			)			,				1			)

																						_a      :       Tuple   =						tokenizer.decode(_a			,				skip_special_tokens=_a			)
																						self.assertTrue(special_token not in decoded			)


							def 							__lowercase							(     self			)       ->       Tuple:
												_a      :       List[Any]   =						self.get_tokenizers()
												for tokenizer in tokenizers:
																	with self.subTest(F"""{tokenizer.__class__.__name__}"""			):
																						_a ,   _a      :       int   =						self.get_input_output_texts(_a			)

																						_a      :       List[str]   =						tokenizer.tokenize(_a			)
																						_a      :       Optional[int]   =						tokenizer.convert_tokens_to_ids(_a			)
																						_a      :       Tuple   =						tokenizer.encode(_a			,				add_special_tokens=_a			)
																						self.assertListEqual(_a			,				_a			)

																						_a      :       Optional[int]   =						tokenizer.convert_ids_to_tokens(_a			)
																						self.assertNotEqual(len(_a			)			,				0			)
																						_a      :       int   =						tokenizer.decode(_a			)
																						self.assertIsInstance(_a			,				_a			)

																						self.assertEqual(text_a.replace(''' '''			,				''''''			)			,				_a			)


							@unittest.skip('''MGP-STR tokenizer only handles one sequence.'''			)
							def 							__lowercase							(     self			)       ->       List[str]:
												pass




							@unittest.skip('''inputs cannot be pretokenized in MgpstrTokenizer'''			)
							def 							__lowercase							(     self			)       ->       Optional[Any]:
												pass



