


'''simple docstring'''



import re
import string

import numpy as np

import datasets


__lowercase	:						Tuple       =	'\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'

__lowercase	:						List[str]       =	'\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'

__lowercase	:						Any       =	'\n'





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




	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						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						,				__a						,				__a						,				__a=None						,				__a=False						,				__a=False						,				__a=False						,				):

						'''simple docstring'''





						if regexes_to_ignore is not None:
											for s in regexes_to_ignore:
																__a			:       Tuple					    =  np.array([re.sub(__a						,				''						,				__a							) for x in predictions]							)
																__a			:       List[Any]					    =  np.array([re.sub(__a						,				''						,				__a							) for x in references]							)
						else:
											__a			:       int					    =  np.asarray(__a							)
											__a			:       str					    =  np.asarray(__a							)

						if ignore_case:
											__a			:       Dict					    =  np.char.lower(__a							)
											__a			:       List[str]					    =  np.char.lower(__a							)

						if ignore_punctuation:
											__a			:       Dict					    =  string.punctuation.maketrans(''						,				''						,				string.punctuation							)
											__a			:       Tuple					    =  np.char.translate(__a						,				table=__a							)
											__a			:       Dict					    =  np.char.translate(__a						,				table=__a							)

						if ignore_numbers:
											__a			:       Optional[int]					    =  string.digits.maketrans(''						,				''						,				string.digits							)
											__a			:       Tuple					    =  np.char.translate(__a						,				table=__a							)
											__a			:       Optional[int]					    =  np.char.translate(__a						,				table=__a							)

						__a			:       Any					    =  predictions == references

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











"""simple docstring"""
import os
from shutil import copyfile
from typing import List, Optional, Tuple

from tokenizers import processors

from ...tokenization_utils import AddedToken, BatchEncoding
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import is_sentencepiece_available, logging


if is_sentencepiece_available():
			from .tokenization_mbart import MBartTokenizer
else:
			lowerCamelCase_					=      None


lowerCamelCase_					=      logging.get_logger(__name__)


lowerCamelCase_					=      {'''vocab_file''': '''sentencepiece.bpe.model''', '''tokenizer_file''': '''tokenizer.json'''}

lowerCamelCase_					=      {
    '''vocab_file''': {
        '''facebook/mbart-large-en-ro''': (
            '''https://huggingface.co/facebook/mbart-large-en-ro/resolve/main/sentencepiece.bpe.model'''
        ),
        '''facebook/mbart-large-cc25''': (
            '''https://huggingface.co/facebook/mbart-large-cc25/resolve/main/sentencepiece.bpe.model'''
        ),
    },
    '''tokenizer_file''': {
        '''facebook/mbart-large-en-ro''': '''https://huggingface.co/facebook/mbart-large-en-ro/resolve/main/tokenizer.json''',
        '''facebook/mbart-large-cc25''': '''https://huggingface.co/facebook/mbart-large-cc25/resolve/main/tokenizer.json''',
    },
}

lowerCamelCase_					=      {
    '''facebook/mbart-large-en-ro''': 1024,
    '''facebook/mbart-large-cc25''': 1024,
}

# fmt: off
lowerCamelCase_					=      ['''ar_AR''', '''cs_CZ''', '''de_DE''', '''en_XX''', '''es_XX''', '''et_EE''', '''fi_FI''', '''fr_XX''', '''gu_IN''', '''hi_IN''', '''it_IT''', '''ja_XX''', '''kk_KZ''', '''ko_KR''', '''lt_LT''', '''lv_LV''', '''my_MM''', '''ne_NP''', '''nl_XX''', '''ro_RO''', '''ru_RU''', '''si_LK''', '''tr_TR''', '''vi_VN''', '''zh_CN''']







