





'''simple docstring'''


import inspect
import unittest

import numpy as np

from tests.test_modeling_common import floats_tensor
from transformers import DetrConfig, MaskFormerConfig, SwinConfig, is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_torch_multi_gpu, require_vision, slow, torch_device
from transformers.utils import cached_property

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
       import torch

       from transformers import MaskFormerForInstanceSegmentation, MaskFormerModel

       if is_vision_available():
              from transformers import MaskFormerImageProcessor

if is_vision_available():
       from PIL import Image

class  lowerCAmelCase_		:




 def __init__(						self      ,  _lowerCAmelCase      ,  _lowerCAmelCase=2      ,  _lowerCAmelCase=True      ,  _lowerCAmelCase=False      ,  _lowerCAmelCase=10      ,  _lowerCAmelCase=3      ,  _lowerCAmelCase=32 * 4      ,  _lowerCAmelCase=32 * 6      ,  _lowerCAmelCase=4      ,  _lowerCAmelCase=32      ,  )     ->				Tuple:
     _lowerCAmelCase						      =   parent
     _lowerCAmelCase						      =   batch_size
     _lowerCAmelCase						      =   is_training
     _lowerCAmelCase						      =   use_auxiliary_loss
     _lowerCAmelCase						      =   num_queries
     _lowerCAmelCase						      =   num_channels
     _lowerCAmelCase						      =   min_size
     _lowerCAmelCase						      =   max_size
     _lowerCAmelCase						      =   num_labels
     _lowerCAmelCase						      =   mask_feature_size




 def 				_snake_case (						self		)     ->				int:
     _lowerCAmelCase						      =   floats_tensor([self.batch_size, self.num_channels, self.min_size, self.max_size]		).to(
         _lowerCAmelCase		)

     _lowerCAmelCase						      =   torch.ones([self.batch_size, self.min_size, self.max_size]      ,  device=_lowerCAmelCase		)

     _lowerCAmelCase						      =   (
         torch.rand([self.batch_size, self.num_labels, self.min_size, self.max_size]      ,  device=_lowerCAmelCase		) > 0.5
     ).float()
     _lowerCAmelCase						      =   (torch.rand((self.batch_size, self.num_labels)      ,  device=_lowerCAmelCase		) > 0.5).long()

     _lowerCAmelCase						      =   self.get_config()
     return config, pixel_values, pixel_mask, mask_labels, class_labels




 def 				_snake_case (						self		)     ->				Optional[Any]:
     return MaskFormerConfig.from_backbone_and_decoder_configs(
         backbone_config=SwinConfig(
             depths=[1, 1, 1, 1]      ,  )      ,  decoder_config=DetrConfig(
             decoder_ffn_dim=128      ,  num_queries=self.num_queries      ,  decoder_attention_heads=2      ,  d_model=self.mask_feature_size      ,  )      ,  mask_feature_size=self.mask_feature_size      ,  fpn_feature_size=self.mask_feature_size      ,  num_channels=self.num_channels      ,  num_labels=self.num_labels      ,  )




 def 				_snake_case (						self		)     ->				int:
     _lowerCAmelCase      ,      _lowerCAmelCase      ,      _lowerCAmelCase      ,      _lowerCAmelCase      ,      _lowerCAmelCase						      =   self.prepare_config_and_inputs()
     _lowerCAmelCase						      =   {"pixel_values": pixel_values, "pixel_mask": pixel_mask}
     return config, inputs_dict




 def 				_snake_case (						self      ,  _lowerCAmelCase      ,  _lowerCAmelCase		)     ->				Optional[Any]:
     _lowerCAmelCase						      =   output.encoder_hidden_states
     _lowerCAmelCase						      =   output.pixel_decoder_hidden_states
     _lowerCAmelCase						      =   output.transformer_decoder_hidden_states

     self.parent.assertTrue(len(_lowerCAmelCase		)      ,  len(config.backbone_config.depths		)		)
     self.parent.assertTrue(len(_lowerCAmelCase		)      ,  len(config.backbone_config.depths		)		)
     self.parent.assertTrue(len(_lowerCAmelCase		)      ,  config.decoder_config.decoder_layers		)




 def 				_snake_case (						self      ,  _lowerCAmelCase      ,  _lowerCAmelCase      ,  _lowerCAmelCase      ,  _lowerCAmelCase=False		)     ->				List[str]:
     with torch.no_grad():
         _lowerCAmelCase						      =   MaskFormerModel(config=_lowerCAmelCase		)
         model.to(_lowerCAmelCase		)
         model.eval()

         _lowerCAmelCase						      =   model(pixel_values=_lowerCAmelCase      ,  pixel_mask=_lowerCAmelCase		)
         _lowerCAmelCase						      =   model(_lowerCAmelCase      ,  output_hidden_states=_lowerCAmelCase		)
     # the correct shape of output.transformer_decoder_hidden_states ensure the correcteness of the
     # encoder and pixel decoder
     self.parent.assertEqual(
         output.transformer_decoder_last_hidden_state.shape      ,  (self.batch_size, self.num_queries, self.mask_feature_size)      ,  )
     # let's ensure the other two hidden state exists
     self.parent.assertTrue(output.pixel_decoder_last_hidden_state is not None		)
     self.parent.assertTrue(output.encoder_last_hidden_state is not None		)

     if output_hidden_states:
         self.check_output_hidden_state(_lowerCAmelCase      ,  _lowerCAmelCase		)





 def 				_snake_case (						self      ,  _lowerCAmelCase      ,  _lowerCAmelCase      ,  _lowerCAmelCase      ,  _lowerCAmelCase      ,  _lowerCAmelCase		)     ->				Dict:
     _lowerCAmelCase						      =   MaskFormerForInstanceSegmentation(config=_lowerCAmelCase		)
     model.to(_lowerCAmelCase		)
     model.eval()

     def comm_check_on_output(_lowerCAmelCase		):
         # let's still check that all the required stuff is there
         self.parent.assertTrue(result.transformer_decoder_last_hidden_state is not None		)
         self.parent.assertTrue(result.pixel_decoder_last_hidden_state is not None		)
         self.parent.assertTrue(result.encoder_last_hidden_state is not None		)
         # okay, now we need to check the logits shape
         # due to the encoder compression, masks have a //4 spatial size
         self.parent.assertEqual(
             result.masks_queries_logits.shape      ,  (self.batch_size, self.num_queries, self.min_size // 4, self.max_size // 4)      ,  )
         # + 1 for null class
         self.parent.assertEqual(
             result.class_queries_logits.shape      ,  (self.batch_size, self.num_queries, self.num_labels + 1)		)

     with torch.no_grad():
         _lowerCAmelCase						      =   model(pixel_values=_lowerCAmelCase      ,  pixel_mask=_lowerCAmelCase		)
         _lowerCAmelCase						      =   model(_lowerCAmelCase		)

         comm_check_on_output(_lowerCAmelCase		)

         _lowerCAmelCase						      =   model(
             pixel_values=_lowerCAmelCase      ,  pixel_mask=_lowerCAmelCase      ,  mask_labels=_lowerCAmelCase      ,  class_labels=_lowerCAmelCase		)

     comm_check_on_output(_lowerCAmelCase		)

     self.parent.assertTrue(result.loss is not None		)
     self.parent.assertEqual(result.loss.shape      ,  torch.Size([1]		)		)







@require_torch
class  lowerCAmelCase_		(		__magic_name__    ,__magic_name__    ,unittest.TestCase		):
 __lowerCamelCase    :				List[str]								=       (MaskFormerModel, MaskFormerForInstanceSegmentation) if is_torch_available() else ()
 __lowerCamelCase    :				List[str]								=       (
     {"feature-extraction": MaskFormerModel, "image-segmentation": MaskFormerForInstanceSegmentation}
     if is_torch_available()
     else {}
 )

 __lowerCamelCase    :				Any								=       False
 __lowerCamelCase    :				List[str]								=       False
 __lowerCamelCase    :				Union[str, Any]								=       False
 __lowerCamelCase    :				int								=       False




 def 				_snake_case (						self		)     ->				Any:
     _lowerCAmelCase						      =   MaskFormerModelTester(self		)
     _lowerCAmelCase						      =   ConfigTester(self      ,  config_class=_lowerCAmelCase      ,  has_text_modality=_lowerCAmelCase		)




 def 				_snake_case (						self		)     ->				Tuple:
     self.config_tester.run_common_tests()




 def 				_snake_case (						self		)     ->				int:
     _lowerCAmelCase      ,      _lowerCAmelCase						      =   self.model_tester.prepare_config_and_inputs_for_common()
     self.model_tester.create_and_check_maskformer_model(_lowerCAmelCase      ,  **_lowerCAmelCase      ,  output_hidden_states=_lowerCAmelCase		)




 def 				_snake_case (						self		)     ->				Dict:
     _lowerCAmelCase						      =   self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_maskformer_instance_segmentation_head_model(*_lowerCAmelCase		)




 @unittest.skip(reason="MaskFormer does not use inputs_embeds"		)
 def 				_snake_case (						self		)     ->				List[Any]:
     pass




 @unittest.skip(reason="MaskFormer does not have a get_input_embeddings method"		)
 def 				_snake_case (						self		)     ->				Any:
     pass




 @unittest.skip(reason="MaskFormer is not a generative model"		)
 def 				_snake_case (						self		)     ->				Tuple:
     pass




 @unittest.skip(reason="MaskFormer does not use token embeddings"		)
 def 				_snake_case (						self		)     ->				str:
     pass




 @require_torch_multi_gpu
 @unittest.skip(
     reason="MaskFormer has some layers using `add_module` which doesn't work well with `nn.DataParallel`"		)
 def 				_snake_case (						self		)     ->				Union[str, Any]:
     pass




 @unittest.skip("Will be fixed soon by reducing the size of the model used for common tests."		)
 def 				_snake_case (						self		)     ->				Optional[int]:
     pass




 def 				_snake_case (						self		)     ->				Dict:
     _lowerCAmelCase      ,      _lowerCAmelCase						      =   self.model_tester.prepare_config_and_inputs_for_common()

     for model_class in self.all_model_classes:
         _lowerCAmelCase						      =   model_class(_lowerCAmelCase		)
         _lowerCAmelCase						      =   inspect.signature(model.forward		)
         # signature.parameters is an OrderedDict => so arg_names order is deterministic
         _lowerCAmelCase						      =   [*signature.parameters.keys()]

         _lowerCAmelCase						      =   ["pixel_values"]
         self.assertListEqual(arg_names[:1]      ,  _lowerCAmelCase		)




 @slow
 def 				_snake_case (						self		)     ->				Dict:
     for model_name in ["facebook/maskformer-swin-small-coco"]:
         _lowerCAmelCase						      =   MaskFormerModel.from_pretrained(_lowerCAmelCase		)
         self.assertIsNotNone(_lowerCAmelCase		)




 def 				_snake_case (						self		)     ->				List[str]:
     _lowerCAmelCase						      =   (self.model_tester.min_size,) * 2
     _lowerCAmelCase						      =   {
         "pixel_values": torch.randn((2, 3, *size)      ,  device=_lowerCAmelCase		),
         "mask_labels": torch.randn((2, 10, *size)      ,  device=_lowerCAmelCase		),
         "class_labels": torch.zeros(2      ,  10      ,  device=_lowerCAmelCase		).long(),
     }

     _lowerCAmelCase						      =   MaskFormerForInstanceSegmentation(MaskFormerConfig()		).to(_lowerCAmelCase		)
     _lowerCAmelCase						      =   model(**_lowerCAmelCase		)
     self.assertTrue(outputs.loss is not None		)




 def 				_snake_case (						self		)     ->				List[Any]:
     _lowerCAmelCase      ,      _lowerCAmelCase						      =   self.model_tester.prepare_config_and_inputs_for_common()
     self.model_tester.create_and_check_maskformer_model(_lowerCAmelCase      ,  **_lowerCAmelCase      ,  output_hidden_states=_lowerCAmelCase		)




 def 				_snake_case (						self		)     ->				Optional[int]:
     _lowerCAmelCase      ,      _lowerCAmelCase						      =   self.model_tester.prepare_config_and_inputs_for_common()

     for model_class in self.all_model_classes:
         _lowerCAmelCase						      =   model_class(_lowerCAmelCase		).to(_lowerCAmelCase		)
         _lowerCAmelCase						      =   model(**_lowerCAmelCase      ,  output_attentions=_lowerCAmelCase		)
         self.assertTrue(outputs.attentions is not None		)




 def 				_snake_case (						self		)     ->				Optional[Any]:
     if not self.model_tester.is_training:
         return
     # only MaskFormerForInstanceSegmentation has the loss
     _lowerCAmelCase						      =   self.all_model_classes[1]
     _lowerCAmelCase      ,      _lowerCAmelCase      ,      _lowerCAmelCase      ,      _lowerCAmelCase      ,      _lowerCAmelCase						      =   self.model_tester.prepare_config_and_inputs()

     _lowerCAmelCase						      =   model_class(_lowerCAmelCase		)
     model.to(_lowerCAmelCase		)
     model.train()

     _lowerCAmelCase						      =   model(_lowerCAmelCase      ,  mask_labels=_lowerCAmelCase      ,  class_labels=_lowerCAmelCase		).loss
     loss.backward()





 def 				_snake_case (						self		)     ->				Any:
     # only MaskFormerForInstanceSegmentation has the loss
     _lowerCAmelCase						      =   self.all_model_classes[1]
     _lowerCAmelCase      ,      _lowerCAmelCase      ,      _lowerCAmelCase      ,      _lowerCAmelCase      ,      _lowerCAmelCase						      =   self.model_tester.prepare_config_and_inputs()
     _lowerCAmelCase						      =   True
     _lowerCAmelCase						      =   True

     _lowerCAmelCase						      =   model_class(_lowerCAmelCase		)
     model.to(_lowerCAmelCase		)
     model.train()

     _lowerCAmelCase						      =   model(_lowerCAmelCase      ,  mask_labels=_lowerCAmelCase      ,  class_labels=_lowerCAmelCase		)

     _lowerCAmelCase						      =   outputs.encoder_hidden_states[0]
     encoder_hidden_states.retain_grad()

     _lowerCAmelCase						      =   outputs.pixel_decoder_hidden_states[0]
     pixel_decoder_hidden_states.retain_grad()
     # we requires_grad=True in inputs_embeds (line 2152), the original implementation don't
     _lowerCAmelCase						      =   outputs.transformer_decoder_hidden_states[0]
     transformer_decoder_hidden_states.retain_grad()

     _lowerCAmelCase						      =   outputs.attentions[0]
     attentions.retain_grad()

     outputs.loss.backward(retain_graph=_lowerCAmelCase		)

     self.assertIsNotNone(encoder_hidden_states.grad		)
     self.assertIsNotNone(pixel_decoder_hidden_states.grad		)
     self.assertIsNotNone(transformer_decoder_hidden_states.grad		)
     self.assertIsNotNone(attentions.grad		)







_SCREAMING_SNAKE_CASE									=				1e-4


def 						__a():



    '''simple docstring'''





    _lowerCAmelCase						      =   Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"     )
    return image





@require_vision
@slow
class  lowerCAmelCase_		(		unittest.TestCase		):




 @cached_property
 def 				_snake_case (						self		)     ->				Tuple:
     return (
         MaskFormerImageProcessor.from_pretrained("facebook/maskformer-swin-small-coco"		)
         if is_vision_available()
         else None
     )




 def 				_snake_case (						self		)     ->				Optional[Any]:
     _lowerCAmelCase						      =   MaskFormerModel.from_pretrained("facebook/maskformer-swin-small-coco"		).to(_lowerCAmelCase		)
     _lowerCAmelCase						      =   self.default_image_processor
     _lowerCAmelCase						      =   prepare_img()
     _lowerCAmelCase						      =   image_processor(_lowerCAmelCase      ,  return_tensors="pt"		).to(_lowerCAmelCase		)
     _lowerCAmelCase						      =   inputs["pixel_values"].shape
     # check size is divisible by 32
     self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0		)
     # check size
     self.assertEqual(_lowerCAmelCase      ,  (1, 3, 800, 1088)		)

     with torch.no_grad():
         _lowerCAmelCase						      =   model(**_lowerCAmelCase		)

     _lowerCAmelCase						      =   torch.tensor(
         [[-0.0482, 0.9228, 0.4951], [-0.2547, 0.8017, 0.8527], [-0.0069, 0.3385, -0.0089]]		).to(_lowerCAmelCase		)
     self.assertTrue(
         torch.allclose(
             outputs.encoder_last_hidden_state[0, 0, :3, :3]      ,  _lowerCAmelCase      ,  atol=_lowerCAmelCase		)		)

     _lowerCAmelCase						      =   torch.tensor(
         [[-0.8422, -0.8434, -0.9718], [-1.0144, -0.5565, -0.4195], [-1.0038, -0.4484, -0.1961]]		).to(_lowerCAmelCase		)
     self.assertTrue(
         torch.allclose(
             outputs.pixel_decoder_last_hidden_state[0, 0, :3, :3]      ,  _lowerCAmelCase      ,  atol=_lowerCAmelCase		)		)

     _lowerCAmelCase						      =   torch.tensor(
         [[0.2852, -0.0159, 0.9735], [0.6254, 0.1858, 0.8529], [-0.0680, -0.4116, 1.8413]]		).to(_lowerCAmelCase		)
     self.assertTrue(
         torch.allclose(
             outputs.transformer_decoder_last_hidden_state[0, :3, :3]      ,  _lowerCAmelCase      ,  atol=_lowerCAmelCase		)		)




 def 				_snake_case (						self		)     ->				Dict:
     _lowerCAmelCase						      =   (
         MaskFormerForInstanceSegmentation.from_pretrained("facebook/maskformer-swin-small-coco"		)
         .to(_lowerCAmelCase		)
         .eval()
     )
     _lowerCAmelCase						      =   self.default_image_processor
     _lowerCAmelCase						      =   prepare_img()
     _lowerCAmelCase						      =   image_processor(_lowerCAmelCase      ,  return_tensors="pt"		).to(_lowerCAmelCase		)
     _lowerCAmelCase						      =   inputs["pixel_values"].shape
     # check size is divisible by 32
     self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0		)
     # check size
     self.assertEqual(_lowerCAmelCase      ,  (1, 3, 800, 1088)		)

     with torch.no_grad():
         _lowerCAmelCase						      =   model(**_lowerCAmelCase		)
     # masks_queries_logits
     _lowerCAmelCase						      =   outputs.masks_queries_logits
     self.assertEqual(
         masks_queries_logits.shape      ,  (1, model.config.decoder_config.num_queries, inputs_shape[-2] // 4, inputs_shape[-1] // 4)      ,  )
     _lowerCAmelCase						      =   [
         [-1.3737124, -1.7724937, -1.9364233],
         [-1.5977281, -1.9867939, -2.1523695],
         [-1.5795398, -1.9269832, -2.093942],
     ]
     _lowerCAmelCase						      =   torch.tensor(_lowerCAmelCase		).to(_lowerCAmelCase		)
     self.assertTrue(torch.allclose(masks_queries_logits[0, 0, :3, :3]      ,  _lowerCAmelCase      ,  atol=_lowerCAmelCase		)		)
     # class_queries_logits
     _lowerCAmelCase						      =   outputs.class_queries_logits
     self.assertEqual(
         class_queries_logits.shape      ,  (1, model.config.decoder_config.num_queries, model.config.num_labels + 1)		)
     _lowerCAmelCase						      =   torch.tensor(
         [
             [1.6512E00, -5.2572E00, -3.3519E00],
             [3.6169E-02, -5.9025E00, -2.9313E00],
             [1.0766E-04, -7.7630E00, -5.1263E00],
         ]		).to(_lowerCAmelCase		)
     self.assertTrue(torch.allclose(outputs.class_queries_logits[0, :3, :3]      ,  _lowerCAmelCase      ,  atol=_lowerCAmelCase		)		)




 def 				_snake_case (						self		)     ->				Dict:
     _lowerCAmelCase						      =   (
         MaskFormerForInstanceSegmentation.from_pretrained("facebook/maskformer-resnet101-coco-stuff"		)
         .to(_lowerCAmelCase		)
         .eval()
     )
     _lowerCAmelCase						      =   self.default_image_processor
     _lowerCAmelCase						      =   prepare_img()
     _lowerCAmelCase						      =   image_processor(_lowerCAmelCase      ,  return_tensors="pt"		).to(_lowerCAmelCase		)
     _lowerCAmelCase						      =   inputs["pixel_values"].shape
     # check size is divisible by 32
     self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0		)
     # check size
     self.assertEqual(_lowerCAmelCase      ,  (1, 3, 800, 1088)		)

     with torch.no_grad():
         _lowerCAmelCase						      =   model(**_lowerCAmelCase		)
     # masks_queries_logits
     _lowerCAmelCase						      =   outputs.masks_queries_logits
     self.assertEqual(
         masks_queries_logits.shape      ,  (1, model.config.decoder_config.num_queries, inputs_shape[-2] // 4, inputs_shape[-1] // 4)      ,  )
     _lowerCAmelCase						      =   [[-0.9046, -2.6366, -4.6062], [-3.4179, -5.7890, -8.8057], [-4.9179, -7.6560, -10.7711]]
     _lowerCAmelCase						      =   torch.tensor(_lowerCAmelCase		).to(_lowerCAmelCase		)
     self.assertTrue(torch.allclose(masks_queries_logits[0, 0, :3, :3]      ,  _lowerCAmelCase      ,  atol=_lowerCAmelCase		)		)
     # class_queries_logits
     _lowerCAmelCase						      =   outputs.class_queries_logits
     self.assertEqual(
         class_queries_logits.shape      ,  (1, model.config.decoder_config.num_queries, model.config.num_labels + 1)		)
     _lowerCAmelCase						      =   torch.tensor(
         [[4.7188, -3.2585, -2.8857], [6.6871, -2.9181, -1.2487], [7.2449, -2.2764, -2.1874]]		).to(_lowerCAmelCase		)
     self.assertTrue(torch.allclose(outputs.class_queries_logits[0, :3, :3]      ,  _lowerCAmelCase      ,  atol=_lowerCAmelCase		)		)





 def 				_snake_case (						self		)     ->				Tuple:
     _lowerCAmelCase						      =   (
         MaskFormerForInstanceSegmentation.from_pretrained("facebook/maskformer-swin-small-coco"		)
         .to(_lowerCAmelCase		)
         .eval()
     )
     _lowerCAmelCase						      =   self.default_image_processor

     _lowerCAmelCase						      =   image_processor(
         [np.zeros((3, 800, 1333)		), np.zeros((3, 800, 1333)		)]      ,  segmentation_maps=[np.zeros((384, 384)		).astype(np.floataa		), np.zeros((384, 384)		).astype(np.floataa		)]      ,  return_tensors="pt"      ,  )

     _lowerCAmelCase						      =   inputs["pixel_values"].to(_lowerCAmelCase		)
     _lowerCAmelCase						      =   [el.to(_lowerCAmelCase		) for el in inputs["mask_labels"]]
     _lowerCAmelCase						      =   [el.to(_lowerCAmelCase		) for el in inputs["class_labels"]]

     with torch.no_grad():
         _lowerCAmelCase						      =   model(**_lowerCAmelCase		)

     self.assertTrue(outputs.loss is not None		)









'''simple docstring'''


import re
import string

import numpy as np

import datasets


_SCREAMING_SNAKE_CASE									=				"\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"

_SCREAMING_SNAKE_CASE									=				"\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"

_SCREAMING_SNAKE_CASE									=				"\n"

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




 def 				_snake_case (						self		)     ->				List[str]:
     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      ,  _lowerCAmelCase      ,  _lowerCAmelCase      ,  _lowerCAmelCase=None      ,  _lowerCAmelCase=False      ,  _lowerCAmelCase=False      ,  _lowerCAmelCase=False      ,  )     ->				str:
     if regexes_to_ignore is not None:
         for s in regexes_to_ignore:
             _lowerCAmelCase						      =   np.array([re.sub(_lowerCAmelCase      ,  ""      ,  _lowerCAmelCase		) for x in predictions]		)
             _lowerCAmelCase						      =   np.array([re.sub(_lowerCAmelCase      ,  ""      ,  _lowerCAmelCase		) for x in references]		)
     else:
         _lowerCAmelCase						      =   np.asarray(_lowerCAmelCase		)
         _lowerCAmelCase						      =   np.asarray(_lowerCAmelCase		)

     if ignore_case:
         _lowerCAmelCase						      =   np.char.lower(_lowerCAmelCase		)
         _lowerCAmelCase						      =   np.char.lower(_lowerCAmelCase		)

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

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

     _lowerCAmelCase						      =   predictions == references

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


