"""simple docstring"""


import json
import os
import unittest

from transformers import OpenAIGPTTokenizer, OpenAIGPTTokenizerFast
from transformers.models.openai.tokenization_openai import VOCAB_FILES_NAMES
from transformers.testing_utils import require_ftfy, require_spacy, require_tokenizers

from ...test_tokenization_common import TokenizerTesterMixin


@require_tokenizers
class        a				(		UpperCamelCase__	,							unittest.TestCase   ):
    _snake_case     :  Optional[int]     							=							OpenAIGPTTokenizer
    _snake_case     :  Any     							=							OpenAIGPTTokenizerFast
    _snake_case     :  Tuple     							=							True
    _snake_case     :  Optional[int]     							=							False


    def      lowerCAmelCase_  (					self	:  Optional[Any]					):
      super().setUp()

      # Adapted from Sennrich et al. 2015 and https://github.com/rsennrich/subword-nmt
      _UpperCAmelCase						 =      [
          """l""",
          """o""",
          """w""",
          """e""",
          """r""",
          """s""",
          """t""",
          """i""",
          """d""",
          """n""",
          """w</w>""",
          """r</w>""",
          """t</w>""",
          """lo""",
          """low""",
          """er</w>""",
          """low</w>""",
          """lowest</w>""",
          """newer</w>""",
          """wider</w>""",
          """<unk>""",
      ]
      _UpperCAmelCase						 =      dict(zip(__A   ,				range(len(__A					)					)					)					)
      _UpperCAmelCase						 =      ["""#version: 0.2""", """l o""", """lo w""", """e r</w>""", """"""]

      _UpperCAmelCase						 =      os.path.join(self.tmpdirname   ,				VOCAB_FILES_NAMES["""vocab_file"""]					)
      _UpperCAmelCase						 =      os.path.join(self.tmpdirname   ,				VOCAB_FILES_NAMES["""merges_file"""]					)
      with open(self.vocab_file   ,				"""w"""					) as fp:
        fp.write(json.dumps(__A					)					)
      with open(self.merges_file   ,				"""w"""					) as fp:
        fp.write("""\n""".join(__A					)					)


    def      lowerCAmelCase_  (					self	:  Union[str, Any]   ,				__lowerCAmelCase	:  str					):
      return "lower newer", "lower newer"


    def      lowerCAmelCase_  (					self	:  Optional[Any]					):
      _UpperCAmelCase						 =      OpenAIGPTTokenizer(self.vocab_file   ,				self.merges_file					)

      _UpperCAmelCase						 =      """lower"""
      _UpperCAmelCase						 =      ["""low""", """er</w>"""]
      _UpperCAmelCase						 =      tokenizer.tokenize(__A					)
      self.assertListEqual(__A   ,				__A					)

      _UpperCAmelCase						 =      tokens + ["""<unk>"""]
      _UpperCAmelCase						 =      [14, 15, 20]
      self.assertListEqual(tokenizer.convert_tokens_to_ids(__A					)   ,				__A					)


    def      lowerCAmelCase_  (					self	:  Optional[Any]   ,				__lowerCAmelCase	:  Optional[Any]=15					):



      for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
        with self.subTest(f'''{tokenizer.__class__.__name__} ({pretrained_name})'''					):
          _UpperCAmelCase						 =      self.rust_tokenizer_class.from_pretrained(__A   ,				**__A					)

          # Simple input
          _UpperCAmelCase						 =      """This is a simple input"""
          _UpperCAmelCase						 =      ["""This is a simple input 1""", """This is a simple input 2"""]
          _UpperCAmelCase						 =      ("""This is a simple input""", """This is a pair""")
          _UpperCAmelCase						 =      [
              ("""This is a simple input 1""", """This is a simple input 2"""),
              ("""This is a simple pair 1""", """This is a simple pair 2"""),
          ]

          # Simple input tests
          self.assertRaises(__A   ,				tokenizer_r.encode   ,				__A   ,				max_length=__A   ,				padding="""max_length"""					)

          # Simple input
          self.assertRaises(__A   ,				tokenizer_r.encode_plus   ,				__A   ,				max_length=__A   ,				padding="""max_length"""					)

          # Simple input
          self.assertRaises(
              __A   ,				tokenizer_r.batch_encode_plus   ,				__A   ,				max_length=__A   ,				padding="""max_length"""   ,				)

          # Pair input
          self.assertRaises(__A   ,				tokenizer_r.encode   ,				__A   ,				max_length=__A   ,				padding="""max_length"""					)

          # Pair input
          self.assertRaises(__A   ,				tokenizer_r.encode_plus   ,				__A   ,				max_length=__A   ,				padding="""max_length"""					)

          # Pair input
          self.assertRaises(
              __A   ,				tokenizer_r.batch_encode_plus   ,				__A   ,				max_length=__A   ,				padding="""max_length"""   ,				)


    def      lowerCAmelCase_  (					self	:  Dict					):
      pass



@require_ftfy
@require_spacy
@require_tokenizers
class        a				(		UpperCamelCase__   ):
    pass

"""simple docstring"""


import datasets


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

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

UpperCAmelCase__  		=						"""
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					(			lowercase   ,lowercase		):







  """simple docstring"""
  return (preds == labels).mean()


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


    def      lowerCAmelCase_  (					self	:  Union[str, 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      lowerCAmelCase_  (					self	:  List[str]   ,				__lowerCAmelCase	:  int   ,				__lowerCAmelCase	:  Any					):
      return {"accuracy": simple_accuracy(__lowerCAmelCase   ,				__lowerCAmelCase					)}
