
"""simple docstring"""


import unittest

from cer import CER


lowerCAmelCase								=						CER()

class    A_     (					unittest.TestCase       ):



							"""simple docstring"""






							def 				UpperCAmelCase__							(  self  :Dict	):





										"""simple docstring"""

										lowerCamelCase__     :					int     	=['White House']
										lowerCamelCase__     :					Any     	=['white house']
										# S = 2, D = 0, I = 0, N = 11, CER = 2 / 11
										lowerCamelCase__     :					Any     	=cer.compute(predictions=lowerCamelCase_					,							references=lowerCamelCase_	)
										self.assertTrue(abs(char_error_rate - 0.18_18_18_18_18	) < 1e-6	)





							def 				UpperCAmelCase__							(  self  :Dict	):





										"""simple docstring"""

										lowerCamelCase__     :					Any     	=['were wolf']
										lowerCamelCase__     :					List[str]     	=['werewolf']
										# S = 0, D = 0, I = 1, N = 9, CER = 1 / 9
										lowerCamelCase__     :					List[str]     	=cer.compute(predictions=lowerCamelCase_					,							references=lowerCamelCase_	)
										self.assertTrue(abs(char_error_rate - 0.1_11_11_11	) < 1e-6	)

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

										# consecutive whitespaces case 1
										lowerCamelCase__     :					Union[str, Any]     	=['were wolf']
										lowerCamelCase__     :					Union[str, Any]     	=['were               wolf']
										# S = 0, D = 0, I = 0, N = 9, CER = 0
										lowerCamelCase__     :					Tuple     	=cer.compute(predictions=lowerCamelCase_					,							references=lowerCamelCase_	)
										self.assertTrue(abs(char_error_rate - 0.0	) < 1e-6	)

										# consecutive whitespaces case 2
										lowerCamelCase__     :					Tuple     	=['were   wolf']
										lowerCamelCase__     :					List[Any]     	=['were               wolf']
										# S = 0, D = 0, I = 0, N = 9, CER = 0
										lowerCamelCase__     :					Any     	=cer.compute(predictions=lowerCamelCase_					,							references=lowerCamelCase_	)
										self.assertTrue(abs(char_error_rate - 0.0	) < 1e-6	)





							def 				UpperCAmelCase__							(  self  :int	):





										"""simple docstring"""

										lowerCamelCase__     :					Union[str, Any]     	=['werewolf']
										lowerCamelCase__     :					str     	=['weaewolf']
										# S = 1, D = 0, I = 0, N = 8, CER = 0.125
										lowerCamelCase__     :					Optional[int]     	=cer.compute(predictions=lowerCamelCase_					,							references=lowerCamelCase_	)
										self.assertTrue(abs(char_error_rate - 0.1_25	) < 1e-6	)





							def 				UpperCAmelCase__							(  self  :Any	):





										"""simple docstring"""

										lowerCamelCase__     :					List[str]     	=['werewolf']
										lowerCamelCase__     :					str     	=['wereawolf']
										# S = 0, D = 1, I = 0, N = 8, CER = 0.125
										lowerCamelCase__     :					Tuple     	=cer.compute(predictions=lowerCamelCase_					,							references=lowerCamelCase_	)
										self.assertTrue(abs(char_error_rate - 0.1_25	) < 1e-6	)





							def 				UpperCAmelCase__							(  self  :Optional[Any]	):





										"""simple docstring"""

										lowerCamelCase__     :					Dict     	=['werewolf']
										lowerCamelCase__     :					Union[str, Any]     	=['wereolf']
										# S = 0, D = 0, I = 1, N = 8, CER = 0.125
										lowerCamelCase__     :					List[Any]     	=cer.compute(predictions=lowerCamelCase_					,							references=lowerCamelCase_	)
										self.assertTrue(abs(char_error_rate - 0.1_25	) < 1e-6	)





							def 				UpperCAmelCase__							(  self  :Any	):





										"""simple docstring"""

										lowerCamelCase__     :					Dict     	=['werewolf']
										lowerCamelCase__     :					Tuple     	=cer.compute(predictions=lowerCamelCase_					,							references=lowerCamelCase_	)
										self.assertEqual(lowerCamelCase_					,							0.0	)





							def 				UpperCAmelCase__							(  self  :Optional[Any]	):





										"""simple docstring"""

										lowerCamelCase__     :					List[str]     	=['werewolf', 'I am your father']
										lowerCamelCase__     :					List[Any]     	=cer.compute(predictions=lowerCamelCase_					,							references=lowerCamelCase_	)
										self.assertEqual(lowerCamelCase_					,							0.0	)

										lowerCamelCase__     :					Optional[Any]     	=['werewolf', 'I am your father', 'doge']
										lowerCamelCase__     :					str     	=['werxwolf', 'I       am your father', 'doge']
										# S = 1, D = 0, I = 0, N = 28, CER = 1 / 28
										lowerCamelCase__     :					List[str]     	=cer.compute(predictions=lowerCamelCase_					,							references=lowerCamelCase_	)
										self.assertTrue(abs(char_error_rate - 0.03_57_14_28	) < 1e-6	)





							def 				UpperCAmelCase__							(  self  :Optional[Any]	):





										"""simple docstring"""

										lowerCamelCase__     :					Dict     	=['My hovercraft', 'is full of eels']
										lowerCamelCase__     :					str     	=['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
										lowerCamelCase__     :					Dict     	=cer.compute(predictions=lowerCamelCase_					,							references=lowerCamelCase_					,							concatenate_texts=lowerCamelCase_	)
										self.assertTrue(abs(char_error_rate - 0.07_14_28	) < 1e-6	)





							def 				UpperCAmelCase__							(  self  :int	):





										"""simple docstring"""

										lowerCamelCase__     :					Optional[Any]     	=['我能吞下玻璃而不伤身体']
										lowerCamelCase__     :					int     	=[' 能吞虾玻璃而 不霜身体啦']
										# S = 3, D = 2, I = 0, N = 11, CER = 5 / 11
										lowerCamelCase__     :					Optional[Any]     	=cer.compute(predictions=lowerCamelCase_					,							references=lowerCamelCase_	)
										self.assertTrue(abs(char_error_rate - 0.45_45_45_45_45	) < 1e-6	)

										lowerCamelCase__     :					Dict     	=['我能吞下玻璃', '而不伤身体']
										lowerCamelCase__     :					str     	=['我    能 吞 下 玻 璃', '而不伤身体']
										# S = 0, D = 5, I = 0, N = 11, CER = 5 / 11
										lowerCamelCase__     :					Dict     	=cer.compute(predictions=lowerCamelCase_					,							references=lowerCamelCase_	)
										self.assertTrue(abs(char_error_rate - 0.45_45_45_45_45_45	) < 1e-6	)

										lowerCamelCase__     :					Dict     	=['我能吞下玻璃而不伤身体']
										lowerCamelCase__     :					Any     	=cer.compute(predictions=lowerCamelCase_					,							references=lowerCamelCase_	)
										self.assertFalse(lowerCamelCase_					,							0.0	)





							def 				UpperCAmelCase__							(  self  :Any	):





										"""simple docstring"""

										lowerCamelCase__     :					str     	=['']
										lowerCamelCase__     :					int     	=['Hypothesis']
										with self.assertRaises(lowerCamelCase_	):
													cer.compute(predictions=lowerCamelCase_					,							references=lowerCamelCase_	)


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

"""simple docstring"""


from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowerCAmelCase								=						logging.get_logger(__name__)

lowerCAmelCase								=						{
    """uw-madison/nystromformer-512""": """https://huggingface.co/uw-madison/nystromformer-512/resolve/main/config.json""",
    # See all Nystromformer models at https://huggingface.co/models?filter=nystromformer
}

class    A_     (					A__       ):



							"""simple docstring"""






							SCREAMING_SNAKE_CASE_     				=       """nystromformer"""





							def __init__(  self  :Optional[Any]					,							lowerCamelCase_  :Optional[Any]=30_000					,							lowerCamelCase_  :str=768					,							lowerCamelCase_  :str=12					,							lowerCamelCase_  :str=12					,							lowerCamelCase_  :Any=3_072					,							lowerCamelCase_  :Optional[int]="gelu_new"					,							lowerCamelCase_  :List[Any]=0.1					,							lowerCamelCase_  :List[str]=0.1					,							lowerCamelCase_  :Any=510					,							lowerCamelCase_  :Optional[int]=2					,							lowerCamelCase_  :List[Any]=64					,							lowerCamelCase_  :Union[str, Any]=64					,							lowerCamelCase_  :str=65					,							lowerCamelCase_  :Union[str, Any]=False					,							lowerCamelCase_  :str=0.02					,							lowerCamelCase_  :Any=1e-5					,							lowerCamelCase_  :int=1					,							lowerCamelCase_  :Optional[int]=0					,							lowerCamelCase_  :str=2					,							**lowerCamelCase_  :int					,							):





										"""simple docstring"""

										lowerCamelCase__     :					int		=vocab_size
										lowerCamelCase__     :					Optional[int]		=max_position_embeddings
										lowerCamelCase__     :					List[Any]		=hidden_size
										lowerCamelCase__     :					Tuple		=num_hidden_layers
										lowerCamelCase__     :					Optional[Any]		=num_attention_heads
										lowerCamelCase__     :					List[str]		=intermediate_size
										lowerCamelCase__     :					Union[str, Any]		=hidden_act
										lowerCamelCase__     :					int		=hidden_dropout_prob
										lowerCamelCase__     :					Tuple		=attention_probs_dropout_prob
										lowerCamelCase__     :					Dict		=initializer_range
										lowerCamelCase__     :					Tuple		=type_vocab_size
										lowerCamelCase__     :					Any		=segment_means_seq_len
										lowerCamelCase__     :					int		=num_landmarks
										lowerCamelCase__     :					Tuple		=conv_kernel_size
										lowerCamelCase__     :					Optional[int]		=inv_coeff_init_option
										lowerCamelCase__     :					List[str]		=layer_norm_eps
										super().__init__(pad_token_id=lowerCamelCase_					,							bos_token_id=lowerCamelCase_					,							eos_token_id=lowerCamelCase_					,							**lowerCamelCase_	)