






'''simple docstring'''




import warnings

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding

class    _UpperCAmelCase			(     snake_case_						):




   """simple docstring"""

   snake_case    				=						['''image_processor''', '''tokenizer''']
   snake_case    				=						'''CLIPImageProcessor'''
   snake_case    				=						('''XLMRobertaTokenizer''', '''XLMRobertaTokenizerFast''')

   def __init__(		self :	Any      ,      __UpperCAmelCase :	List[Any]=None      ,      __UpperCAmelCase :	List[Any]=None      ,      **__UpperCAmelCase :	str		):





         '''simple docstring'''





         _A			     =	None
         if "feature_extractor" in kwargs:
               warnings.warn(
                   "The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`"
                   " instead."      ,      __UpperCAmelCase      ,      )
               _A			     =	kwargs.pop("feature_extractor"		)

         _A			     =	image_processor if image_processor is not None else feature_extractor
         if image_processor is None:
               raise ValueError("You need to specify an `image_processor`."		)
         if tokenizer is None:
               raise ValueError("You need to specify a `tokenizer`."		)

         super().__init__(__UpperCAmelCase      ,      __UpperCAmelCase		)

   def __call__(		self :	Any      ,      __UpperCAmelCase :	int=None      ,      __UpperCAmelCase :	Tuple=None      ,      __UpperCAmelCase :	List[Any]=None      ,      **__UpperCAmelCase :	List[Any]		):





         '''simple docstring'''





         if text is None and images is None:
               raise ValueError("You have to specify either text or images. Both cannot be none."		)

         if text is not None:
               _A			     =	self.tokenizer(__UpperCAmelCase      ,      return_tensors=__UpperCAmelCase      ,      **__UpperCAmelCase		)

         if images is not None:
               _A			     =	self.image_processor(__UpperCAmelCase      ,      return_tensors=__UpperCAmelCase      ,      **__UpperCAmelCase		)

         if text is not None and images is not None:
               _A			     =	image_features.pixel_values
               return encoding
         elif text is not None:
               return encoding
         else:
               return BatchEncoding(data=dict(**__UpperCAmelCase		)      ,      tensor_type=__UpperCAmelCase		)

   def 						lowerCAmelCase (		self :	List[str]      ,      *__UpperCAmelCase :	Tuple      ,      **__UpperCAmelCase :	List[Any]		):





         '''simple docstring'''





         return self.tokenizer.batch_decode(*__UpperCAmelCase      ,      **__UpperCAmelCase		)

   def 						lowerCAmelCase (		self :	Optional[int]      ,      *__UpperCAmelCase :	Any      ,      **__UpperCAmelCase :	Any		):





         '''simple docstring'''





         return self.tokenizer.decode(*__UpperCAmelCase      ,      **__UpperCAmelCase		)

   @property
   def 						lowerCAmelCase (		self :	List[Any]		):





         '''simple docstring'''





         _A			     =	self.tokenizer.model_input_names
         _A			     =	self.image_processor.model_input_names
         return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names		)		)









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

import datasets


__lowerCAmelCase	: Optional[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'


__lowerCAmelCase	: 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'


__lowerCAmelCase	: Optional[Any]  				=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        _lowercase      (			datasets.Metric       ):






				'''simple docstring'''



				def 		__magic_name__(       self			:Optional[Any]	)		->			List[str]:
										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 		__magic_name__(       self			:Any			,			lowerCAmelCase__			:Optional[int]			,			lowerCAmelCase__			:Any	)		->			Optional[int]:
										__SCREAMING_SNAKE_CASE						:     Tuple					=		0.0
										for i, j in zip(lowerCAmelCase__			,			lowerCAmelCase__	):
																n_correct += 1.0 if math_equivalence.is_equiv(lowerCAmelCase__			,			lowerCAmelCase__	) else 0.0
										__SCREAMING_SNAKE_CASE						:     str					=		n_correct / len(lowerCAmelCase__	)
										return {
										    "accuracy": accuracy,
										}
