'''simple docstring'''





from __future__ import annotations

import unittest

from transformers import DebertaVaConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
    import tensorflow as tf

    from transformers import (
        TFDebertaVaForMaskedLM,
        TFDebertaVaForQuestionAnswering,
        TFDebertaVaForSequenceClassification,
        TFDebertaVaForTokenClassification,
        TFDebertaVaModel,
    )




class        __A      :



    def __init__(self    :    Dict   ,			__a    :    List[str]   ,			__a    :    Union[str, Any]=13   ,			__a    :    Optional[int]=7   ,			__a    :    Tuple=True   ,			__a    :    Any=True   ,			__a    :    List[Any]=True   ,			__a    :    List[str]=True   ,			__a    :    Optional[Any]=99   ,			__a    :    Dict=32   ,			__a    :    Tuple=2   ,			__a    :    Dict=4   ,			__a    :    Dict=37   ,			__a    :    int="gelu"   ,			__a    :    Tuple=0.1   ,			__a    :    Optional[int]=0.1   ,			__a    :    Union[str, Any]=512   ,			__a    :    str=16   ,			__a    :    Any=2   ,			__a    :    Optional[Any]=0.02   ,			__a    :    int=False   ,			__a    :    Any=True   ,			__a    :    int="None"   ,			__a    :    str=3   ,			__a    :    List[Any]=4   ,			__a    :    int=None   ,			):
         UpperCAmelCase_           =   parent
         UpperCAmelCase_           =   batch_size
         UpperCAmelCase_           =   seq_length
         UpperCAmelCase_           =   is_training
         UpperCAmelCase_           =   use_input_mask
         UpperCAmelCase_           =   use_token_type_ids
         UpperCAmelCase_           =   use_labels
         UpperCAmelCase_           =   vocab_size
         UpperCAmelCase_           =   hidden_size
         UpperCAmelCase_           =   num_hidden_layers
         UpperCAmelCase_           =   num_attention_heads
         UpperCAmelCase_           =   intermediate_size
         UpperCAmelCase_           =   hidden_act
         UpperCAmelCase_           =   hidden_dropout_prob
         UpperCAmelCase_           =   attention_probs_dropout_prob
         UpperCAmelCase_           =   max_position_embeddings
         UpperCAmelCase_           =   type_vocab_size
         UpperCAmelCase_           =   type_sequence_label_size
         UpperCAmelCase_           =   initializer_range
         UpperCAmelCase_           =   num_labels
         UpperCAmelCase_           =   num_choices
         UpperCAmelCase_           =   relative_attention
         UpperCAmelCase_           =   position_biased_input
         UpperCAmelCase_           =   pos_att_type
         UpperCAmelCase_           =   scope



    def 					_lowercase						(self    :    Optional[Any] ):
         UpperCAmelCase_           =   ids_tensor([self.batch_size, self.seq_length]   ,			self.vocab_size )

         UpperCAmelCase_           =   None
         if self.use_input_mask:
              UpperCAmelCase_           =   random_attention_mask([self.batch_size, self.seq_length] )

         UpperCAmelCase_           =   None
         if self.use_token_type_ids:
              UpperCAmelCase_           =   ids_tensor([self.batch_size, self.seq_length]   ,			self.type_vocab_size )

         UpperCAmelCase_           =   None
         UpperCAmelCase_           =   None
         UpperCAmelCase_           =   None
         if self.use_labels:
              UpperCAmelCase_           =   ids_tensor([self.batch_size]   ,			self.type_sequence_label_size )
              UpperCAmelCase_           =   ids_tensor([self.batch_size, self.seq_length]   ,			self.num_labels )

         UpperCAmelCase_           =   DebertaVaConfig(
             vocab_size=self.vocab_size   ,			hidden_size=self.hidden_size   ,			num_hidden_layers=self.num_hidden_layers   ,			num_attention_heads=self.num_attention_heads   ,			intermediate_size=self.intermediate_size   ,			hidden_act=self.hidden_act   ,			hidden_dropout_prob=self.hidden_dropout_prob   ,			attention_probs_dropout_prob=self.attention_probs_dropout_prob   ,			max_position_embeddings=self.max_position_embeddings   ,			type_vocab_size=self.type_vocab_size   ,			relative_attention=self.relative_attention   ,			position_biased_input=self.position_biased_input   ,			initializer_range=self.initializer_range   ,			return_dict=__a   ,			)

         return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels



    def 					_lowercase						(self    :    Optional[Any]   ,			__a    :    Dict   ,			__a    :    List[Any]   ,			__a    :    str   ,			__a    :    str   ,			__a    :    int   ,			__a    :    int   ,			__a    :    Tuple ):
         UpperCAmelCase_           =   TFDebertaVaModel(config=__a )
         UpperCAmelCase_           =   {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}

         UpperCAmelCase_           =   [input_ids, input_mask]
         UpperCAmelCase_           =   model(__a )

         UpperCAmelCase_           =   model(__a )

         self.parent.assertEqual(result.last_hidden_state.shape   ,			(self.batch_size, self.seq_length, self.hidden_size) )



    def 					_lowercase						(self    :    Optional[int]   ,			__a    :    Tuple   ,			__a    :    Optional[Any]   ,			__a    :    int   ,			__a    :    Dict   ,			__a    :    str   ,			__a    :    Any   ,			__a    :    Any ):
         UpperCAmelCase_           =   TFDebertaVaForMaskedLM(config=__a )
         UpperCAmelCase_           =   {
             "input_ids": input_ids,
             "attention_mask": input_mask,
             "token_type_ids": token_type_ids,
         }
         UpperCAmelCase_           =   model(__a )
         self.parent.assertEqual(result.logits.shape   ,			(self.batch_size, self.seq_length, self.vocab_size) )



    def 					_lowercase						(self    :    Optional[Any]   ,			__a    :    int   ,			__a    :    Any   ,			__a    :    Optional[Any]   ,			__a    :    Dict   ,			__a    :    Dict   ,			__a    :    Tuple   ,			__a    :    str ):
         UpperCAmelCase_           =   self.num_labels
         UpperCAmelCase_           =   TFDebertaVaForSequenceClassification(config=__a )
         UpperCAmelCase_           =   {
             "input_ids": input_ids,
             "attention_mask": input_mask,
             "token_type_ids": token_type_ids,
         }

         UpperCAmelCase_           =   model(__a )
         self.parent.assertEqual(result.logits.shape   ,			(self.batch_size, self.num_labels) )



    def 					_lowercase						(self    :    Tuple   ,			__a    :    List[Any]   ,			__a    :    str   ,			__a    :    Dict   ,			__a    :    Tuple   ,			__a    :    int   ,			__a    :    Tuple   ,			__a    :    List[str] ):
         UpperCAmelCase_           =   self.num_labels
         UpperCAmelCase_           =   TFDebertaVaForTokenClassification(config=__a )
         UpperCAmelCase_           =   {
             "input_ids": input_ids,
             "attention_mask": input_mask,
             "token_type_ids": token_type_ids,
         }
         UpperCAmelCase_           =   model(__a )
         self.parent.assertEqual(result.logits.shape   ,			(self.batch_size, self.seq_length, self.num_labels) )



    def 					_lowercase						(self    :    Optional[Any]   ,			__a    :    Optional[int]   ,			__a    :    Tuple   ,			__a    :    Optional[Any]   ,			__a    :    Any   ,			__a    :    Union[str, Any]   ,			__a    :    Union[str, Any]   ,			__a    :    int ):
         UpperCAmelCase_           =   TFDebertaVaForQuestionAnswering(config=__a )
         UpperCAmelCase_           =   {
             "input_ids": input_ids,
             "attention_mask": input_mask,
             "token_type_ids": token_type_ids,
         }

         UpperCAmelCase_           =   model(__a )
         self.parent.assertEqual(result.start_logits.shape   ,			(self.batch_size, self.seq_length) )
         self.parent.assertEqual(result.end_logits.shape   ,			(self.batch_size, self.seq_length) )






    def 					_lowercase						(self    :    List[str] ):
         UpperCAmelCase_           =   self.prepare_config_and_inputs()
         (
             (
             UpperCAmelCase_
         )    , (
             UpperCAmelCase_
         )    , (
             UpperCAmelCase_
         )    , (
             UpperCAmelCase_
         )    , (
             UpperCAmelCase_
         )    , (
             UpperCAmelCase_
         )    , (
             UpperCAmelCase_
         )    , 
         )           =   config_and_inputs
         UpperCAmelCase_           =   {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
         return config, inputs_dict




@require_tf
class        __A      ( UpperCamelCase__		,	UpperCamelCase__		,	unittest.TestCase	):
    a__       :						Optional[Any]          =  (
        (
            TFDebertaVaModel,
            TFDebertaVaForMaskedLM,
            TFDebertaVaForQuestionAnswering,
            TFDebertaVaForSequenceClassification,
            TFDebertaVaForTokenClassification,
        )
        if is_tf_available()
        else ()
    )
    a__       :						int          =  (
        {
            """feature-extraction""": TFDebertaVaModel,
            """fill-mask""": TFDebertaVaForMaskedLM,
            """question-answering""": TFDebertaVaForQuestionAnswering,
            """text-classification""": TFDebertaVaForSequenceClassification,
            """token-classification""": TFDebertaVaForTokenClassification,
            """zero-shot""": TFDebertaVaForSequenceClassification,
        }
        if is_tf_available()
        else {}
    )

    a__       :						Optional[Any]          =  False
    a__       :						List[Any]          =  False



    def 					_lowercase						(self    :    Any ):
         UpperCAmelCase_           =   TFDebertaVaModelTester(self )
         UpperCAmelCase_           =   ConfigTester(self   ,			config_class=__a   ,			hidden_size=37 )



    def 					_lowercase						(self    :    Optional[int] ):
         self.config_tester.run_common_tests()



    def 					_lowercase						(self    :    int ):
         UpperCAmelCase_           =   self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*__a )



    def 					_lowercase						(self    :    Union[str, Any] ):
         UpperCAmelCase_           =   self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_masked_lm(*__a )



    def 					_lowercase						(self    :    Union[str, Any] ):
         UpperCAmelCase_           =   self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_question_answering(*__a )



    def 					_lowercase						(self    :    Union[str, Any] ):
         UpperCAmelCase_           =   self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_sequence_classification(*__a )



    def 					_lowercase						(self    :    Tuple ):
         UpperCAmelCase_           =   self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_token_classification(*__a )






    @slow
    def 					_lowercase						(self    :    Dict ):
         UpperCAmelCase_           =   TFDebertaVaModel.from_pretrained("kamalkraj/deberta-v2-xlarge" )
         self.assertIsNotNone(__a )




@require_tf
class        __A      ( unittest.TestCase	):



    @unittest.skip(reason="Model not available yet" )
    def 					_lowercase						(self    :    Dict ):
         pass






    @slow
    def 					_lowercase						(self    :    str ):
         UpperCAmelCase_           =   TFDebertaVaModel.from_pretrained("kamalkraj/deberta-v2-xlarge" )
         UpperCAmelCase_           =   tf.constant([[0, 31414, 232, 328, 740, 1140, 12695, 69, 46078, 1588, 2]] )
         UpperCAmelCase_           =   tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]] )
         UpperCAmelCase_           =   model(__a   ,			attention_mask=__a )[0]

         UpperCAmelCase_           =   tf.constant(
             [[[0.23_56, 0.19_48, 0.03_69], [-0.10_63, 0.35_86, -0.51_52], [-0.63_99, -0.02_59, -0.25_25]]] )
         tf.debugging.assert_near(output[:, 1:4, 1:4]   ,			__a   ,			atol=1E-4 )





'''simple docstring'''





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

import datasets


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


SCREAMING_SNAKE_CASE_:     Union[str, 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'


SCREAMING_SNAKE_CASE_:     List[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        __A      ( datasets.Metric	):



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