class 			UpperCamelCase_       (__A     ):
	__magic_name__	      =				VOCAB_FILES_NAMES
	__magic_name__	      =				PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
	__magic_name__	      =				PRETRAINED_VOCAB_FILES_MAP
	__magic_name__	      =				['''input_ids''', '''attention_mask''']
	__magic_name__	      =				MBartTokenizer

	__magic_name__	      =				[]
	__magic_name__	      =				[]





	def __init__(      self					: List[str]	,	lowerCAmelCase_					: List[Any]=None	,	lowerCAmelCase_					: str=None	,	lowerCAmelCase_					: List[Any]="<s>"	,	lowerCAmelCase_					: Optional[Any]="</s>"	,	lowerCAmelCase_					: str="</s>"	,	lowerCAmelCase_					: str="<s>"	,	lowerCAmelCase_					: List[Any]="<unk>"	,	lowerCAmelCase_					: Tuple="<pad>"	,	lowerCAmelCase_					: Union[str, Any]="<mask>"	,	lowerCAmelCase_					: List[Any]=None	,	lowerCAmelCase_					: str=None	,	lowerCAmelCase_					: Optional[Any]=None	,	**lowerCAmelCase_					: Any	,	)						->			Tuple:
				# Mask token behave like a normal word, i.e. include the space before it
				UpperCAmelCase_     : Union[str, Any]			     =					AddedToken(lowerCAmelCase_	,	lstrip=lowerCAmelCase_	,	rstrip=lowerCAmelCase_						) if isinstance(lowerCAmelCase_	,	lowerCAmelCase_						) else mask_token

				super().__init__(
				    vocab_file=lowerCAmelCase_	,	tokenizer_file=lowerCAmelCase_	,	bos_token=lowerCAmelCase_	,	eos_token=lowerCAmelCase_	,	sep_token=lowerCAmelCase_	,	cls_token=lowerCAmelCase_	,	unk_token=lowerCAmelCase_	,	pad_token=lowerCAmelCase_	,	mask_token=lowerCAmelCase_	,	src_lang=lowerCAmelCase_	,	tgt_lang=lowerCAmelCase_	,	additional_special_tokens=lowerCAmelCase_	,	**lowerCAmelCase_	,	)

				UpperCAmelCase_     : Tuple			     =					vocab_file
				UpperCAmelCase_     : str			     =					False if not self.vocab_file else True

				UpperCAmelCase_     : List[Any]			     =					FAIRSEQ_LANGUAGE_CODES.copy()

				if additional_special_tokens is not None:
							# Only add those special tokens if they are not already there.
							_additional_special_tokens.extend(
							    [t for t in additional_special_tokens if t not in _additional_special_tokens]						)

				self.add_special_tokens({"additional_special_tokens": _additional_special_tokens}						)
				UpperCAmelCase_     : Tuple			     =					{
				    lang_code: self.convert_tokens_to_ids(lowerCAmelCase_						) for lang_code in FAIRSEQ_LANGUAGE_CODES
				}

				UpperCAmelCase_     : int			     =					src_lang if src_lang is not None else "en_XX"
				UpperCAmelCase_     : Union[str, Any]			     =					self.convert_tokens_to_ids(self._src_lang						)
				UpperCAmelCase_     : Any			     =					tgt_lang
				self.set_src_lang_special_tokens(self._src_lang						)





	@property
	def      _SCREAMING_SNAKE_CASE      (      self					: Optional[int]						)						->			str:
				return self._src_lang





	@src_lang.setter
	def      _SCREAMING_SNAKE_CASE      (      self					: Any	,	lowerCAmelCase_					: str						)						->			None:
				UpperCAmelCase_     : List[Any]			     =					new_src_lang
				self.set_src_lang_special_tokens(self._src_lang						)





	def      _SCREAMING_SNAKE_CASE      (      self					: Optional[Any]	,	lowerCAmelCase_					: List[int]	,	lowerCAmelCase_					: Optional[List[int]] = None						)						->			List[int]:
				if token_ids_a is None:
							return self.prefix_tokens + token_ids_a + self.suffix_tokens
				# We don't expect to process pairs, but leave the pair logic for API consistency
				return self.prefix_tokens + token_ids_a + token_ids_a + self.suffix_tokens





	def      _SCREAMING_SNAKE_CASE      (      self					: List[Any]	,	lowerCAmelCase_					: List[int]	,	lowerCAmelCase_					: Optional[List[int]] = None						)						->			List[int]:
				UpperCAmelCase_     : List[str]			     =					[self.sep_token_id]
				UpperCAmelCase_     : Dict			     =					[self.cls_token_id]

				if token_ids_a is None:
							return len(cls + token_ids_a + sep						) * [0]
				return len(cls + token_ids_a + sep + sep + token_ids_a + sep						) * [0]





	def      _SCREAMING_SNAKE_CASE      (      self					: Any	,	lowerCAmelCase_					: Tuple	,	lowerCAmelCase_					: str	,	lowerCAmelCase_					: Optional[str]	,	lowerCAmelCase_					: Optional[str]	,	**lowerCAmelCase_					: Union[str, Any]						)						->			Dict:
				if src_lang is None or tgt_lang is None:
							raise ValueError("Translation requires a `src_lang` and a `tgt_lang` for this model"						)
				UpperCAmelCase_     : str			     =					src_lang
				UpperCAmelCase_     : str			     =					self(lowerCAmelCase_	,	add_special_tokens=lowerCAmelCase_	,	return_tensors=lowerCAmelCase_	,	**lowerCAmelCase_						)
				UpperCAmelCase_     : Optional[int]			     =					self.convert_tokens_to_ids(lowerCAmelCase_						)
				UpperCAmelCase_     : Dict			     =					tgt_lang_id
				return inputs





	def      _SCREAMING_SNAKE_CASE      (      self					: List[Any]	,	lowerCAmelCase_					: List[str]	,	lowerCAmelCase_					: str = "en_XX"	,	lowerCAmelCase_					: Optional[List[str]] = None	,	lowerCAmelCase_					: str = "ro_RO"	,	**lowerCAmelCase_					: Dict	,	)						->			BatchEncoding:
				UpperCAmelCase_     : List[Any]			     =					src_lang
				UpperCAmelCase_     : Tuple			     =					tgt_lang
				return super().prepare_seqaseq_batch(lowerCAmelCase_	,	lowerCAmelCase_	,	**lowerCAmelCase_						)





	def      _SCREAMING_SNAKE_CASE      (      self					: Optional[int]						)						->			Any:
				return self.set_src_lang_special_tokens(self.src_lang						)





	def      _SCREAMING_SNAKE_CASE      (      self					: List[Any]						)						->			Dict:
				return self.set_tgt_lang_special_tokens(self.tgt_lang						)





	def      _SCREAMING_SNAKE_CASE      (      self					: Optional[Any]	,	lowerCAmelCase_					: List[Any]						)						->			None:
				UpperCAmelCase_     : int			     =					self.convert_tokens_to_ids(lowerCAmelCase_						)
				UpperCAmelCase_     : str			     =					[]
				UpperCAmelCase_     : str			     =					[self.eos_token_id, self.cur_lang_code]

				UpperCAmelCase_     : Union[str, Any]			     =					self.convert_ids_to_tokens(self.prefix_tokens						)
				UpperCAmelCase_     : List[Any]			     =					self.convert_ids_to_tokens(self.suffix_tokens						)

				UpperCAmelCase_     : Optional[Any]			     =					processors.TemplateProcessing(
				    single=prefix_tokens_str + ["$A"] + suffix_tokens_str	,	pair=prefix_tokens_str + ["$A", "$B"] + suffix_tokens_str	,	special_tokens=list(zip(prefix_tokens_str + suffix_tokens_str	,	self.prefix_tokens + self.suffix_tokens						)						)	,	)





	def      _SCREAMING_SNAKE_CASE      (      self					: Tuple	,	lowerCAmelCase_					: str						)						->			None:
				UpperCAmelCase_     : Union[str, Any]			     =					self.convert_tokens_to_ids(lowerCAmelCase_						)
				UpperCAmelCase_     : Dict			     =					[]
				UpperCAmelCase_     : Optional[int]			     =					[self.eos_token_id, self.cur_lang_code]

				UpperCAmelCase_     : Tuple			     =					self.convert_ids_to_tokens(self.prefix_tokens						)
				UpperCAmelCase_     : Tuple			     =					self.convert_ids_to_tokens(self.suffix_tokens						)

				UpperCAmelCase_     : Optional[Any]			     =					processors.TemplateProcessing(
				    single=prefix_tokens_str + ["$A"] + suffix_tokens_str	,	pair=prefix_tokens_str + ["$A", "$B"] + suffix_tokens_str	,	special_tokens=list(zip(prefix_tokens_str + suffix_tokens_str	,	self.prefix_tokens + self.suffix_tokens						)						)	,	)





	def      _SCREAMING_SNAKE_CASE      (      self					: str	,	lowerCAmelCase_					: str	,	lowerCAmelCase_					: Optional[str] = None						)						->			Tuple[str]:
				if not self.can_save_slow_tokenizer:
							raise ValueError(
							    "Your fast tokenizer does not have the necessary information to save the vocabulary for a slow "
							    "tokenizer."						)

				if not os.path.isdir(lowerCAmelCase_						):
							logger.error(f"""Vocabulary path ({save_directory}) should be a directory."""						)
							return
				UpperCAmelCase_     : List[str]			     =					os.path.join(
				    lowerCAmelCase_	,	(filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"]						)

				if os.path.abspath(self.vocab_file						) != os.path.abspath(lowerCAmelCase_						):
							copyfile(self.vocab_file	,	lowerCAmelCase_						)

				return (out_vocab_file,)



