

"""simple docstring"""






import unittest

from cer import CER


lowerCamelCase__			:					Dict							  =					CER()






class       _UpperCAmelCase     (						unittest.TestCase):
			def 							__snake_case	(						self       )      ->      str:






				'''simple docstring'''







				_UpperCAmelCase      :							str       =   ["""White House"""]
				_UpperCAmelCase      :							Any       =   ["""white house"""]
				# S = 2, D = 0, I = 0, N = 11, CER = 2 / 11
				_UpperCAmelCase      :							Tuple       =   cer.compute(predictions=_A ,						references=_A       )
				self.assertTrue(abs(char_error_rate - 0.1818181818       ) < 1e-6       )
			def 							__snake_case	(						self       )      ->      str:






				'''simple docstring'''







				_UpperCAmelCase      :							List[str]       =   ["""were wolf"""]
				_UpperCAmelCase      :							List[Any]       =   ["""werewolf"""]
				# S = 0, D = 0, I = 1, N = 9, CER = 1 / 9
				_UpperCAmelCase      :							int       =   cer.compute(predictions=_A ,						references=_A       )
				self.assertTrue(abs(char_error_rate - 0.1111111       ) < 1e-6       )

				_UpperCAmelCase      :							Any       =   ["""werewolf"""]
				_UpperCAmelCase      :							List[Any]       =   ["""weae     wolf"""]
				# S = 1, D = 1, I = 0, N = 8, CER = 0.25
				_UpperCAmelCase      :							str       =   cer.compute(predictions=_A ,						references=_A       )
				self.assertTrue(abs(char_error_rate - 0.25       ) < 1e-6       )

				# consecutive whitespaces case 1
				_UpperCAmelCase      :							str       =   ["""were wolf"""]
				_UpperCAmelCase      :							Optional[int]       =   ["""were               wolf"""]
				# S = 0, D = 0, I = 0, N = 9, CER = 0
				_UpperCAmelCase      :							Tuple       =   cer.compute(predictions=_A ,						references=_A       )
				self.assertTrue(abs(char_error_rate - 0.0       ) < 1e-6       )

				# consecutive whitespaces case 2
				_UpperCAmelCase      :							List[Any]       =   ["""were   wolf"""]
				_UpperCAmelCase      :							Dict       =   ["""were               wolf"""]
				# S = 0, D = 0, I = 0, N = 9, CER = 0
				_UpperCAmelCase      :							Union[str, Any]       =   cer.compute(predictions=_A ,						references=_A       )
				self.assertTrue(abs(char_error_rate - 0.0       ) < 1e-6       )
			def 							__snake_case	(						self       )      ->      List[str]:






				'''simple docstring'''







				_UpperCAmelCase      :							List[Any]       =   ["""werewolf"""]
				_UpperCAmelCase      :							List[Any]       =   ["""weaewolf"""]
				# S = 1, D = 0, I = 0, N = 8, CER = 0.125
				_UpperCAmelCase      :							Tuple       =   cer.compute(predictions=_A ,						references=_A       )
				self.assertTrue(abs(char_error_rate - 0.125       ) < 1e-6       )
			def 							__snake_case	(						self       )      ->      Union[str, Any]:






				'''simple docstring'''







				_UpperCAmelCase      :							int       =   ["""werewolf"""]
				_UpperCAmelCase      :							Optional[int]       =   ["""wereawolf"""]
				# S = 0, D = 1, I = 0, N = 8, CER = 0.125
				_UpperCAmelCase      :							Dict       =   cer.compute(predictions=_A ,						references=_A       )
				self.assertTrue(abs(char_error_rate - 0.125       ) < 1e-6       )
			def 							__snake_case	(						self       )      ->      Tuple:






				'''simple docstring'''







				_UpperCAmelCase      :							Union[str, Any]       =   ["""werewolf"""]
				_UpperCAmelCase      :							List[str]       =   ["""wereolf"""]
				# S = 0, D = 0, I = 1, N = 8, CER = 0.125
				_UpperCAmelCase      :							Tuple       =   cer.compute(predictions=_A ,						references=_A       )
				self.assertTrue(abs(char_error_rate - 0.125       ) < 1e-6       )
			def 							__snake_case	(						self       )      ->      Any:






				'''simple docstring'''







				_UpperCAmelCase      :							Tuple       =   ["""werewolf"""]
				_UpperCAmelCase      :							Optional[int]       =   cer.compute(predictions=_A ,						references=_A       )
				self.assertEqual(_A ,						0.0       )
			def 							__snake_case	(						self       )      ->      int:






				'''simple docstring'''







				_UpperCAmelCase      :							Dict       =   ["""werewolf""", """I am your father"""]
				_UpperCAmelCase      :							Tuple       =   cer.compute(predictions=_A ,						references=_A       )
				self.assertEqual(_A ,						0.0       )

				_UpperCAmelCase      :							List[Any]       =   ["""werewolf""", """I am your father""", """doge"""]
				_UpperCAmelCase      :							Dict       =   ["""werxwolf""", """I       am your father""", """doge"""]
				# S = 1, D = 0, I = 0, N = 28, CER = 1 / 28
				_UpperCAmelCase      :							Union[str, Any]       =   cer.compute(predictions=_A ,						references=_A       )
				self.assertTrue(abs(char_error_rate - 0.03571428       ) < 1e-6       )
			def 							__snake_case	(						self       )      ->      Union[str, Any]:






				'''simple docstring'''







				_UpperCAmelCase      :							Tuple       =   ["""My hovercraft""", """is full of eels"""]
				_UpperCAmelCase      :							List[Any]       =   ["""My hovercraft is full""", """ of eels"""]
				# S = 0, D = 0, I = 2, N = 28, CER = 2 / 28
				# whitespace at the front of " of eels" will be strip during preporcessing
				# so need to insert 2 whitespaces
				_UpperCAmelCase      :							List[Any]       =   cer.compute(predictions=_A ,						references=_A ,						concatenate_texts=_A       )
				self.assertTrue(abs(char_error_rate - 0.071428       ) < 1e-6       )
			def 							__snake_case	(						self       )      ->      Dict:






				'''simple docstring'''







				_UpperCAmelCase      :							Dict       =   ["""我能吞下玻璃而不伤身体"""]
				_UpperCAmelCase      :							List[Any]       =   [""" 能吞虾玻璃而 不霜身体啦"""]
				# S = 3, D = 2, I = 0, N = 11, CER = 5 / 11
				_UpperCAmelCase      :							List[Any]       =   cer.compute(predictions=_A ,						references=_A       )
				self.assertTrue(abs(char_error_rate - 0.4545454545       ) < 1e-6       )

				_UpperCAmelCase      :							List[str]       =   ["""我能吞下玻璃""", """而不伤身体"""]
				_UpperCAmelCase      :							str       =   ["""我    能 吞 下 玻 璃""", """而不伤身体"""]
				# S = 0, D = 5, I = 0, N = 11, CER = 5 / 11
				_UpperCAmelCase      :							List[str]       =   cer.compute(predictions=_A ,						references=_A       )
				self.assertTrue(abs(char_error_rate - 0.454545454545       ) < 1e-6       )

				_UpperCAmelCase      :							Dict       =   ["""我能吞下玻璃而不伤身体"""]
				_UpperCAmelCase      :							Union[str, Any]       =   cer.compute(predictions=_A ,						references=_A       )
				self.assertFalse(_A ,						0.0       )
			def 							__snake_case	(						self       )      ->      List[Any]:






				'''simple docstring'''







				_UpperCAmelCase      :							Tuple       =   [""""""]
				_UpperCAmelCase      :							Union[str, Any]       =   ["""Hypothesis"""]
				with self.assertRaises(_A       ):
					cer.compute(predictions=_A ,						references=_A       )


