






"""simple docstring"""
import torch
import torch.nn as nn
from transformers.modeling_utils import ModuleUtilsMixin
from transformers.models.ta.modeling_ta import TaBlock, TaConfig, TaLayerNorm

from ...configuration_utils import ConfigMixin, register_to_config
from ...models import ModelMixin



class   SCREAMING_SNAKE_CASE	(					_SCREAMING_SNAKE_CASE							,							_SCREAMING_SNAKE_CASE							,							_SCREAMING_SNAKE_CASE    ):





	"""simple docstring"""




	@register_to_config
	def __init__(self  ,  lowerCAmelCase_  ,  lowerCAmelCase_  ,  lowerCAmelCase_  ,  lowerCAmelCase_  ,  lowerCAmelCase_  ,  lowerCAmelCase_  ,  lowerCAmelCase_  ,  lowerCAmelCase_  ,  lowerCAmelCase_  ,  lowerCAmelCase_ = False  ,  ):
		super().__init__()

		A_		:    Tuple						     = nn.Embedding(lowerCAmelCase_  ,  lowerCAmelCase_				)

		A_		:    List[str]						     = nn.Embedding(lowerCAmelCase_  ,  lowerCAmelCase_				)
		A_		:    Any						     = False

		A_		:    Tuple						     = nn.Dropout(p=lowerCAmelCase_				)

		A_		:    List[str]						     = TaConfig(
		    vocab_size=lowerCAmelCase_  ,  d_model=lowerCAmelCase_  ,  num_heads=lowerCAmelCase_  ,  d_kv=lowerCAmelCase_  ,  d_ff=lowerCAmelCase_  ,  dropout_rate=lowerCAmelCase_  ,  feed_forward_proj=lowerCAmelCase_  ,  is_decoder=lowerCAmelCase_  ,  is_encoder_decoder=lowerCAmelCase_  ,  )

		A_		:    Optional[Any]						     = nn.ModuleList()
		for lyr_num in range(lowerCAmelCase_				):
			A_		:    Tuple						     = TaBlock(lowerCAmelCase_				)
			self.encoders.append(lowerCAmelCase_				)

		A_		:    Any						     = TaLayerNorm(lowerCAmelCase_				)
		A_		:    Union[str, Any]						     = nn.Dropout(p=lowerCAmelCase_				)





	def  lowerCamelCase(self  ,  lowerCAmelCase_  ,  lowerCAmelCase_				):
		A_		:    List[Any]						     = self.token_embedder(lowerCAmelCase_				)

		A_		:    Optional[Any]						     = encoder_input_tokens.shape[1]
		A_		:    Any						     = torch.arange(lowerCAmelCase_  ,  device=encoder_input_tokens.device				)
		x += self.position_encoding(lowerCAmelCase_				)

		A_		:    Optional[Any]						     = self.dropout_pre(lowerCAmelCase_				)

		# inverted the attention mask
		A_		:    int						     = encoder_input_tokens.size()
		A_		:    Optional[Any]						     = self.get_extended_attention_mask(lowerCAmelCase_  ,  lowerCAmelCase_				)

		for lyr in self.encoders:
			A_		:    int						     = lyr(lowerCAmelCase_  ,  lowerCAmelCase_				)[0]
		A_		:    List[str]						     = self.layer_norm(lowerCAmelCase_				)

		return self.dropout_post(lowerCAmelCase_				), encoder_inputs_mask









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

import datasets


_lowerCAmelCase       =				"\\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       =				"\\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       =				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   SCREAMING_SNAKE_CASE	(					datasets.Metric    ):





	"""simple docstring"""




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

