



"""simple docstring"""


import os
import unittest

from transformers import FunnelTokenizer, FunnelTokenizerFast
from transformers.models.funnel.tokenization_funnel import VOCAB_FILES_NAMES
from transformers.testing_utils import require_tokenizers

from ...test_tokenization_common import TokenizerTesterMixin
@require_tokenizers
class 			_a (					lowerCAmelCase			,							unittest.TestCase):
			"""simple docstring"""
			UpperCamelCase__			      =	FunnelTokenizer
			UpperCamelCase__			      =	FunnelTokenizerFast
			UpperCamelCase__			      =	True
			UpperCamelCase__			      =	True



			def  lowercase__						(		self     :    int   )->int:
							super().setUp()

							_UpperCAmelCase					=    [
							    '''<unk>''',
							    '''<cls>''',
							    '''<sep>''',
							    '''want''',
							    '''##want''',
							    '''##ed''',
							    '''wa''',
							    '''un''',
							    '''runn''',
							    '''##ing''',
							    ''',''',
							    '''low''',
							    '''lowest''',
							]
							_UpperCAmelCase					=    os.path.join(self.tmpdirname				,   VOCAB_FILES_NAMES['''vocab_file''']   )
							with open(self.vocab_file				,   '''w'''				,   encoding='''utf-8'''   ) as vocab_writer:
											vocab_writer.write(''''''.join([x + '''\n''' for x in vocab_tokens]   )   )



			def  lowercase__						(		self     :    Union[str, Any]				,   **__UpperCamelCase     :    List[str]   )->int:
							return FunnelTokenizer.from_pretrained(self.tmpdirname				,   **__UpperCamelCase   )



			def  lowercase__						(		self     :    Dict				,   **__UpperCamelCase     :    str   )->Any:
							return FunnelTokenizerFast.from_pretrained(self.tmpdirname				,   **__UpperCamelCase   )



			def  lowercase__						(		self     :    str				,   __UpperCamelCase     :    List[Any]   )->Dict:
							_UpperCAmelCase					=    '''UNwant\u00E9d,running'''
							_UpperCAmelCase					=    '''unwanted, running'''
							return input_text, output_text



			def  lowercase__						(		self     :    Any   )->Union[str, Any]:
							_UpperCAmelCase					=    self.tokenizer_class(self.vocab_file   )

							_UpperCAmelCase					=    tokenizer.tokenize('''UNwant\u00E9d,running'''   )
							self.assertListEqual(__UpperCamelCase				,   ['''un''', '''##want''', '''##ed''', ''',''', '''runn''', '''##ing''']   )
							self.assertListEqual(tokenizer.convert_tokens_to_ids(__UpperCamelCase   )				,   [7, 4, 5, 1_0, 8, 9]   )



			def  lowercase__						(		self     :    str   )->Union[str, Any]:
							_UpperCAmelCase					=    self.get_tokenizers(do_lower_case=__UpperCamelCase   )
							for tokenizer in tokenizers:
											_UpperCAmelCase					=    tokenizer('''UNwant\u00E9d,running'''   )
											_UpperCAmelCase					=    len(inputs['''input_ids''']   ) - 1
											self.assertListEqual(inputs['''token_type_ids''']				,   [2] + [0] * sentence_len   )

											_UpperCAmelCase					=    tokenizer('''UNwant\u00E9d,running'''				,   '''UNwant\u00E9d,running'''   )
											self.assertListEqual(inputs['''token_type_ids''']				,   [2] + [0] * sentence_len + [1] * sentence_len   )








"""simple docstring"""


import math_equivalence  # From: git+https://github.com/hendrycks/math.git

import datasets


__A   :							Any										=   "\\n@article{hendrycksmath2021,\n  title={Measuring Mathematical Problem Solving With the MATH Dataset},\n  author={Dan Hendrycks\n    and Collin Burns\n    and Saurav Kadavath\n    and Akul Arora\n    and Steven Basart\n    and Eric Tang\n    and Dawn Song\n    and Jacob Steinhardt},\n  journal={arXiv preprint arXiv:2103.03874},\n  year={2021}\n}\n"


__A   :							Optional[Any]										=   "\\nThis metric is used to assess performance on the Mathematics Aptitude Test of Heuristics (MATH) dataset.\nIt first canonicalizes the inputs (e.g., converting \"1/2\" to \"\\frac{1}{2}\") and then computes accuracy.\n"


__A   :							Tuple										=   r"\nCalculates accuracy after canonicalizing inputs.\n\nArgs:\n    predictions: list of predictions to score. Each prediction\n        is a string that contains natural language and LaTex.\n    references: list of reference for each prediction. Each\n        reference is a string that contains natural language\n        and LaTex.\nReturns:\n    accuracy: accuracy after canonicalizing inputs\n        (e.g., converting \"1/2\" to \"\\frac{1}{2}\")\n\nExamples:\n    >>> metric = datasets.load_metric(\"competition_math\")\n    >>> results = metric.compute(references=[\"\\frac{1}{2}\"], predictions=[\"1/2\"])\n    >>> print(results)\n    {'accuracy': 1.0}\n"
@datasets.utils.file_utils.add_end_docstrings(_DESCRIPTION			,							_KWARGS_DESCRIPTION)
class 			_a (					datasets.Metric):
			"""simple docstring"""



			def  lowercase__						(		self     :    List[Any]   )->Dict:
							return datasets.MetricInfo(
							    description=_DESCRIPTION				,   citation=_CITATION				,   inputs_description=_KWARGS_DESCRIPTION				,   features=datasets.Features(
							        {
							            '''predictions''': datasets.Value('''string'''   ),
							            '''references''': datasets.Value('''string'''   ),
							        }   )				,   homepage='''https://github.com/hendrycks/math'''				,   codebase_urls=['''https://github.com/hendrycks/math''']				,   )



			def  lowercase__						(		self     :    int				,   __UpperCamelCase     :    List[str]				,   __UpperCamelCase     :    Union[str, Any]   )->Tuple:
							_UpperCAmelCase					=    0.0
							for i, j in zip(__UpperCamelCase				,   __UpperCamelCase   ):
											n_correct += 1.0 if math_equivalence.is_equiv(__UpperCamelCase				,   __UpperCamelCase   ) else 0.0
							_UpperCAmelCase					=    n_correct / len(__UpperCamelCase   )
							return {
							    "accuracy": accuracy,
							}



