


import re
import string

import numpy as np

import datasets


_snake_case             =     '''
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.
'''

_snake_case             =     '''
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

'''

_snake_case             =     '''
'''
@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION		, _KWARGS_DESCRIPTION    )
class 	UpperCAmelCase_					(					datasets.Metric    ):

   '''simple docstring'''




   def _snake_case    (		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 _snake_case    (		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:
         lowerCamelCase :					Any    =				np.array([re.sub(__A						,				""						,				__A ) for x in predictions] )
         lowerCamelCase :					List[Any]    =				np.array([re.sub(__A						,				""						,				__A ) for x in references] )
     else:
       lowerCamelCase :					Tuple    =				np.asarray(__A )
       lowerCamelCase :					Dict    =				np.asarray(__A )

     if ignore_case:
       lowerCamelCase :					Optional[Any]    =				np.char.lower(__A )
       lowerCamelCase :					List[str]    =				np.char.lower(__A )

     if ignore_punctuation:
       lowerCamelCase :					List[str]    =				string.punctuation.maketrans(""						,				""						,				string.punctuation )
       lowerCamelCase :					Any    =				np.char.translate(__A						,				table=__A )
       lowerCamelCase :					List[Any]    =				np.char.translate(__A						,				table=__A )

     if ignore_numbers:
       lowerCamelCase :					Any    =				string.digits.maketrans(""						,				""						,				string.digits )
       lowerCamelCase :					Optional[int]    =				np.char.translate(__A						,				table=__A )
       lowerCamelCase :					Any    =				np.char.translate(__A						,				table=__A )

     lowerCamelCase :					int    =				predictions == references

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







from typing import List, Optional, Union

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding, PaddingStrategy, PreTokenizedInput, TextInput, TruncationStrategy
from ...utils import TensorType
class 	UpperCAmelCase_					(					UpperCamelCase    ):

   '''simple docstring'''




   __A :      Dict     		=		["image_processor", "tokenizer"]
   __A :      Dict     		=		"BridgeTowerImageProcessor"
   __A :      Optional[int]     		=		("RobertaTokenizer", "RobertaTokenizerFast")






   def __init__(		self						,				__A						,				__A ):






     """simple docstring"""





     super().__init__(__A						,				__A )






   def __call__(		self						,				__A						,				__A = None						,				__A = True						,				__A = False						,				__A = None						,				__A = None						,				__A = 0						,				__A = None						,				__A = None						,				__A = None						,				__A = False						,				__A = False						,				__A = False						,				__A = False						,				__A = True						,				__A = None						,				**__A						,				):






     """simple docstring"""





     lowerCamelCase :					str    =				self.tokenizer(
         text=__A						,				add_special_tokens=__A						,				padding=__A						,				truncation=__A						,				max_length=__A						,				stride=__A						,				pad_to_multiple_of=__A						,				return_token_type_ids=__A						,				return_attention_mask=__A						,				return_overflowing_tokens=__A						,				return_special_tokens_mask=__A						,				return_offsets_mapping=__A						,				return_length=__A						,				verbose=__A						,				return_tensors=__A						,				**__A						,				)
     # add pixel_values + pixel_mask
     lowerCamelCase :					int    =				self.image_processor(
         __A						,				return_tensors=__A						,				do_normalize=__A						,				do_center_crop=__A						,				**__A )
     encoding.update(__A )

     return encoding






   def _snake_case    (		self						,				*__A						,				**__A ):






     """simple docstring"""





     return self.tokenizer.batch_decode(*__A						,				**__A )






   def _snake_case    (		self						,				*__A						,				**__A ):






     """simple docstring"""





     return self.tokenizer.decode(*__A						,				**__A )






   @property
   def _snake_case    (		self ):






     """simple docstring"""





     lowerCamelCase :					List[Any]    =				self.tokenizer.model_input_names
     lowerCamelCase :					int    =				self.image_processor.model_input_names
     return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names ) )



