



"""simple docstring"""







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 						_A  (  _a   ,unittest.TestCase  ):







    """simple docstring"""




    UpperCAmelCase	:							List[Any]     =	MgpstrTokenizer
    UpperCAmelCase	:							int     =	False
    UpperCAmelCase	:							int     =	{}
    UpperCAmelCase	:							List[str]     =	False






    def      __snake_case							( self    :   Optional[int]):
      super().setUp()

      # fmt: off
      a						:		Any											=      ['[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						:		int											=      dict(zip(_A    ,			range(len(_A))))

      a						:		int											=      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      __snake_case							( self    :   Union[str, Any]    ,			**__UpperCAmelCase    :   str):
      return MgpstrTokenizer.from_pretrained(self.tmpdirname    ,			**_A)






    def      __snake_case							( self    :   Tuple    ,			__UpperCAmelCase    :   Optional[int]):
      a						:		Optional[Any]											=      'tester'
      a						:		Dict											=      'tester'
      return input_text, output_text






    @unittest.skip("MGP-STR always lower cases letters.")
    def      __snake_case							( self    :   Union[str, Any]):
      pass






    def      __snake_case							( self    :   str):
      a						:		Optional[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						:		Optional[Any]											=      tokenizer.encode([special_token]    ,			add_special_tokens=_A)
          self.assertEqual(len(_A)    ,			1)

          a						:		Optional[Any]											=      tokenizer.decode(_A    ,			skip_special_tokens=_A)
          self.assertTrue(special_token not in decoded)






    def      __snake_case							( self    :   Optional[Any]):
      a						:		Any											=      self.get_tokenizers()
      for tokenizer in tokenizers:
        with self.subTest(f'''{tokenizer.__class__.__name__}'''):
          a						:		Optional[Any]											=      self.get_input_output_texts(_A)

          a						:		List[Any]											=      tokenizer.tokenize(_A)
          a						:		str											=      tokenizer.convert_tokens_to_ids(_A)
          a						:		Any											=      tokenizer.encode(_A    ,			add_special_tokens=_A)
          self.assertListEqual(_A    ,			_A)

          a						:		Tuple											=      tokenizer.convert_ids_to_tokens(_A)
          self.assertNotEqual(len(_A)    ,			0)
          a						:		List[str]											=      tokenizer.decode(_A)
          self.assertIsInstance(_A    ,			_A)

          self.assertEqual(text_a.replace(" "    ,			"")    ,			_A)






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






    @unittest.skip("inputs cannot be pretokenized in MgpstrTokenizer")
    def      __snake_case							( self    :   Any):
      pass










"""simple docstring"""







import datasets


__lowercase    =				"""\
@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\",
}
"""

__lowercase    =				"""\
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).
"""

__lowercase    =				"""
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 					lowercase      (    A_  ,       A_	)->				List[str]:
  '''simple docstring'''







  return (preds == labels).mean()







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







    """simple docstring"""




    def      __snake_case							( self    :   List[str]):
      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      __snake_case							( self    :   str    ,			__UpperCAmelCase    :   List[Any]    ,			__UpperCAmelCase    :   Tuple):
      return {"accuracy": simple_accuracy(__UpperCAmelCase    ,			__UpperCAmelCase)}






