




import collections
import inspect
import unittest
from typing import Dict, List, Tuple

from transformers import MaskFormerSwinConfig
from transformers.testing_utils import require_torch, require_torch_multi_gpu, torch_device
from transformers.utils import is_torch_available

from ...test_backbone_common import BackboneTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
							import torch
							from torch import nn

							from transformers import MaskFormerSwinBackbone
							from transformers.models.maskformer import MaskFormerSwinModel




class 		__A   :

						def __init__(		self :Dict     ,			__snake_case :str     ,			__snake_case :str=13     ,			__snake_case :Tuple=32     ,			__snake_case :int=2     ,			__snake_case :Any=3     ,			__snake_case :Any=16     ,			__snake_case :Optional[Any]=[1, 2, 1]     ,			__snake_case :Union[str, Any]=[2, 2, 4]     ,			__snake_case :Union[str, Any]=2     ,			__snake_case :Any=2.0     ,			__snake_case :int=True     ,			__snake_case :int=0.0     ,			__snake_case :List[Any]=0.0     ,			__snake_case :Dict=0.1     ,			__snake_case :Union[str, Any]="gelu"     ,			__snake_case :List[str]=False     ,			__snake_case :int=True     ,			__snake_case :str=0.02     ,			__snake_case :Dict=1E-5     ,			__snake_case :List[str]=True     ,			__snake_case :int=None     ,			__snake_case :Optional[int]=True     ,			__snake_case :int=10     ,			__snake_case :Any=8     ,			__snake_case :List[str]=["stage1", "stage2", "stage3"]     ,			__snake_case :Tuple=[1, 2, 3]     ,			):
										'''simple docstring'''

										__magic_name__						:						Tuple										=parent
										__magic_name__						:						List[Any]										=batch_size
										__magic_name__						:						Optional[Any]										=image_size
										__magic_name__						:						int										=patch_size
										__magic_name__						:						Dict										=num_channels
										__magic_name__						:						Any										=embed_dim
										__magic_name__						:						Any										=depths
										__magic_name__						:						List[str]										=num_heads
										__magic_name__						:						Union[str, Any]										=window_size
										__magic_name__						:						str										=mlp_ratio
										__magic_name__						:						str										=qkv_bias
										__magic_name__						:						int										=hidden_dropout_prob
										__magic_name__						:						Any										=attention_probs_dropout_prob
										__magic_name__						:						Any										=drop_path_rate
										__magic_name__						:						int										=hidden_act
										__magic_name__						:						Dict										=use_absolute_embeddings
										__magic_name__						:						Any										=patch_norm
										__magic_name__						:						str										=layer_norm_eps
										__magic_name__						:						Union[str, Any]										=initializer_range
										__magic_name__						:						Dict										=is_training
										__magic_name__						:						Union[str, Any]										=scope
										__magic_name__						:						Optional[int]										=use_labels
										__magic_name__						:						str										=type_sequence_label_size
										__magic_name__						:						Dict										=encoder_stride
										__magic_name__						:						List[str]										=out_features
										__magic_name__						:						Optional[Any]										=out_indices

						def      A__    (		self :List[str]			):
										'''simple docstring'''

										__magic_name__						:						List[str]										=floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]			)

										__magic_name__						:						Dict										=None
										if self.use_labels:
														__magic_name__						:						List[str]										=ids_tensor([self.batch_size]     ,			self.type_sequence_label_size			)

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

										return config, pixel_values, labels

						def      A__    (		self :Union[str, Any]			):
										'''simple docstring'''

										return MaskFormerSwinConfig(
										    image_size=self.image_size     ,			patch_size=self.patch_size     ,			num_channels=self.num_channels     ,			embed_dim=self.embed_dim     ,			depths=self.depths     ,			num_heads=self.num_heads     ,			window_size=self.window_size     ,			mlp_ratio=self.mlp_ratio     ,			qkv_bias=self.qkv_bias     ,			hidden_dropout_prob=self.hidden_dropout_prob     ,			attention_probs_dropout_prob=self.attention_probs_dropout_prob     ,			drop_path_rate=self.drop_path_rate     ,			hidden_act=self.hidden_act     ,			use_absolute_embeddings=self.use_absolute_embeddings     ,			path_norm=self.patch_norm     ,			layer_norm_eps=self.layer_norm_eps     ,			initializer_range=self.initializer_range     ,			encoder_stride=self.encoder_stride     ,			out_features=self.out_features     ,			out_indices=self.out_indices     ,			)

						def      A__    (		self :int     ,			__snake_case :Tuple     ,			__snake_case :Union[str, Any]     ,			__snake_case :List[str]			):
										'''simple docstring'''

										__magic_name__						:						Optional[Any]										=MaskFormerSwinModel(config=__snake_case			)
										model.to(__snake_case			)
										model.eval()
										__magic_name__						:						Dict										=model(__snake_case			)

										__magic_name__						:						Union[str, Any]										=((config.image_size // config.patch_size) ** 2) // (4 ** (len(config.depths			) - 1))
										__magic_name__						:						Dict										=int(config.embed_dim * 2 ** (len(config.depths			) - 1)			)

										self.parent.assertEqual(result.last_hidden_state.shape     ,			(self.batch_size, expected_seq_len, expected_dim)			)

						def      A__    (		self :Tuple     ,			__snake_case :Any     ,			__snake_case :Tuple     ,			__snake_case :List[str]			):
										'''simple docstring'''

										__magic_name__						:						Optional[int]										=MaskFormerSwinBackbone(config=__snake_case			)
										model.to(__snake_case			)
										model.eval()
										__magic_name__						:						Optional[Any]										=model(__snake_case			)

										# verify feature maps
										self.parent.assertEqual(len(result.feature_maps			)     ,			len(config.out_features			)			)
										self.parent.assertListEqual(list(result.feature_maps[0].shape			)     ,			[13, 16, 16, 16]			)

										# verify channels
										self.parent.assertEqual(len(model.channels			)     ,			len(config.out_features			)			)
										self.parent.assertListEqual(model.channels     ,			[16, 32, 64]			)

										# verify ValueError
										with self.parent.assertRaises(__snake_case			):
														__magic_name__						:						str										=["""stem"""]
														__magic_name__						:						Optional[int]										=MaskFormerSwinBackbone(config=__snake_case			)


						def      A__    (		self :Union[str, Any]			):
										'''simple docstring'''

										__magic_name__						:						Optional[int]										=self.prepare_config_and_inputs()
										__magic_name__					,			__magic_name__					,			__magic_name__						:						Optional[int]										=config_and_inputs
										__magic_name__						:						Any										={"""pixel_values""": pixel_values}
										return config, inputs_dict




@require_torch
class 		__A   (      snake_case_       ,    snake_case_       ,    unittest.TestCase      ):
						UpperCamelCase      =       (
						    (
						        MaskFormerSwinModel,
						        MaskFormerSwinBackbone,
						    )
						    if is_torch_available()
						    else ()
						)
						UpperCamelCase      =       {'''feature-extraction''': MaskFormerSwinModel} if is_torch_available() else {}
						UpperCamelCase      =       False
						UpperCamelCase      =       False
						UpperCamelCase      =       False
						UpperCamelCase      =       False
						UpperCamelCase      =       False

						def      A__    (		self :Dict			):
										'''simple docstring'''

										__magic_name__						:						Optional[int]										=MaskFormerSwinModelTester(self			)
										__magic_name__						:						Dict										=ConfigTester(self     ,			config_class=__snake_case     ,			embed_dim=37			)

						@require_torch_multi_gpu
						@unittest.skip(
						    reason=(
						        """`MaskFormerSwinModel` outputs `hidden_states_spatial_dimensions` which doesn't work well with"""
						        """ `nn.DataParallel`"""
						    )			)
						def      A__    (		self :Union[str, Any]			):
										'''simple docstring'''

										pass

						def      A__    (		self :int			):
										'''simple docstring'''

										self.create_and_test_config_common_properties()
										self.config_tester.create_and_test_config_to_json_string()
										self.config_tester.create_and_test_config_to_json_file()
										self.config_tester.create_and_test_config_from_and_save_pretrained()
										self.config_tester.create_and_test_config_with_num_labels()
										self.config_tester.check_config_can_be_init_without_params()
										self.config_tester.check_config_arguments_init()

						def      A__    (		self :Union[str, Any]			):
										'''simple docstring'''

										return

						def      A__    (		self :Dict			):
										'''simple docstring'''

										__magic_name__						:						Any										=self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_model(*__snake_case			)

						def      A__    (		self :Dict			):
										'''simple docstring'''

										__magic_name__						:						Union[str, Any]										=self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_backbone(*__snake_case			)

						@unittest.skip("""Swin does not use inputs_embeds"""			)
						def      A__    (		self :List[Any]			):
										'''simple docstring'''

										pass

						@unittest.skip("""Swin does not support feedforward chunking"""			)
						def      A__    (		self :Any			):
										'''simple docstring'''

										pass

						def      A__    (		self :Any			):
										'''simple docstring'''

										__magic_name__					,			__magic_name__						:						List[str]										=self.model_tester.prepare_config_and_inputs_for_common()

										for model_class in self.all_model_classes:
														__magic_name__						:						List[str]										=model_class(__snake_case			)
														self.assertIsInstance(model.get_input_embeddings()     ,			(nn.Module)			)
														__magic_name__						:						Dict										=model.get_output_embeddings()
														self.assertTrue(x is None or isinstance(__snake_case     ,			nn.Linear			)			)

						def      A__    (		self :Union[str, Any]			):
										'''simple docstring'''

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

										for model_class in self.all_model_classes:
														__magic_name__						:						List[str]										=model_class(__snake_case			)
														__magic_name__						:						Optional[Any]										=inspect.signature(model.forward			)
														# signature.parameters is an OrderedDict => so arg_names order is deterministic
														__magic_name__						:						int										=[*signature.parameters.keys()]

														__magic_name__						:						List[str]										=["""pixel_values"""]
														self.assertListEqual(arg_names[:1]     ,			__snake_case			)

						@unittest.skip(reason="""MaskFormerSwin is only used as backbone and doesn't support output_attentions"""			)
						def      A__    (		self :str			):
										'''simple docstring'''

										pass

						@unittest.skip(reason="""MaskFormerSwin is only used as an internal backbone"""			)
						def      A__    (		self :Tuple			):
										'''simple docstring'''

										pass

						def      A__    (		self :Any     ,			__snake_case :List[str]     ,			__snake_case :List[Any]     ,			__snake_case :Union[str, Any]     ,			__snake_case :str			):
										'''simple docstring'''

										__magic_name__						:						Tuple										=model_class(__snake_case			)
										model.to(__snake_case			)
										model.eval()

										with torch.no_grad():
														__magic_name__						:						List[Any]										=model(**self._prepare_for_class(__snake_case     ,			__snake_case			)			)

										__magic_name__						:						Dict										=outputs.hidden_states

										__magic_name__						:						Any										=getattr(
										    self.model_tester     ,			"""expected_num_hidden_layers"""     ,			len(self.model_tester.depths			) + 1			)
										self.assertEqual(len(__snake_case			)     ,			__snake_case			)

										# Swin has a different seq_length
										__magic_name__						:						str										=(
										    config.patch_size
										    if isinstance(config.patch_size     ,			collections.abc.Iterable			)
										    else (config.patch_size, config.patch_size)
										)

										__magic_name__						:						Optional[Any]										=(image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])

										self.assertListEqual(
										    list(hidden_states[0].shape[-2:]			)     ,			[num_patches, self.model_tester.embed_dim]     ,			)

						def      A__    (		self :int			):
										'''simple docstring'''

										__magic_name__					,			__magic_name__						:						List[Any]										=self.model_tester.prepare_config_and_inputs_for_common()

										__magic_name__						:						Any										=(
										    self.model_tester.image_size
										    if isinstance(self.model_tester.image_size     ,			collections.abc.Iterable			)
										    else (self.model_tester.image_size, self.model_tester.image_size)
										)

										for model_class in self.all_model_classes:
														__magic_name__						:						Tuple										=True
														self.check_hidden_states_output(__snake_case     ,			__snake_case     ,			__snake_case     ,			__snake_case			)

														# check that output_hidden_states also work using config
														del inputs_dict["output_hidden_states"]
														__magic_name__						:						Tuple										=True

														self.check_hidden_states_output(__snake_case     ,			__snake_case     ,			__snake_case     ,			__snake_case			)

						def      A__    (		self :str			):
										'''simple docstring'''

										__magic_name__					,			__magic_name__						:						Any										=self.model_tester.prepare_config_and_inputs_for_common()
										__magic_name__						:						Union[str, Any]										=3

										__magic_name__						:						str										=(
										    self.model_tester.image_size
										    if isinstance(self.model_tester.image_size     ,			collections.abc.Iterable			)
										    else (self.model_tester.image_size, self.model_tester.image_size)
										)
										__magic_name__						:						Any										=(
										    config.patch_size
										    if isinstance(config.patch_size     ,			collections.abc.Iterable			)
										    else (config.patch_size, config.patch_size)
										)

										__magic_name__						:						Tuple										=image_size[0] + patch_size[0] - (image_size[0] % patch_size[0])
										__magic_name__						:						List[Any]										=image_size[1] + patch_size[1] - (image_size[1] % patch_size[1])

										for model_class in self.all_model_classes:
														__magic_name__						:						Union[str, Any]										=True
														self.check_hidden_states_output(__snake_case     ,			__snake_case     ,			__snake_case     ,			(padded_height, padded_width)			)

														# check that output_hidden_states also work using config
														del inputs_dict["output_hidden_states"]
														__magic_name__						:						List[Any]										=True
														self.check_hidden_states_output(__snake_case     ,			__snake_case     ,			__snake_case     ,			(padded_height, padded_width)			)

						@unittest.skip(reason="""MaskFormerSwin doesn't have pretrained checkpoints"""			)
						def      A__    (		self :str			):
										'''simple docstring'''

										pass

						@unittest.skip(reason="""This will be fixed once MaskFormerSwin is replaced by native Swin"""			)
						def      A__    (		self :str			):
										'''simple docstring'''

										pass

						@unittest.skip(reason="""This will be fixed once MaskFormerSwin is replaced by native Swin"""			)
						def      A__    (		self :Any			):
										'''simple docstring'''

										pass


						def      A__    (		self :Optional[Any]			):
										'''simple docstring'''

										__magic_name__					,			__magic_name__						:						Union[str, Any]										=self.model_tester.prepare_config_and_inputs_for_common()

										def set_nan_tensor_to_zero(__snake_case :Tuple			):
														__magic_name__						:						Union[str, Any]										=0
														return t

										def check_equivalence(__snake_case :str     ,			__snake_case :Optional[Any]     ,			__snake_case :int     ,			__snake_case :List[Any]={}			):
														with torch.no_grad():
																		__magic_name__						:						Optional[int]										=model(**__snake_case     ,			return_dict=__snake_case     ,			**__snake_case			)
																		__magic_name__						:						List[str]										=model(**__snake_case     ,			return_dict=__snake_case     ,			**__snake_case			).to_tuple()

																		def recursive_check(__snake_case :Optional[Any]     ,			__snake_case :Tuple			):
																						if isinstance(__snake_case     ,			(List, Tuple)			):
																										for tuple_iterable_value, dict_iterable_value in zip(__snake_case     ,			__snake_case			):
																														recursive_check(__snake_case     ,			__snake_case			)
																						elif isinstance(__snake_case     ,			__snake_case			):
																										for tuple_iterable_value, dict_iterable_value in zip(
																										    tuple_object.values()     ,			dict_object.values()			):
																														recursive_check(__snake_case     ,			__snake_case			)
																						elif tuple_object is None:
																										return
																						else:
																										self.assertTrue(
																										    torch.allclose(
																										        set_nan_tensor_to_zero(__snake_case			)     ,			set_nan_tensor_to_zero(__snake_case			)     ,			atol=1E-5			)     ,			msg=(
																										        """Tuple and dict output are not equal. Difference:"""
																										        f" {torch.max(torch.abs(tuple_object - dict_object			)			)}. Tuple has `nan`:"
																										        f" {torch.isnan(__snake_case			).any()} and `inf`: {torch.isinf(__snake_case			)}. Dict has"
																										        f" `nan`: {torch.isnan(__snake_case			).any()} and `inf`: {torch.isinf(__snake_case			)}."
																										    )     ,			)

																		recursive_check(__snake_case     ,			__snake_case			)

										for model_class in self.all_model_classes:
														__magic_name__						:						Optional[int]										=model_class(__snake_case			)
														model.to(__snake_case			)
														model.eval()

														__magic_name__						:						Tuple										=self._prepare_for_class(__snake_case     ,			__snake_case			)
														__magic_name__						:						int										=self._prepare_for_class(__snake_case     ,			__snake_case			)
														check_equivalence(__snake_case     ,			__snake_case     ,			__snake_case			)

														__magic_name__						:						Tuple										=self._prepare_for_class(__snake_case     ,			__snake_case     ,			return_labels=__snake_case			)
														__magic_name__						:						str										=self._prepare_for_class(__snake_case     ,			__snake_case     ,			return_labels=__snake_case			)
														check_equivalence(__snake_case     ,			__snake_case     ,			__snake_case			)

														__magic_name__						:						Optional[Any]										=self._prepare_for_class(__snake_case     ,			__snake_case			)
														__magic_name__						:						Tuple										=self._prepare_for_class(__snake_case     ,			__snake_case			)
														check_equivalence(__snake_case     ,			__snake_case     ,			__snake_case     ,			{"""output_hidden_states""": True}			)

														__magic_name__						:						Union[str, Any]										=self._prepare_for_class(__snake_case     ,			__snake_case     ,			return_labels=__snake_case			)
														__magic_name__						:						Tuple										=self._prepare_for_class(__snake_case     ,			__snake_case     ,			return_labels=__snake_case			)
														check_equivalence(__snake_case     ,			__snake_case     ,			__snake_case     ,			{"""output_hidden_states""": True}			)




@require_torch
class 		__A   (      unittest.TestCase       ,    snake_case_      ):
						UpperCamelCase      =       (MaskFormerSwinBackbone,) if is_torch_available() else ()
						UpperCamelCase      =       MaskFormerSwinConfig

						def      A__    (		self :List[Any]			):
										'''simple docstring'''

										__magic_name__						:						Any										=MaskFormerSwinModelTester(self			)


						def      A__    (		self :Tuple			):
										'''simple docstring'''

										__magic_name__					,			__magic_name__						:						Optional[int]										=self.model_tester.prepare_config_and_inputs_for_common()
										__magic_name__						:						List[Any]										=inputs_dict["""pixel_values"""].shape[0]

										for backbone_class in self.all_model_classes:
														__magic_name__						:						Union[str, Any]										=backbone_class(__snake_case			)
														backbone.to(__snake_case			)
														backbone.eval()

														__magic_name__						:						Optional[Any]										=backbone(**__snake_case			)

														# Test default outputs and verify feature maps
														self.assertIsInstance(outputs.feature_maps     ,			__snake_case			)
														self.assertTrue(len(outputs.feature_maps			) == len(backbone.channels			)			)
														for feature_map, n_channels in zip(outputs.feature_maps     ,			backbone.channels			):
																		self.assertTrue(feature_map.shape[:2]     ,			(batch_size, n_channels)			)
														self.assertIsNone(outputs.hidden_states			)
														self.assertIsNone(outputs.attentions			)

														# Test output_hidden_states=True
														__magic_name__						:						List[str]										=backbone(**__snake_case     ,			output_hidden_states=__snake_case			)
														self.assertIsNotNone(outputs.hidden_states			)
														self.assertTrue(len(outputs.hidden_states			)     ,			len(backbone.stage_names			)			)
														# We skip the stem layer
														for hidden_states, n_channels in zip(outputs.hidden_states[1:]     ,			backbone.channels			):
																		for hidden_state in hidden_states:
																						# Hidden states are in the format (batch_size, (height * width), n_channels)
																						__magic_name__					,			__magic_name__					,			__magic_name__						:						int										=hidden_state.shape
																						self.assertTrue((h_batch_size, h_n_channels)     ,			(batch_size, n_channels)			)

            # Test output_attentions=True
														if self.has_attentions:
																		__magic_name__						:						Union[str, Any]										=backbone(**__snake_case     ,			output_attentions=__snake_case			)
																		self.assertIsNotNone(outputs.attentions			)











'''simple docstring'''






from typing import List

import jiwer
import jiwer.transforms as tr
from packaging import version

import datasets
from datasets.config import PY_VERSION


if PY_VERSION < version.parse('''3.8'''):
      import importlib_metadata
else:
      import importlib.metadata as importlib_metadata


A__							:  Dict    =''''''


if version.parse(importlib_metadata.version('''jiwer''')) < version.parse('''2.3.0'''):




      class 					UpperCAmelCase	(     tr.AbstractTransform  ):




            def __init__(     self     :					Any     ,     __snake_case     :					str = " "    )							-> Any:
                  _lowerCAmelCase					=				sentence_delimiter




            def 							lowercase__       (     self     :					str     ,     __snake_case     :					str    )							-> Optional[int]:
                  return list(__snake_case    )




            def 							lowercase__       (     self     :					Tuple     ,     __snake_case     :					List[str]    )							-> Union[str, Any]:
                  _lowerCAmelCase					=				[]
                  for sent_idx, sentence in enumerate(__snake_case    ):
                        chars.extend(self.process_string(__snake_case    )    )
                        if self.sentence_delimiter is not None and self.sentence_delimiter != "" and sent_idx < len(__snake_case    ) - 1:
                              chars.append(self.sentence_delimiter    )
                  return chars




      A__							:  Optional[Any]    =tr.Compose(
          [tr.RemoveMultipleSpaces(), tr.Strip(), SentencesToListOfCharacters(SENTENCE_DELIMITER)]
      )
else:
      A__							:  Tuple    =tr.Compose(
          [
              tr.RemoveMultipleSpaces(),
              tr.Strip(),
              tr.ReduceToSingleSentence(SENTENCE_DELIMITER),
              tr.ReduceToListOfListOfChars(),
          ]
      )


A__							:  List[str]    ='''\
@inproceedings{inproceedings,
    author = {Morris, Andrew and Maier, Viktoria and Green, Phil},
    year = {2004},
    month = {01},
    pages = {},
    title = {From WER and RIL to MER and WIL: improved evaluation measures for connected speech recognition.}
}
'''

A__							:  Optional[int]    ='''\
Character error rate (CER) is a common metric of the performance of an automatic speech recognition system.

CER is similar to Word Error Rate (WER), but operates on character instead of word. Please refer to docs of WER for further information.

Character error rate can be computed as:

CER = (S + D + I) / N = (S + D + I) / (S + D + C)

where

S is the number of substitutions,
D is the number of deletions,
I is the number of insertions,
C is the number of correct characters,
N is the number of characters in the reference (N=S+D+C).

CER\'s output is not always a number between 0 and 1, in particular when there is a high number of insertions. This value is often associated to the percentage of characters that were incorrectly predicted. The lower the value, the better the
performance of the ASR system with a CER of 0 being a perfect score.
'''

A__							:  List[str]    ='''
Computes CER score of transcribed segments against references.
Args:
    references: list of references for each speech input.
    predictions: list of transcribtions to score.
    concatenate_texts: Whether or not to concatenate sentences before evaluation, set to True for more accurate result.
Returns:
    (float): the character error rate

Examples:

    >>> predictions = ["this is the prediction", "there is an other sample"]
    >>> references = ["this is the reference", "there is another one"]
    >>> cer = datasets.load_metric("cer")
    >>> cer_score = cer.compute(predictions=predictions, references=references)
    >>> print(cer_score)
    0.34146341463414637
'''




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




      def 							lowercase__       (     self     :					Any    )							-> Dict:
            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"""    ),
                    }    )     ,     codebase_urls=["""https://github.com/jitsi/jiwer/"""]     ,     reference_urls=[
                    """https://en.wikipedia.org/wiki/Word_error_rate""",
                    """https://sites.google.com/site/textdigitisation/qualitymeasures/computingerrorrates""",
                ]     ,     )




      def 							lowercase__       (     self     :					Optional[Any]     ,     __snake_case     :					Optional[Any]     ,     __snake_case     :					List[str]     ,     __snake_case     :					Tuple=False    )							-> List[Any]:
            if concatenate_texts:
                  return jiwer.compute_measures(
                      __snake_case     ,     __snake_case     ,     truth_transform=__snake_case     ,     hypothesis_transform=__snake_case     ,     )["wer"]

            _lowerCAmelCase					=				0
            _lowerCAmelCase					=				0
            for prediction, reference in zip(__snake_case     ,     __snake_case    ):
                  _lowerCAmelCase					=				jiwer.compute_measures(
                      __snake_case     ,     __snake_case     ,     truth_transform=__snake_case     ,     hypothesis_transform=__snake_case     ,     )
                  incorrect += measures["substitutions"] + measures["deletions"] + measures["insertions"]
                  total += measures["substitutions"] + measures["deletions"] + measures["hits"]

            return incorrect / total






