
import re
import string

import numpy as np

import datasets


SCREAMING_SNAKE_CASE							:List[str] 			=    '\nReturns the rate at which the input predicted strings exactly match their references, ignoring any strings input as part of the regexes_to_ignore list.\n'

SCREAMING_SNAKE_CASE							:Any 			=    '\nArgs:\n    predictions: List of predicted texts.\n    references: List of reference texts.\n    regexes_to_ignore: List, defaults to None. Regex expressions of characters to\n        ignore when calculating the exact matches. Note: these regexes are removed\n        from the input data before the changes based on the options below (e.g. ignore_case,\n        ignore_punctuation, ignore_numbers) are applied.\n    ignore_case: Boolean, defaults to False. If true, turns everything\n        to lowercase so that capitalization differences are ignored.\n    ignore_punctuation: Boolean, defaults to False. If true, removes all punctuation before\n        comparing predictions and references.\n    ignore_numbers: Boolean, defaults to False. If true, removes all punctuation before\n        comparing predictions and references.\nReturns:\n    exact_match: Dictionary containing exact_match rate. Possible values are between 0.0 and 100.0, inclusive.\nExamples:\n    >>> exact_match = datasets.load_metric("exact_match")\n    >>> refs = ["the cat", "theater", "YELLING", "agent007"]\n    >>> preds = ["cat?", "theater", "yelling", "agent"]\n    >>> results = exact_match.compute(references=refs, predictions=preds)\n    >>> print(round(results["exact_match"], 1))\n    25.0\n\n    >>> exact_match = datasets.load_metric("exact_match")\n    >>> refs = ["the cat", "theater", "YELLING", "agent007"]\n    >>> preds = ["cat?", "theater", "yelling", "agent"]\n    >>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=["the ", "yell"], ignore_case=True, ignore_punctuation=True)\n    >>> print(round(results["exact_match"], 1))\n    50.0\n\n\n    >>> exact_match = datasets.load_metric("exact_match")\n    >>> refs = ["the cat", "theater", "YELLING", "agent007"]\n    >>> preds = ["cat?", "theater", "yelling", "agent"]\n    >>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=["the ", "yell", "YELL"], ignore_case=True, ignore_punctuation=True)\n    >>> print(round(results["exact_match"], 1))\n    75.0\n\n    >>> exact_match = datasets.load_metric("exact_match")\n    >>> refs = ["the cat", "theater", "YELLING", "agent007"]\n    >>> preds = ["cat?", "theater", "yelling", "agent"]\n    >>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=["the ", "yell", "YELL"], ignore_case=True, ignore_punctuation=True, ignore_numbers=True)\n    >>> print(round(results["exact_match"], 1))\n    100.0\n\n    >>> exact_match = datasets.load_metric("exact_match")\n    >>> refs = ["The cat sat on the mat.", "Theaters are great.", "It\'s like comparing oranges and apples."]\n    >>> preds = ["The cat sat on the mat?", "Theaters are great.", "It\'s like comparing apples and oranges."]\n    >>> results = exact_match.compute(references=refs, predictions=preds)\n    >>> print(round(results["exact_match"], 1))\n    33.3\n\n'

SCREAMING_SNAKE_CASE							:Dict 			=    '\n'





@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION      ,      _KWARGS_DESCRIPTION  )
class 							UpperCAmelCase				(  datasets.Metric  ):




	'''simple docstring'''





	def     UpperCamelCase_  (	self :			str			):
					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     UpperCamelCase_  (	self :			List[str]							,A :			Optional[int]							,A :			Optional[int]							,A :			int=None							,A :			List[Any]=False							,A :			List[Any]=False							,A :			int=False							,):
					if regexes_to_ignore is not None:
									for s in regexes_to_ignore:
													__A             =			np.array([re.sub(__SCREAMING_SNAKE_CASE							,""							,__SCREAMING_SNAKE_CASE			) for x in predictions]			)
													__A             =			np.array([re.sub(__SCREAMING_SNAKE_CASE							,""							,__SCREAMING_SNAKE_CASE			) for x in references]			)
					else:
									__A             =			np.asarray(__SCREAMING_SNAKE_CASE			)
									__A             =			np.asarray(__SCREAMING_SNAKE_CASE			)

					if ignore_case:
									__A             =			np.char.lower(__SCREAMING_SNAKE_CASE			)
									__A             =			np.char.lower(__SCREAMING_SNAKE_CASE			)

					if ignore_punctuation:
									__A             =			string.punctuation.maketrans(""							,""							,string.punctuation			)
									__A             =			np.char.translate(__SCREAMING_SNAKE_CASE							,table=__SCREAMING_SNAKE_CASE			)
									__A             =			np.char.translate(__SCREAMING_SNAKE_CASE							,table=__SCREAMING_SNAKE_CASE			)

					if ignore_numbers:
									__A             =			string.digits.maketrans(""							,""							,string.digits			)
									__A             =			np.char.translate(__SCREAMING_SNAKE_CASE							,table=__SCREAMING_SNAKE_CASE			)
									__A             =			np.char.translate(__SCREAMING_SNAKE_CASE							,table=__SCREAMING_SNAKE_CASE			)

					__A             =			predictions == references

					return {"exact_match": np.mean(__SCREAMING_SNAKE_CASE			) * 1_00}


from collections import OrderedDict
from typing import TYPE_CHECKING, Any, List, Mapping, Optional

from packaging import version


if TYPE_CHECKING:
					from ... import PreTrainedTokenizer, TensorType

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfigWithPast, PatchingSpec
from ...utils import is_torch_available, logging