if __name__ == "__main__":
						unittest.main()








"""simple docstring"""






from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


lowerCamelCase__			:					int							  =					{'''configuration_qdqbert''': ['''QDQBERT_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''QDQBertConfig''']}

try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						lowerCamelCase__			:					Optional[int]							  =					[
						    '''QDQBERT_PRETRAINED_MODEL_ARCHIVE_LIST''',
						    '''QDQBertForMaskedLM''',
						    '''QDQBertForMultipleChoice''',
						    '''QDQBertForNextSentencePrediction''',
						    '''QDQBertForQuestionAnswering''',
						    '''QDQBertForSequenceClassification''',
						    '''QDQBertForTokenClassification''',
						    '''QDQBertLayer''',
						    '''QDQBertLMHeadModel''',
						    '''QDQBertModel''',
						    '''QDQBertPreTrainedModel''',
						    '''load_tf_weights_in_qdqbert''',
						]


if TYPE_CHECKING:
						from .configuration_qdqbert import QDQBERT_PRETRAINED_CONFIG_ARCHIVE_MAP, QDQBertConfig

						try:
												if not is_torch_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_qdqbert import (
												    QDQBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
												    QDQBertForMaskedLM,
												    QDQBertForMultipleChoice,
												    QDQBertForNextSentencePrediction,
												    QDQBertForQuestionAnswering,
												    QDQBertForSequenceClassification,
												    QDQBertForTokenClassification,
												    QDQBertLayer,
												    QDQBertLMHeadModel,
												    QDQBertModel,
												    QDQBertPreTrainedModel,
												    load_tf_weights_in_qdqbert,
												)


else:
						import sys

						lowerCamelCase__			:					Optional[Any]							  =					_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)





