





'''simple docstring'''







from __future__ import annotations

import copy
import inspect
import json
import math
import os
import tempfile
import unittest
from importlib import import_module

import numpy as np

from transformers import ViTMAEConfig
from transformers.file_utils import cached_property, is_tf_available, is_vision_available
from transformers.testing_utils import require_tf, require_vision, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
					import tensorflow as tf

					from transformers import TFViTMAEForPreTraining, TFViTMAEModel


if is_vision_available():
					from PIL import Image

					from transformers import ViTImageProcessor


class     __a					:

							def __init__(							self							:   int				,   __magic_name__							:   List[str]				,   __magic_name__							:   int=13				,   __magic_name__							:   Union[str, Any]=30				,   __magic_name__							:   Optional[Any]=2				,   __magic_name__							:   Optional[Any]=3				,   __magic_name__							:   Any=True				,   __magic_name__							:   str=True				,   __magic_name__							:   Tuple=32				,   __magic_name__							:   Optional[Any]=2				,   __magic_name__							:   Optional[int]=4				,   __magic_name__							:   List[str]=37				,   __magic_name__							:   Tuple="gelu"				,   __magic_name__							:   Optional[int]=0.1				,   __magic_name__							:   str=0.1				,   __magic_name__							:   int=10				,   __magic_name__							:   List[str]=0.0_2				,   __magic_name__							:   Tuple=3				,   __magic_name__							:   List[str]=0.6				,   __magic_name__							:   Dict=None				,   )    ->				str:







													"""simple docstring"""
													UpperCAmelCase_	:					Optional[int]     =     parent
													UpperCAmelCase_	:					str     =     batch_size
													UpperCAmelCase_	:					Tuple     =     image_size
													UpperCAmelCase_	:					Optional[int]     =     patch_size
													UpperCAmelCase_	:					Optional[int]     =     num_channels
													UpperCAmelCase_	:					Any     =     is_training
													UpperCAmelCase_	:					Union[str, Any]     =     use_labels
													UpperCAmelCase_	:					Union[str, Any]     =     hidden_size
													UpperCAmelCase_	:					Optional[Any]     =     num_hidden_layers
													UpperCAmelCase_	:					List[Any]     =     num_attention_heads
													UpperCAmelCase_	:					Tuple     =     intermediate_size
													UpperCAmelCase_	:					Tuple     =     hidden_act
													UpperCAmelCase_	:					Any     =     hidden_dropout_prob
													UpperCAmelCase_	:					int     =     attention_probs_dropout_prob
													UpperCAmelCase_	:					int     =     type_sequence_label_size
													UpperCAmelCase_	:					Optional[Any]     =     initializer_range
													UpperCAmelCase_	:					Union[str, Any]     =     mask_ratio
													UpperCAmelCase_	:					Union[str, Any]     =     scope

													# in ViTMAE, the expected sequence length = (num_patches + 1) * (1 - config.mask_ratio), rounded above
													# (we add 1 for the [CLS] token)
													UpperCAmelCase_	:					Any     =     (image_size // patch_size) ** 2
													UpperCAmelCase_	:					Tuple     =     int(math.ceil((1 - mask_ratio) * (num_patches + 1)      )      )

							def 			UpperCAmelCase__		(							self							:   Dict      )    ->				Tuple:







													"""simple docstring"""
													UpperCAmelCase_	:					Optional[int]     =     floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]      )

													UpperCAmelCase_	:					Optional[int]     =     None
													if self.use_labels:
																			UpperCAmelCase_	:					Optional[Any]     =     ids_tensor([self.batch_size]				,   self.type_sequence_label_size      )

													UpperCAmelCase_	:					Optional[Any]     =     self.get_config()

													return config, pixel_values, labels

							def 			UpperCAmelCase__		(							self							:   Optional[int]      )    ->				Dict:







													"""simple docstring"""
													return ViTMAEConfig(
													    image_size=self.image_size				,   patch_size=self.patch_size				,   num_channels=self.num_channels				,   hidden_size=self.hidden_size				,   num_hidden_layers=self.num_hidden_layers				,   num_attention_heads=self.num_attention_heads				,   intermediate_size=self.intermediate_size				,   decoder_hidden_size=self.hidden_size				,   decoder_num_hidden_layers=self.num_hidden_layers				,   decoder_num_attention_heads=self.num_attention_heads				,   decoder_intermediate_size=self.intermediate_size				,   hidden_act=self.hidden_act				,   hidden_dropout_prob=self.hidden_dropout_prob				,   attention_probs_dropout_prob=self.attention_probs_dropout_prob				,   is_decoder=UpperCamelCase__				,   initializer_range=self.initializer_range				,   mask_ratio=self.mask_ratio				,   )

							def 			UpperCAmelCase__		(							self							:   List[Any]				,   __magic_name__							:   Optional[Any]				,   __magic_name__							:   Optional[Any]				,   __magic_name__							:   int      )    ->				str:







													"""simple docstring"""
													UpperCAmelCase_	:					List[str]     =     TFViTMAEModel(config=UpperCamelCase__      )
													UpperCAmelCase_	:					str     =     model(UpperCamelCase__				,   training=UpperCamelCase__      )
													self.parent.assertEqual(result.last_hidden_state.shape				,   (self.batch_size, self.seq_length, self.hidden_size)      )

							def 			UpperCAmelCase__		(							self							:   Optional[int]				,   __magic_name__							:   Optional[int]				,   __magic_name__							:   Any				,   __magic_name__							:   Optional[int]      )    ->				Any:







													"""simple docstring"""
													UpperCAmelCase_	:					Any     =     TFViTMAEForPreTraining(UpperCamelCase__      )
													UpperCAmelCase_	:					Any     =     model(UpperCamelCase__				,   training=UpperCamelCase__      )
													# expected sequence length = num_patches
													UpperCAmelCase_	:					Dict     =     (self.image_size // self.patch_size) ** 2
													UpperCAmelCase_	:					Any     =     self.patch_size**2 * self.num_channels
													self.parent.assertEqual(result.logits.shape				,   (self.batch_size, num_patches, expected_num_channels)      )

													# test greyscale images
													UpperCAmelCase_	:					int     =     1
													UpperCAmelCase_	:					List[Any]     =     TFViTMAEForPreTraining(UpperCamelCase__      )

													UpperCAmelCase_	:					Optional[Any]     =     floats_tensor([self.batch_size, 1, self.image_size, self.image_size]      )
													UpperCAmelCase_	:					int     =     model(UpperCamelCase__				,   training=UpperCamelCase__      )
													UpperCAmelCase_	:					Any     =     self.patch_size**2
													self.parent.assertEqual(result.logits.shape				,   (self.batch_size, num_patches, expected_num_channels)      )



							def 			UpperCAmelCase__		(							self							:   Optional[Any]      )    ->				Optional[int]:







													"""simple docstring"""
													UpperCAmelCase_	:					Dict     =     self.prepare_config_and_inputs()
													((UpperCAmelCase_)  ,				(UpperCAmelCase_)  ,				(UpperCAmelCase_))	:					List[str]     =     config_and_inputs
													UpperCAmelCase_	:					Tuple     =     {'''pixel_values''': pixel_values}
													return config, inputs_dict





@require_tf
class     __a					(_A				,						_A				,						unittest.TestCase   ):
							__a    :      Dict  	=				(TFViTMAEModel, TFViTMAEForPreTraining) if is_tf_available() else ()
							__a    :      List[Any]  	=				{"feature-extraction": TFViTMAEModel} if is_tf_available() else {}

							__a    :      Union[str, Any]  	=				False
							__a    :      Dict  	=				False
							__a    :      str  	=				False
							__a    :      Optional[Any]  	=				False

							def 			UpperCAmelCase__		(							self							:   Tuple      )    ->				List[Any]:







													"""simple docstring"""
													UpperCAmelCase_	:					Tuple     =     TFViTMAEModelTester(self      )
													UpperCAmelCase_	:					Any     =     ConfigTester(self				,   config_class=UpperCamelCase__				,   has_text_modality=UpperCamelCase__				,   hidden_size=37      )

							def 			UpperCAmelCase__		(							self							:   Optional[int]      )    ->				str:







													"""simple docstring"""
													self.config_tester.run_common_tests()

							@unittest.skip(reason='''ViTMAE does not use inputs_embeds'''      )
							def 			UpperCAmelCase__		(							self							:   Tuple      )    ->				List[Any]:







													"""simple docstring"""
													pass

							def 			UpperCAmelCase__		(							self							:   Optional[int]      )    ->				Any:







													"""simple docstring"""
													UpperCAmelCase_  ,				UpperCAmelCase_	:					int     =     self.model_tester.prepare_config_and_inputs_for_common()

													for model_class in self.all_model_classes:
																			UpperCAmelCase_	:					Optional[int]     =     model_class(UpperCamelCase__      )
																			self.assertIsInstance(model.get_input_embeddings()				,   (tf.keras.layers.Layer)      )
																			UpperCAmelCase_	:					Any     =     model.get_output_embeddings()
																			self.assertTrue(x is None or isinstance(UpperCamelCase__				,   tf.keras.layers.Layer      )      )

							def 			UpperCAmelCase__		(							self							:   List[Any]      )    ->				List[Any]:







													"""simple docstring"""
													UpperCAmelCase_  ,				UpperCAmelCase_	:					Optional[int]     =     self.model_tester.prepare_config_and_inputs_for_common()

													for model_class in self.all_model_classes:
																			UpperCAmelCase_	:					str     =     model_class(UpperCamelCase__      )
																			UpperCAmelCase_	:					Optional[Any]     =     inspect.signature(model.call      )
																			# signature.parameters is an OrderedDict => so arg_names order is deterministic
																			UpperCAmelCase_	:					Dict     =     [*signature.parameters.keys()]

																			UpperCAmelCase_	:					Union[str, Any]     =     ['''pixel_values''']
																			self.assertListEqual(arg_names[:1]				,   UpperCamelCase__      )

							def 			UpperCAmelCase__		(							self							:   List[Any]      )    ->				str:







													"""simple docstring"""
													UpperCAmelCase_	:					str     =     self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_model(*UpperCamelCase__      )

							def 			UpperCAmelCase__		(							self							:   Any      )    ->				Optional[int]:







													"""simple docstring"""
													UpperCAmelCase_	:					List[Any]     =     self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_pretraining(*UpperCamelCase__      )

							def 			UpperCAmelCase__		(							self							:   Union[str, Any]      )    ->				Optional[int]:







													"""simple docstring"""
													np.random.seed(2      )

													UpperCAmelCase_  ,				UpperCAmelCase_	:					str     =     self.model_tester.prepare_config_and_inputs_for_common()

													UpperCAmelCase_	:					Dict     =     int((config.image_size // config.patch_size) ** 2      )
													UpperCAmelCase_	:					Tuple     =     np.random.uniform(size=(self.model_tester.batch_size, num_patches)      )

													for model_class in self.all_model_classes:
																			UpperCAmelCase_	:					str     =     model_class(UpperCamelCase__      )
																			UpperCAmelCase_	:					Any     =     self._prepare_for_class(UpperCamelCase__				,   UpperCamelCase__      )

																			UpperCAmelCase_	:					List[str]     =     model(UpperCamelCase__				,   noise=UpperCamelCase__      )

																			UpperCAmelCase_	:					List[Any]     =     copy.deepcopy(self._prepare_for_class(UpperCamelCase__				,   UpperCamelCase__      )      )
																			UpperCAmelCase_	:					List[Any]     =     model(**UpperCamelCase__				,   noise=UpperCamelCase__      )
																			UpperCAmelCase_	:					str     =     outputs_dict[0].numpy()
																			UpperCAmelCase_	:					Any     =     outputs_keywords[0].numpy()

																			self.assertLess(np.sum(np.abs(output_dict - output_keywords      )      )				,   1E-6      )

							def 			UpperCAmelCase__		(							self							:   Dict      )    ->				Any:







													"""simple docstring"""
													np.random.seed(2      )

													UpperCAmelCase_  ,				UpperCAmelCase_	:					Any     =     self.model_tester.prepare_config_and_inputs_for_common()

													UpperCAmelCase_	:					Optional[int]     =     int((config.image_size // config.patch_size) ** 2      )
													UpperCAmelCase_	:					List[str]     =     np.random.uniform(size=(self.model_tester.batch_size, num_patches)      )

													def prepare_numpy_arrays(__magic_name__							:   int      ):
																			UpperCAmelCase_	:					Any     =     {}
																			for k, v in inputs_dict.items():
																									if tf.is_tensor(UpperCamelCase__      ):
																															UpperCAmelCase_	:					Union[str, Any]     =     v.numpy()
																									else:
																															UpperCAmelCase_	:					int     =     np.array(UpperCamelCase__      )

																			return inputs_np_dict

													for model_class in self.all_model_classes:
																			UpperCAmelCase_	:					int     =     model_class(UpperCamelCase__      )

																			UpperCAmelCase_	:					Optional[Any]     =     self._prepare_for_class(UpperCamelCase__				,   UpperCamelCase__      )
																			UpperCAmelCase_	:					Any     =     prepare_numpy_arrays(UpperCamelCase__      )

																			UpperCAmelCase_	:					Any     =     model(UpperCamelCase__				,   noise=UpperCamelCase__      )
																			UpperCAmelCase_	:					List[str]     =     model(**UpperCamelCase__				,   noise=UpperCamelCase__      )
																			self.assert_outputs_same(UpperCamelCase__				,   UpperCamelCase__      )

							def 			UpperCAmelCase__		(							self							:   str				,   __magic_name__							:   Tuple				,   __magic_name__							:   Any				,   __magic_name__							:   Tuple      )    ->				List[Any]:







													"""simple docstring"""
													np.random.seed(2      )

													UpperCAmelCase_	:					Tuple     =     int((tf_model.config.image_size // tf_model.config.patch_size) ** 2      )
													UpperCAmelCase_	:					Any     =     np.random.uniform(size=(self.model_tester.batch_size, num_patches)      )
													UpperCAmelCase_	:					str     =     tf.constant(UpperCamelCase__      )

													# Add `noise` argument.
													# PT inputs will be prepared in `super().check_pt_tf_models()` with this added `noise` argument
													UpperCAmelCase_	:					Optional[Any]     =     tf_noise

													super().check_pt_tf_models(UpperCamelCase__				,   UpperCamelCase__				,   UpperCamelCase__      )

							def 			UpperCAmelCase__		(							self							:   List[str]      )    ->				Dict:







													"""simple docstring"""
													np.random.seed(2      )

													UpperCAmelCase_  ,				UpperCAmelCase_	:					Tuple     =     self.model_tester.prepare_config_and_inputs_for_common()

													UpperCAmelCase_	:					Dict     =     {
													    module_member
													    for model_class in self.all_model_classes
													    for module in (import_module(model_class.__module__      ),)
													    for module_member_name in dir(UpperCamelCase__      )
													    if module_member_name.endswith('''MainLayer'''      )
													    # This condition is required, since `modeling_tf_clip.py` has 3 classes whose names end with `MainLayer`.
													    and module_member_name[: -len('''MainLayer'''      )] == model_class.__name__[: -len('''Model'''      )]
													    for module_member in (getattr(UpperCamelCase__				,   UpperCamelCase__      ),)
													    if isinstance(UpperCamelCase__				,   UpperCamelCase__      )
													    and tf.keras.layers.Layer in module_member.__bases__
													    and getattr(UpperCamelCase__				,   '''_keras_serializable'''				,   UpperCamelCase__      )
													}

													UpperCAmelCase_	:					List[Any]     =     int((config.image_size // config.patch_size) ** 2      )
													UpperCAmelCase_	:					Dict     =     np.random.uniform(size=(self.model_tester.batch_size, num_patches)      )
													UpperCAmelCase_	:					List[Any]     =     tf.convert_to_tensor(UpperCamelCase__      )
													inputs_dict.update({'''noise''': noise}      )

													for main_layer_class in tf_main_layer_classes:
																			UpperCAmelCase_	:					Tuple     =     main_layer_class(UpperCamelCase__      )

																			UpperCAmelCase_	:					Tuple     =     {
																			    name: tf.keras.Input(tensor.shape[1:]				,   dtype=tensor.dtype      ) for name, tensor in inputs_dict.items()
																			}

																			UpperCAmelCase_	:					str     =     tf.keras.Model(UpperCamelCase__				,   outputs=main_layer(UpperCamelCase__      )      )
																			UpperCAmelCase_	:					Any     =     model(UpperCamelCase__      )

																			with tempfile.TemporaryDirectory() as tmpdirname:
																									UpperCAmelCase_	:					int     =     os.path.join(UpperCamelCase__				,   '''keras_model.h5'''      )
																									model.save(UpperCamelCase__      )
																									UpperCAmelCase_	:					Optional[int]     =     tf.keras.models.load_model(
																									    UpperCamelCase__				,   custom_objects={main_layer_class.__name__: main_layer_class}      )
																									assert isinstance(UpperCamelCase__				,   tf.keras.Model      )
																									UpperCAmelCase_	:					str     =     model(UpperCamelCase__      )
																									self.assert_outputs_same(UpperCamelCase__				,   UpperCamelCase__      )

							@slow
							def 			UpperCAmelCase__		(							self							:   Optional[int]      )    ->				Dict:







													"""simple docstring"""
													np.random.seed(2      )

													UpperCAmelCase_  ,				UpperCAmelCase_	:					str     =     self.model_tester.prepare_config_and_inputs_for_common()

													UpperCAmelCase_	:					List[Any]     =     int((config.image_size // config.patch_size) ** 2      )
													UpperCAmelCase_	:					int     =     np.random.uniform(size=(self.model_tester.batch_size, num_patches)      )

													for model_class in self.all_model_classes:
																			UpperCAmelCase_	:					Optional[Any]     =     model_class(UpperCamelCase__      )
																			UpperCAmelCase_	:					Dict     =     self._prepare_for_class(UpperCamelCase__				,   UpperCamelCase__      )
																			UpperCAmelCase_	:					str     =     model(UpperCamelCase__				,   noise=UpperCamelCase__      )

																			if model_class.__name__ == "TFViTMAEModel":
																									UpperCAmelCase_	:					int     =     outputs.last_hidden_state.numpy()
																									UpperCAmelCase_	:					int     =     0
																			else:
																									UpperCAmelCase_	:					Union[str, Any]     =     outputs.logits.numpy()
																									UpperCAmelCase_	:					Any     =     0

																			with tempfile.TemporaryDirectory() as tmpdirname:
																									model.save_pretrained(UpperCamelCase__				,   saved_model=UpperCamelCase__      )
																									UpperCAmelCase_	:					Optional[int]     =     model_class.from_pretrained(UpperCamelCase__      )
																									UpperCAmelCase_	:					int     =     model(UpperCamelCase__				,   noise=UpperCamelCase__      )

																									if model_class.__name__ == "TFViTMAEModel":
																															UpperCAmelCase_	:					Tuple     =     after_outputs['''last_hidden_state'''].numpy()
																															UpperCAmelCase_	:					str     =     0
																									else:
																															UpperCAmelCase_	:					Dict     =     after_outputs['''logits'''].numpy()
																															UpperCAmelCase_	:					Any     =     0

																									UpperCAmelCase_	:					Any     =     np.amax(np.abs(out_a - out_a      )      )
																									self.assertLessEqual(UpperCamelCase__				,   1E-5      )

							def 			UpperCAmelCase__		(							self							:   Any      )    ->				Union[str, Any]:







													"""simple docstring"""
													np.random.seed(2      )

													UpperCAmelCase_  ,				UpperCAmelCase_	:					Optional[Any]     =     self.model_tester.prepare_config_and_inputs_for_common()

													UpperCAmelCase_	:					Any     =     int((config.image_size // config.patch_size) ** 2      )
													UpperCAmelCase_	:					Union[str, Any]     =     np.random.uniform(size=(self.model_tester.batch_size, num_patches)      )

													for model_class in self.all_model_classes:
																			UpperCAmelCase_	:					Optional[int]     =     model_class(UpperCamelCase__      )
																			UpperCAmelCase_	:					List[Any]     =     self._prepare_for_class(UpperCamelCase__				,   UpperCamelCase__      )

																			UpperCAmelCase_	:					List[str]     =     model(UpperCamelCase__				,   noise=UpperCamelCase__      )
																			UpperCAmelCase_	:					Any     =     model.get_config()
																			# make sure that returned config is jsonifiable, which is required by keras
																			json.dumps(UpperCamelCase__      )
																			UpperCAmelCase_	:					List[str]     =     model_class.from_config(model.get_config()      )
																			# make sure it also accepts a normal config
																			UpperCAmelCase_	:					int     =     model_class.from_config(model.config      )
																			UpperCAmelCase_	:					Optional[int]     =     new_model(UpperCamelCase__      )  # Build model
																			new_model.set_weights(model.get_weights()      )
																			UpperCAmelCase_	:					Tuple     =     new_model(UpperCamelCase__				,   noise=UpperCamelCase__      )

																			self.assert_outputs_same(UpperCamelCase__				,   UpperCamelCase__      )

							@unittest.skip(
							    reason='''ViTMAE returns a random mask + ids_restore in each forward pass. See test_save_load
    to get deterministic results.'''      )
							def 			UpperCAmelCase__		(							self							:   Dict      )    ->				Any:







													"""simple docstring"""
													pass

							@unittest.skip(reason='''ViTMAE returns a random mask + ids_restore in each forward pass. See test_save_load'''      )
							def 			UpperCAmelCase__		(							self							:   Union[str, Any]      )    ->				List[Any]:







													"""simple docstring"""
													pass



							@slow
							def 			UpperCAmelCase__		(							self							:   Any      )    ->				str:







													"""simple docstring"""
													UpperCAmelCase_	:					Tuple     =     TFViTMAEModel.from_pretrained('''google/vit-base-patch16-224'''      )
													self.assertIsNotNone(UpperCamelCase__      )





def 				lowerCamelCase_					(     )       ->		Union[str, Any]:
						UpperCAmelCase_	:					List[str]     =     Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''      )
						return image


@require_tf
@require_vision
class     __a					(unittest.TestCase   ):

							@cached_property
							def 			UpperCAmelCase__		(							self							:   Optional[Any]      )    ->				Union[str, Any]:







													"""simple docstring"""
													return ViTImageProcessor.from_pretrained('''facebook/vit-mae-base'''      ) if is_vision_available() else None



							@slow
							def 			UpperCAmelCase__		(							self							:   Dict      )    ->				int:







													"""simple docstring"""
													np.random.seed(2      )

													UpperCAmelCase_	:					Optional[Any]     =     TFViTMAEForPreTraining.from_pretrained('''facebook/vit-mae-base'''      )

													UpperCAmelCase_	:					List[Any]     =     self.default_image_processor
													UpperCAmelCase_	:					Any     =     prepare_img()
													UpperCAmelCase_	:					List[Any]     =     image_processor(images=UpperCamelCase__				,   return_tensors='''tf'''      )

													# prepare a noise vector that will be also used for testing the TF model
													# (this way we can ensure that the PT and TF models operate on the same inputs)
													UpperCAmelCase_	:					str     =     ViTMAEConfig()
													UpperCAmelCase_	:					Optional[Any]     =     int((vit_mae_config.image_size // vit_mae_config.patch_size) ** 2      )
													UpperCAmelCase_	:					List[Any]     =     np.random.uniform(size=(1, num_patches)      )

													# forward pass
													UpperCAmelCase_	:					Optional[int]     =     model(**UpperCamelCase__				,   noise=UpperCamelCase__      )

													# verify the logits
													UpperCAmelCase_	:					List[Any]     =     tf.convert_to_tensor([1, 1_96, 7_68]      )
													self.assertEqual(outputs.logits.shape				,   UpperCamelCase__      )

													UpperCAmelCase_	:					Dict     =     tf.convert_to_tensor(
													    [[-0.0_5_4_8, -1.7_0_2_3, -0.9_3_2_5], [0.3_7_2_1, -0.5_6_7_0, -0.2_2_3_3], [0.8_2_3_5, -1.3_8_7_8, -0.3_5_2_4]]      )

													tf.debugging.assert_near(outputs.logits[0, :3, :3]				,   UpperCamelCase__				,   atol=1E-4      )







import re
import string

import numpy as np

import datasets


__lowerCAmelCase			:     Optional[int]           =   '\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'

__lowerCAmelCase			:     Optional[int]           =   '\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'

__lowerCAmelCase			:     Optional[int]           =   '\n'




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


  '''simple docstring'''







  def 							_lowercase							( self			: str    )			->	Optional[int]:







    """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 							_lowercase							( self			: Optional[int]			,							UpperCamelCase__			: Optional[Any]			,							UpperCamelCase__			: Tuple			,							UpperCamelCase__			: Optional[Any]=None			,							UpperCamelCase__			: Optional[Any]=False			,							UpperCamelCase__			: int=False			,							UpperCamelCase__			: Tuple=False			,							)			->	Dict:







    """simple docstring"""






    if regexes_to_ignore is not None:
      for s in regexes_to_ignore:
        __magic_name__				     =       np.array([re.sub(UpperCamelCase__			,							""""""			,							UpperCamelCase__    ) for x in predictions]    )
        __magic_name__				     =       np.array([re.sub(UpperCamelCase__			,							""""""			,							UpperCamelCase__    ) for x in references]    )
    else:
      __magic_name__				     =       np.asarray(UpperCamelCase__    )
      __magic_name__				     =       np.asarray(UpperCamelCase__    )

    if ignore_case:
      __magic_name__				     =       np.char.lower(UpperCamelCase__    )
      __magic_name__				     =       np.char.lower(UpperCamelCase__    )

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

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

    __magic_name__				     =       predictions == references

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

