




"""simple docstring"""

import re
import string

import numpy as np

import datasets


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

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

'''

a							      =     '''
'''





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



 '''simple docstring'''

 def      lowerCAmelCase_				(					self			:			Optional[Any]						):
       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			:			str       ,				_UpperCAmelCase			:			Any       ,				_UpperCAmelCase			:			Dict       ,				_UpperCAmelCase			:			Any=None       ,				_UpperCAmelCase			:			Dict=False       ,				_UpperCAmelCase			:			Optional[Any]=False       ,				_UpperCAmelCase			:			Optional[Any]=False       ,				):
       if regexes_to_ignore is not None:
             for s in regexes_to_ignore:
                   _A     =  np.array([re.sub(_UpperCAmelCase       ,				''       ,				_UpperCAmelCase						) for x in predictions]						)
                   _A     =  np.array([re.sub(_UpperCAmelCase       ,				''       ,				_UpperCAmelCase						) for x in references]						)
       else:
             _A     =  np.asarray(_UpperCAmelCase						)
             _A     =  np.asarray(_UpperCAmelCase						)

       if ignore_case:
             _A     =  np.char.lower(_UpperCAmelCase						)
             _A     =  np.char.lower(_UpperCAmelCase						)

       if ignore_punctuation:
             _A     =  string.punctuation.maketrans(''       ,				''       ,				string.punctuation						)
             _A     =  np.char.translate(_UpperCAmelCase       ,				table=_UpperCAmelCase						)
             _A     =  np.char.translate(_UpperCAmelCase       ,				table=_UpperCAmelCase						)

       if ignore_numbers:
             _A     =  string.digits.maketrans(''       ,				''       ,				string.digits						)
             _A     =  np.char.translate(_UpperCAmelCase       ,				table=_UpperCAmelCase						)
             _A     =  np.char.translate(_UpperCAmelCase       ,				table=_UpperCAmelCase						)

       _A     =  predictions == references

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







"""simple docstring"""

import warnings

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding





class 							lowercase_			(	__lowerCAmelCase				):



 '''simple docstring'''
 UpperCAmelCase       :	Any     =      ['''image_processor''', '''tokenizer''']
 UpperCAmelCase       :	Optional[int]     =      '''ViTImageProcessor'''
 UpperCAmelCase       :	int     =      ('''CLIPTokenizer''', '''CLIPTokenizerFast''')

 def __init__(					self			:			Tuple       ,				_UpperCAmelCase			:			int=None       ,				_UpperCAmelCase			:			Tuple=None       ,				**_UpperCAmelCase			:			Dict						):
       _A     =  None
       if "feature_extractor" in kwargs:
             warnings.warn(
                 'The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`'
                 ' instead.'       ,				_UpperCAmelCase       ,				)
             _A     =  kwargs.pop('feature_extractor'						)

       _A     =  image_processor if image_processor is not None else feature_extractor
       if image_processor is None:
             raise ValueError('You need to specify an `image_processor`.'						)
       if tokenizer is None:
             raise ValueError('You need to specify a `tokenizer`.'						)

       super().__init__(_UpperCAmelCase       ,				_UpperCAmelCase						)

 def __call__(					self			:			Optional[Any]       ,				_UpperCAmelCase			:			int=None       ,				_UpperCAmelCase			:			int=None       ,				_UpperCAmelCase			:			Optional[Any]=None       ,				_UpperCAmelCase			:			Optional[int]=None       ,				**_UpperCAmelCase			:			Union[str, Any]						):
       if text is None and visual_prompt is None and images is None:
             raise ValueError('You have to specify either text, visual prompt or images.'						)

       if text is not None and visual_prompt is not None:
             raise ValueError('You have to specify exactly one type of prompt. Either text or visual prompt.'						)

       if text is not None:
             _A     =  self.tokenizer(_UpperCAmelCase       ,				return_tensors=_UpperCAmelCase       ,				**_UpperCAmelCase						)

       if visual_prompt is not None:
             _A     =  self.image_processor(_UpperCAmelCase       ,				return_tensors=_UpperCAmelCase       ,				**_UpperCAmelCase						)

       if images is not None:
             _A     =  self.image_processor(_UpperCAmelCase       ,				return_tensors=_UpperCAmelCase       ,				**_UpperCAmelCase						)

       if visual_prompt is not None and images is not None:
             _A     =  {
                 'pixel_values': image_features.pixel_values,
                 'conditional_pixel_values': prompt_features.pixel_values,
             }
             return encoding
       elif text is not None and images is not None:
             _A     =  image_features.pixel_values
             return encoding
       elif text is not None:
             return encoding
       elif visual_prompt is not None:
             _A     =  {
                 'conditional_pixel_values': prompt_features.pixel_values,
             }
             return encoding
       else:
             return BatchEncoding(data=dict(**_UpperCAmelCase						)       ,				tensor_type=_UpperCAmelCase						)

 def      lowerCAmelCase_				(					self			:			str       ,				*_UpperCAmelCase			:			List[Any]       ,				**_UpperCAmelCase			:			Union[str, Any]						):
       return self.tokenizer.batch_decode(*_UpperCAmelCase       ,				**_UpperCAmelCase						)

 def      lowerCAmelCase_				(					self			:			Union[str, Any]       ,				*_UpperCAmelCase			:			List[str]       ,				**_UpperCAmelCase			:			Union[str, Any]						):
       return self.tokenizer.decode(*_UpperCAmelCase       ,				**_UpperCAmelCase						)

 @property
 def      lowerCAmelCase_				(					self			:			Dict						):
       warnings.warn(
           '`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.'       ,				_UpperCAmelCase       ,				)
       return self.image_processor_class



 @property
 def      lowerCAmelCase_				(					self			:			Tuple						):
       warnings.warn(
           '`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.'       ,				_UpperCAmelCase       ,				)
       return self.image_processor

