





'''simple docstring'''






import re
import string

import numpy as np

import datasets


lowerCAmelCase       		=      """
Returns the rate at which the input predicted strings exactly match their references, ignoring any strings input as part of the regexes_to_ignore list.
"""

lowerCAmelCase       		=      """
Args:
    predictions: List of predicted texts.
    references: List of reference texts.
    regexes_to_ignore: List, defaults to None. Regex expressions of characters to
        ignore when calculating the exact matches. Note: these regexes are removed
        from the input data before the changes based on the options below (e.g. ignore_case,
        ignore_punctuation, ignore_numbers) are applied.
    ignore_case: Boolean, defaults to False. If true, turns everything
        to lowercase so that capitalization differences are ignored.
    ignore_punctuation: Boolean, defaults to False. If true, removes all punctuation before
        comparing predictions and references.
    ignore_numbers: Boolean, defaults to False. If true, removes all punctuation before
        comparing predictions and references.
Returns:
    exact_match: Dictionary containing exact_match rate. Possible values are between 0.0 and 100.0, inclusive.
Examples:
    >>> exact_match = datasets.load_metric(\"exact_match\")
    >>> refs = [\"the cat\", \"theater\", \"YELLING\", \"agent007\"]
    >>> preds = [\"cat?\", \"theater\", \"yelling\", \"agent\"]
    >>> results = exact_match.compute(references=refs, predictions=preds)
    >>> print(round(results[\"exact_match\"], 1))
    25.0

    >>> exact_match = datasets.load_metric(\"exact_match\")
    >>> refs = [\"the cat\", \"theater\", \"YELLING\", \"agent007\"]
    >>> preds = [\"cat?\", \"theater\", \"yelling\", \"agent\"]
    >>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=[\"the \", \"yell\"], ignore_case=True, ignore_punctuation=True)
    >>> print(round(results[\"exact_match\"], 1))
    50.0


    >>> exact_match = datasets.load_metric(\"exact_match\")
    >>> refs = [\"the cat\", \"theater\", \"YELLING\", \"agent007\"]
    >>> preds = [\"cat?\", \"theater\", \"yelling\", \"agent\"]
    >>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=[\"the \", \"yell\", \"YELL\"], ignore_case=True, ignore_punctuation=True)
    >>> print(round(results[\"exact_match\"], 1))
    75.0

    >>> exact_match = datasets.load_metric(\"exact_match\")
    >>> refs = [\"the cat\", \"theater\", \"YELLING\", \"agent007\"]
    >>> preds = [\"cat?\", \"theater\", \"yelling\", \"agent\"]
    >>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=[\"the \", \"yell\", \"YELL\"], ignore_case=True, ignore_punctuation=True, ignore_numbers=True)
    >>> print(round(results[\"exact_match\"], 1))
    100.0

    >>> exact_match = datasets.load_metric(\"exact_match\")
    >>> refs = [\"The cat sat on the mat.\", \"Theaters are great.\", \"It's like comparing oranges and apples.\"]
    >>> preds = [\"The cat sat on the mat?\", \"Theaters are great.\", \"It's like comparing apples and oranges.\"]
    >>> results = exact_match.compute(references=refs, predictions=preds)
    >>> print(round(results[\"exact_match\"], 1))
    33.3

"""

lowerCAmelCase       		=      """
"""
@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION      ,   _KWARGS_DESCRIPTION       )
class 		lowerCamelCase  (      datasets.Metric       ):



	def   _lowerCamelCase    (   self	):
			return datasets.MetricInfo(
			    description=_DESCRIPTION		,      citation=_CITATION		,      inputs_description=_KWARGS_DESCRIPTION		,      features=datasets.Features(
			        {
			            "predictions": datasets.Value("string"		,      id="sequence"	),
			            "references": datasets.Value("string"		,      id="sequence"	),
			        }	)		,      reference_urls=[]		,      )





	def   _lowerCamelCase    (   self		,      a_		,      a_		,      a_=None		,      a_=False		,      a_=False		,      a_=False		,      ):
			if regexes_to_ignore is not None:
					for s in regexes_to_ignore:
							lowerCAmelCase     :    int						=   np.array([re.sub(a_		,      ""		,      a_	) for x in predictions]	)
							lowerCAmelCase     :    Tuple						=   np.array([re.sub(a_		,      ""		,      a_	) for x in references]	)
			else:
					lowerCAmelCase     :    Tuple						=   np.asarray(a_	)
					lowerCAmelCase     :    int						=   np.asarray(a_	)

			if ignore_case:
					lowerCAmelCase     :    List[str]						=   np.char.lower(a_	)
					lowerCAmelCase     :    int						=   np.char.lower(a_	)

			if ignore_punctuation:
					lowerCAmelCase     :    Optional[int]						=   string.punctuation.maketrans(""		,      ""		,      string.punctuation	)
					lowerCAmelCase     :    int						=   np.char.translate(a_		,      table=a_	)
					lowerCAmelCase     :    Tuple						=   np.char.translate(a_		,      table=a_	)

			if ignore_numbers:
					lowerCAmelCase     :    Tuple						=   string.digits.maketrans(""		,      ""		,      string.digits	)
					lowerCAmelCase     :    Optional[Any]						=   np.char.translate(a_		,      table=a_	)
					lowerCAmelCase     :    List[Any]						=   np.char.translate(a_		,      table=a_	)

			lowerCAmelCase     :    Union[str, Any]						=   predictions == references

			return {"exact_match": np.mean(a_	) * 100}










'''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 		lowerCamelCase  (      _A      ,   _A      ,   _A       ):



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

			lowerCAmelCase     :    int						=   nn.Embedding(a_		,      a_	)

			lowerCAmelCase     :    int						=   nn.Embedding(a_		,      a_	)
			lowerCAmelCase     :    int						=   False

			lowerCAmelCase     :    int						=   nn.Dropout(p=a_	)

			lowerCAmelCase     :    str						=   TaConfig(
			    vocab_size=a_		,      d_model=a_		,      num_heads=a_		,      d_kv=a_		,      d_ff=a_		,      dropout_rate=a_		,      feed_forward_proj=a_		,      is_decoder=a_		,      is_encoder_decoder=a_		,      )

			lowerCAmelCase     :    Any						=   nn.ModuleList()
			for lyr_num in range(a_	):
					lowerCAmelCase     :    Optional[Any]						=   TaBlock(a_	)
					self.encoders.append(a_	)

			lowerCAmelCase     :    List[str]						=   TaLayerNorm(a_	)
			lowerCAmelCase     :    Union[str, Any]						=   nn.Dropout(p=a_	)





	def   _lowerCamelCase    (   self		,      a_		,      a_	):
			lowerCAmelCase     :    Optional[Any]						=   self.token_embedder(a_	)

			lowerCAmelCase     :    int						=   encoder_input_tokens.shape[1]
			lowerCAmelCase     :    Optional[int]						=   torch.arange(a_		,      device=encoder_input_tokens.device	)
			x += self.position_encoding(a_	)

			lowerCAmelCase     :    List[str]						=   self.dropout_pre(a_	)

			# inverted the attention mask
			lowerCAmelCase     :    List[Any]						=   encoder_input_tokens.size()
			lowerCAmelCase     :    Dict						=   self.get_extended_attention_mask(a_		,      a_	)

			for lyr in self.encoders:
					lowerCAmelCase     :    Dict						=   lyr(a_		,      a_	)[0]
			lowerCAmelCase     :    int						=   self.layer_norm(a_	)

			return self.dropout_post(a_	), encoder_inputs_mask