SCREAMING_SNAKE_CASE							:Optional[Any]										=    logging.get_logger(__name__)

SCREAMING_SNAKE_CASE							:Union[str, Any]										=    {
    'bigscience/bloom': 'https://huggingface.co/bigscience/bloom/resolve/main/config.json',
    'bigscience/bloom-560m': 'https://huggingface.co/bigscience/bloom-560m/blob/main/config.json',
    'bigscience/bloom-1b1': 'https://huggingface.co/bigscience/bloom-1b1/blob/main/config.json',
    'bigscience/bloom-1b7': 'https://huggingface.co/bigscience/bloom-1b7/blob/main/config.json',
    'bigscience/bloom-3b': 'https://huggingface.co/bigscience/bloom-3b/blob/main/config.json',
    'bigscience/bloom-7b1': 'https://huggingface.co/bigscience/bloom-7b1/blob/main/config.json',
}





class 							UpperCAmelCase				(  __SCREAMING_SNAKE_CASE  ):




	'''simple docstring'''





	snake_case_    =					"bloom"
	snake_case_    =					["past_key_values"]
	snake_case_    =					{
	    "num_hidden_layers": "n_layer",
	    "num_attention_heads": "n_head",
	}






	def __init__(	self :			Optional[Any]							,A :			List[Any]=25_08_80							,A :			Optional[int]=64							,A :			List[Any]=2							,A :			Optional[int]=8							,A :			str=1E-5							,A :			str=0.02							,A :			int=True							,A :			Optional[Any]=1							,A :			int=2							,A :			str=False							,A :			Dict=0.0							,A :			List[Any]=0.0							,A :			str=1							,A :			List[Any]=False							,**A :			List[Any]							,):
					__A             =			vocab_size
					# Backward compatibility with n_embed kwarg
					__A             =			kwargs.pop("n_embed"							,A			)
					__A             =			hidden_size if n_embed is None else n_embed
					__A             =			n_layer
					__A             =			n_head
					__A             =			layer_norm_epsilon
					__A             =			initializer_range
					__A             =			use_cache
					__A             =			pretraining_tp
					__A             =			apply_residual_connection_post_layernorm
					__A             =			hidden_dropout
					__A             =			attention_dropout

					__A             =			bos_token_id
					__A             =			eos_token_id
					__A             =			slow_but_exact

					super().__init__(bos_token_id=A							,eos_token_id=A							,**A			)





class 							UpperCAmelCase				(  __SCREAMING_SNAKE_CASE  ):




	'''simple docstring'''





	snake_case_    =					version.parse("1.12"  )






	def __init__(	self :			str							,A :			PretrainedConfig							,A :			str = "default"							,A :			List[PatchingSpec] = None							,A :			bool = False							,):
					super().__init__(A							,task=A							,patching_specs=A							,use_past=A			)
					if not getattr(self._config							,"pad_token_id"							,A			):
									# TODO: how to do that better?
									__A             =			0






	@property
	def     UpperCamelCase_  (	self :			Union[str, Any]			):
					__A             =			OrderedDict({"input_ids": {0: "batch", 1: "sequence"}}			)
					if self.use_past:
									# BLOOM stores values on dynamic axis 2. For more details see: https://github.com/huggingface/transformers/pull/18344
									self.fill_with_past_key_values_(A							,direction="inputs"							,inverted_values_shape=A			)
									__A             =			{0: "batch", 1: "past_sequence + sequence"}
					else:
									__A             =			{0: "batch", 1: "sequence"}

					return common_inputs






	@property
	def     UpperCamelCase_  (	self :			Optional[Any]			):
					return self._config.n_layer






	@property
	def     UpperCamelCase_  (	self :			List[Any]			):
					return self._config.n_head






	@property
	def     UpperCamelCase_  (	self :			Optional[int]			):
					return 1E-3






	def     UpperCamelCase_  (	self :			Any							,A :			"PreTrainedTokenizer"							,A :			int = -1							,A :			int = -1							,A :			bool = False							,A :			Optional["TensorType"] = None							,):
					__A             =			super(A							,self			).generate_dummy_inputs(
					    A							,batch_size=A							,seq_length=A							,is_pair=A							,framework=A			)

					# We need to order the input in the way they appears in the forward()
					__A             =			OrderedDict({"input_ids": common_inputs["input_ids"]}			)

					# Need to add the past_keys
					if self.use_past:
									if not is_torch_available():
													raise ValueError("Cannot generate dummy past_keys inputs without PyTorch installed."			)
									else:
													import torch

													__A      ,							__A             =			common_inputs["input_ids"].shape
													# Not using the same length for past_key_values
													__A             =			seqlen + 2
													__A             =			self._config.hidden_size // self.num_attention_heads
													__A             =			(
													    batch * self.num_attention_heads,
													    head_dim,
													    past_key_values_length,
													)
													__A             =			(
													    batch * self.num_attention_heads,
													    past_key_values_length,
													    head_dim,
													)
													__A             =			[
													    (torch.zeros(A			), torch.zeros(A			)) for _ in range(self.num_layers			)
													]

					__A             =			common_inputs["attention_mask"]
					if self.use_past:
									__A             =			ordered_inputs["attention_mask"].dtype
									__A             =			torch.cat(
									    [ordered_inputs["attention_mask"], torch.ones(A							,A							,dtype=A			)]							,dim=1			)

					return ordered_inputs







	@property
	def     UpperCamelCase_  (	self :			int			):
					return 13
