






"""simple docstring"""





import unittest

from cer import CER


_SCREAMING_SNAKE_CASE :    Dict    =						CER()






class 					a						( unittest.TestCase		):






    def        UpperCamelCase	(	self					:							List[str] )					->		Dict:
      lowerCamelCase_   					=						["White House"]
      lowerCamelCase_   					=						["white house"]
      # S = 2, D = 0, I = 0, N = 11, CER = 2 / 11
      lowerCamelCase_   					=						cer.compute(predictions=__SCREAMING_SNAKE_CASE	,						references=__SCREAMING_SNAKE_CASE )
      self.assertTrue(abs(char_error_rate - 0.1_818_181_818 ) < 1e-6 )






    def        UpperCamelCase	(	self					:							Tuple )					->		Any:
      lowerCamelCase_   					=						["were wolf"]
      lowerCamelCase_   					=						["werewolf"]
      # S = 0, D = 0, I = 1, N = 9, CER = 1 / 9
      lowerCamelCase_   					=						cer.compute(predictions=__SCREAMING_SNAKE_CASE	,						references=__SCREAMING_SNAKE_CASE )
      self.assertTrue(abs(char_error_rate - 0.1_111_111 ) < 1e-6 )

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

      # consecutive whitespaces case 1
      lowerCamelCase_   					=						["were wolf"]
      lowerCamelCase_   					=						["were               wolf"]
      # S = 0, D = 0, I = 0, N = 9, CER = 0
      lowerCamelCase_   					=						cer.compute(predictions=__SCREAMING_SNAKE_CASE	,						references=__SCREAMING_SNAKE_CASE )
      self.assertTrue(abs(char_error_rate - 0.0 ) < 1e-6 )

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






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






    def        UpperCamelCase	(	self					:							Any )					->		List[str]:
      lowerCamelCase_   					=						["werewolf"]
      lowerCamelCase_   					=						["wereawolf"]
      # S = 0, D = 1, I = 0, N = 8, CER = 0.125
      lowerCamelCase_   					=						cer.compute(predictions=__SCREAMING_SNAKE_CASE	,						references=__SCREAMING_SNAKE_CASE )
      self.assertTrue(abs(char_error_rate - 0.125 ) < 1e-6 )






    def        UpperCamelCase	(	self					:							Optional[Any] )					->		Any:
      lowerCamelCase_   					=						["werewolf"]
      lowerCamelCase_   					=						["wereolf"]
      # S = 0, D = 0, I = 1, N = 8, CER = 0.125
      lowerCamelCase_   					=						cer.compute(predictions=__SCREAMING_SNAKE_CASE	,						references=__SCREAMING_SNAKE_CASE )
      self.assertTrue(abs(char_error_rate - 0.125 ) < 1e-6 )






    def        UpperCamelCase	(	self					:							str )					->		List[str]:
      lowerCamelCase_   					=						["werewolf"]
      lowerCamelCase_   					=						cer.compute(predictions=__SCREAMING_SNAKE_CASE	,						references=__SCREAMING_SNAKE_CASE )
      self.assertEqual(__SCREAMING_SNAKE_CASE	,						0.0 )






    def        UpperCamelCase	(	self					:							Tuple )					->		str:
      lowerCamelCase_   					=						["werewolf", "I am your father"]
      lowerCamelCase_   					=						cer.compute(predictions=__SCREAMING_SNAKE_CASE	,						references=__SCREAMING_SNAKE_CASE )
      self.assertEqual(__SCREAMING_SNAKE_CASE	,						0.0 )

      lowerCamelCase_   					=						["werewolf", "I am your father", "doge"]
      lowerCamelCase_   					=						["werxwolf", "I       am your father", "doge"]
      # S = 1, D = 0, I = 0, N = 28, CER = 1 / 28
      lowerCamelCase_   					=						cer.compute(predictions=__SCREAMING_SNAKE_CASE	,						references=__SCREAMING_SNAKE_CASE )
      self.assertTrue(abs(char_error_rate - 0.03_571_428 ) < 1e-6 )






    def        UpperCamelCase	(	self					:							Optional[Any] )					->		Tuple:
      lowerCamelCase_   					=						["My hovercraft", "is full of eels"]
      lowerCamelCase_   					=						["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_   					=						cer.compute(predictions=__SCREAMING_SNAKE_CASE	,						references=__SCREAMING_SNAKE_CASE	,						concatenate_texts=__SCREAMING_SNAKE_CASE )
      self.assertTrue(abs(char_error_rate - 0.071_428 ) < 1e-6 )






    def        UpperCamelCase	(	self					:							List[str] )					->		List[str]:
      lowerCamelCase_   					=						["我能吞下玻璃而不伤身体"]
      lowerCamelCase_   					=						[" 能吞虾玻璃而 不霜身体啦"]
      # S = 3, D = 2, I = 0, N = 11, CER = 5 / 11
      lowerCamelCase_   					=						cer.compute(predictions=__SCREAMING_SNAKE_CASE	,						references=__SCREAMING_SNAKE_CASE )
      self.assertTrue(abs(char_error_rate - 0.4_545_454_545 ) < 1e-6 )

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

      lowerCamelCase_   					=						["我能吞下玻璃而不伤身体"]
      lowerCamelCase_   					=						cer.compute(predictions=__SCREAMING_SNAKE_CASE	,						references=__SCREAMING_SNAKE_CASE )
      self.assertFalse(__SCREAMING_SNAKE_CASE	,						0.0 )






    def        UpperCamelCase	(	self					:							Dict )					->		int:
      lowerCamelCase_   					=						[""]
      lowerCamelCase_   					=						["Hypothesis"]
      with self.assertRaises(__SCREAMING_SNAKE_CASE ):
        cer.compute(predictions=__SCREAMING_SNAKE_CASE	,						references=__SCREAMING_SNAKE_CASE )


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












"""simple docstring"""





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


_SCREAMING_SNAKE_CASE :    List[Any]    =						logging.get_logger(__name__)

_SCREAMING_SNAKE_CASE :    str    =						{
    '''facebook/regnet-y-040''': '''https://huggingface.co/facebook/regnet-y-040/blob/main/config.json''',
}






class 					a						( __snake_case		):
    SCREAMING_SNAKE_CASE						:					str						=			"""regnet"""
    SCREAMING_SNAKE_CASE						:					List[Any]						=			["""x""", """y"""]






    def __init__(	self					:							int	,						__SCREAMING_SNAKE_CASE					:							Any=3	,						__SCREAMING_SNAKE_CASE					:							Any=32	,						__SCREAMING_SNAKE_CASE					:							List[str]=[128, 192, 512, 1088]	,						__SCREAMING_SNAKE_CASE					:							Union[str, Any]=[2, 6, 12, 2]	,						__SCREAMING_SNAKE_CASE					:							str=64	,						__SCREAMING_SNAKE_CASE					:							List[Any]="y"	,						__SCREAMING_SNAKE_CASE					:							Optional[int]="relu"	,						**__SCREAMING_SNAKE_CASE					:							Union[str, Any]	,						)					->		Union[str, Any]:
      super().__init__(**__SCREAMING_SNAKE_CASE )
      if layer_type not in self.layer_types:
        raise ValueError(F'''layer_type={layer_type} is not one of {",".join(self.layer_types )}''' )
      lowerCamelCase_   					=						num_channels
      lowerCamelCase_   					=						embedding_size
      lowerCamelCase_   					=						hidden_sizes
      lowerCamelCase_   					=						depths
      lowerCamelCase_   					=						groups_width
      lowerCamelCase_   					=						layer_type
      lowerCamelCase_   					=						hidden_act
      # always downsample in the first stage
      lowerCamelCase_   					=						True




