





'''simple docstring'''
import shutil
import tempfile
import unittest

import numpy as np
import pytest

from transformers import is_speech_available, is_vision_available
from transformers.testing_utils import require_torch


if is_vision_available():
    from transformers import TvltImageProcessor

if is_speech_available():
    from transformers import TvltFeatureExtractor

from transformers import TvltProcessor

@require_torch
class      snake_case     (    unittest.TestCase       ):




 """simple docstring"""



 def        _lowerCamelCase					(       self       :							List[Any]	):
        __UpperCamelCase       =  'ZinengTang/tvlt-base'
        __UpperCamelCase       =  tempfile.mkdtemp()






 def        _lowerCamelCase					(       self       :							Any							,	**__A       :							Any	):
        return TvltImageProcessor.from_pretrained(self.checkpoint							,	**__A	)






 def        _lowerCamelCase					(       self       :							Optional[Any]							,	**__A       :							Optional[int]	):
        return TvltFeatureExtractor.from_pretrained(self.checkpoint							,	**__A	)






 def        _lowerCamelCase					(       self       :							List[Any]	):
        shutil.rmtree(self.tmpdirname	)






 def        _lowerCamelCase					(       self       :							Optional[int]	):
        __UpperCamelCase       =  self.get_image_processor()
        __UpperCamelCase       =  self.get_feature_extractor()

        __UpperCamelCase       =  TvltProcessor(image_processor=__A							,	feature_extractor=__A	)
        processor.save_pretrained(self.tmpdirname	)
        __UpperCamelCase       =  TvltProcessor.from_pretrained(self.tmpdirname	)

        self.assertIsInstance(processor.feature_extractor							,	__A	)
        self.assertIsInstance(processor.image_processor							,	__A	)






 def        _lowerCamelCase					(       self       :							Tuple	):
        __UpperCamelCase       =  self.get_image_processor()
        __UpperCamelCase       =  self.get_feature_extractor()

        __UpperCamelCase       =  TvltProcessor(image_processor=__A							,	feature_extractor=__A	)

        __UpperCamelCase       =  np.ones([1_2_0_0_0]	)

        __UpperCamelCase       =  feature_extractor(__A							,	return_tensors='np'	)
        __UpperCamelCase       =  processor(audio=__A							,	return_tensors='np'	)

        for key in audio_dict.keys():
               self.assertAlmostEqual(audio_dict[key].sum()							,	input_processor[key].sum()							,	delta=1e-2	)






 def        _lowerCamelCase					(       self       :							str	):
        __UpperCamelCase       =  self.get_image_processor()
        __UpperCamelCase       =  self.get_feature_extractor()

        __UpperCamelCase       =  TvltProcessor(image_processor=__A							,	feature_extractor=__A	)

        __UpperCamelCase       =  np.ones([3, 2_2_4, 2_2_4]	)

        __UpperCamelCase       =  image_processor(__A							,	return_tensors='np'	)
        __UpperCamelCase       =  processor(images=__A							,	return_tensors='np'	)

        for key in image_dict.keys():
               self.assertAlmostEqual(image_dict[key].sum()							,	input_processor[key].sum()							,	delta=1e-2	)






 def        _lowerCamelCase					(       self       :							List[Any]	):
        __UpperCamelCase       =  self.get_image_processor()
        __UpperCamelCase       =  self.get_feature_extractor()

        __UpperCamelCase       =  TvltProcessor(image_processor=__A							,	feature_extractor=__A	)

        __UpperCamelCase       =  np.ones([1_2_0_0_0]	)
        __UpperCamelCase       =  np.ones([3, 2_2_4, 2_2_4]	)

        __UpperCamelCase       =  processor(audio=__A							,	images=__A	)

        self.assertListEqual(list(inputs.keys()	)							,	['audio_values', 'audio_mask', 'pixel_values', 'pixel_mask']	)

        # test if it raises when no input is passed
        with pytest.raises(__A	):
               processor()






 def        _lowerCamelCase					(       self       :							Union[str, Any]	):
        __UpperCamelCase       =  self.get_image_processor()
        __UpperCamelCase       =  self.get_feature_extractor()

        __UpperCamelCase       =  TvltProcessor(image_processor=__A							,	feature_extractor=__A	)

        self.assertListEqual(
            processor.model_input_names							,	image_processor.model_input_names + feature_extractor.model_input_names							,	msg='`processor` and `image_processor`+`feature_extractor` model input names do not match'							,	)








import re
import string

import numpy as np

import datasets


UpperCAmelCase_ :						Dict      =      '''
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.
'''

UpperCAmelCase_ :						Any      =      '''
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

'''

UpperCAmelCase_ :						Tuple      =      '''
'''

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





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

		if ignore_case:
			UpperCamelCase     :Tuple          =	np.char.lower(__lowerCamelCase	)
			UpperCamelCase     :Any          =	np.char.lower(__lowerCamelCase	)

		if ignore_punctuation:
			UpperCamelCase     :Optional[int]          =	string.punctuation.maketrans("""""" ,  """""" ,  string.punctuation	)
			UpperCamelCase     :Optional[Any]          =	np.char.translate(__lowerCamelCase ,  table=__lowerCamelCase	)
			UpperCamelCase     :List[str]          =	np.char.translate(__lowerCamelCase ,  table=__lowerCamelCase	)

		if ignore_numbers:
			UpperCamelCase     :Tuple          =	string.digits.maketrans("""""" ,  """""" ,  string.digits	)
			UpperCamelCase     :Dict          =	np.char.translate(__lowerCamelCase ,  table=__lowerCamelCase	)
			UpperCamelCase     :Tuple          =	np.char.translate(__lowerCamelCase ,  table=__lowerCamelCase	)

		UpperCamelCase     :int          =	predictions == references

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