

import unittest

from cer import CER


_a									=  CER()






class 				A_					(						unittest.TestCase   ):


     def     UpperCAmelCase    (				self     :						Union[str, Any]   )				->      Optional[Any]:
      __lowerCAmelCase:  Union[str, Any]        = ['White House']
      __lowerCAmelCase:  Optional[Any]        = ['white house']
      # S = 2, D = 0, I = 0, N = 11, CER = 2 / 11
      __lowerCAmelCase:  Optional[Any]        = cer.compute(predictions=_SCREAMING_SNAKE_CASE     ,    references=_SCREAMING_SNAKE_CASE   )
      self.assertTrue(abs(char_error_rate - 0.1818181818   ) < 1E-6   )


     def     UpperCAmelCase    (				self     :						Optional[int]   )				->      List[str]:
      __lowerCAmelCase:  Tuple        = ['were wolf']
      __lowerCAmelCase:  List[str]        = ['werewolf']
      # S = 0, D = 0, I = 1, N = 9, CER = 1 / 9
      __lowerCAmelCase:  Union[str, Any]        = cer.compute(predictions=_SCREAMING_SNAKE_CASE     ,    references=_SCREAMING_SNAKE_CASE   )
      self.assertTrue(abs(char_error_rate - 0.1111111   ) < 1E-6   )

      __lowerCAmelCase:  List[Any]        = ['werewolf']
      __lowerCAmelCase:  Dict        = ['weae     wolf']
      # S = 1, D = 1, I = 0, N = 8, CER = 0.25
      __lowerCAmelCase:  Dict        = 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:  Optional[int]        = ['were wolf']
      __lowerCAmelCase:  Any        = ['were               wolf']
      # S = 0, D = 0, I = 0, N = 9, CER = 0
      __lowerCAmelCase:  List[str]        = 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:  str        = ['were   wolf']
      __lowerCAmelCase:  Tuple        = ['were               wolf']
      # S = 0, D = 0, I = 0, N = 9, CER = 0
      __lowerCAmelCase:  Tuple        = cer.compute(predictions=_SCREAMING_SNAKE_CASE     ,    references=_SCREAMING_SNAKE_CASE   )
      self.assertTrue(abs(char_error_rate - 0.0   ) < 1E-6   )


     def     UpperCAmelCase    (				self     :						Dict   )				->      List[Any]:
      __lowerCAmelCase:  Union[str, Any]        = ['werewolf']
      __lowerCAmelCase:  List[Any]        = ['weaewolf']
      # S = 1, D = 0, I = 0, N = 8, CER = 0.125
      __lowerCAmelCase:  Optional[Any]        = cer.compute(predictions=_SCREAMING_SNAKE_CASE     ,    references=_SCREAMING_SNAKE_CASE   )
      self.assertTrue(abs(char_error_rate - 0.125   ) < 1E-6   )


     def     UpperCAmelCase    (				self     :						Any   )				->      Optional[int]:
      __lowerCAmelCase:  Dict        = ['werewolf']
      __lowerCAmelCase:  Optional[int]        = ['wereawolf']
      # S = 0, D = 1, I = 0, N = 8, CER = 0.125
      __lowerCAmelCase:  Dict        = cer.compute(predictions=_SCREAMING_SNAKE_CASE     ,    references=_SCREAMING_SNAKE_CASE   )
      self.assertTrue(abs(char_error_rate - 0.125   ) < 1E-6   )


     def     UpperCAmelCase    (				self     :						Optional[int]   )				->      str:
      __lowerCAmelCase:  List[str]        = ['werewolf']
      __lowerCAmelCase:  List[Any]        = ['wereolf']
      # S = 0, D = 0, I = 1, N = 8, CER = 0.125
      __lowerCAmelCase:  Union[str, Any]        = cer.compute(predictions=_SCREAMING_SNAKE_CASE     ,    references=_SCREAMING_SNAKE_CASE   )
      self.assertTrue(abs(char_error_rate - 0.125   ) < 1E-6   )


     def     UpperCAmelCase    (				self     :						Any   )				->      Optional[Any]:
      __lowerCAmelCase:  str        = ['werewolf']
      __lowerCAmelCase:  int        = cer.compute(predictions=_SCREAMING_SNAKE_CASE     ,    references=_SCREAMING_SNAKE_CASE   )
      self.assertEqual(_SCREAMING_SNAKE_CASE     ,    0.0   )


     def     UpperCAmelCase    (				self     :						List[str]   )				->      Any:
      __lowerCAmelCase:  Dict        = ['werewolf', 'I am your father']
      __lowerCAmelCase:  Dict        = cer.compute(predictions=_SCREAMING_SNAKE_CASE     ,    references=_SCREAMING_SNAKE_CASE   )
      self.assertEqual(_SCREAMING_SNAKE_CASE     ,    0.0   )

      __lowerCAmelCase:  List[str]        = ['werewolf', 'I am your father', 'doge']
      __lowerCAmelCase:  int        = ['werxwolf', 'I       am your father', 'doge']
      # S = 1, D = 0, I = 0, N = 28, CER = 1 / 28
      __lowerCAmelCase:  Dict        = cer.compute(predictions=_SCREAMING_SNAKE_CASE     ,    references=_SCREAMING_SNAKE_CASE   )
      self.assertTrue(abs(char_error_rate - 0.03571428   ) < 1E-6   )


     def     UpperCAmelCase    (				self     :						List[str]   )				->      Optional[Any]:
      __lowerCAmelCase:  Optional[int]        = ['My hovercraft', 'is full of eels']
      __lowerCAmelCase:  int        = ['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:  Optional[int]        = cer.compute(predictions=_SCREAMING_SNAKE_CASE     ,    references=_SCREAMING_SNAKE_CASE     ,    concatenate_texts=_SCREAMING_SNAKE_CASE   )
      self.assertTrue(abs(char_error_rate - 0.071428   ) < 1E-6   )


     def     UpperCAmelCase    (				self     :						Union[str, Any]   )				->      List[str]:
      __lowerCAmelCase:  List[Any]        = ['我能吞下玻璃而不伤身体']
      __lowerCAmelCase:  Dict        = [' 能吞虾玻璃而 不霜身体啦']
      # S = 3, D = 2, I = 0, N = 11, CER = 5 / 11
      __lowerCAmelCase:  str        = cer.compute(predictions=_SCREAMING_SNAKE_CASE     ,    references=_SCREAMING_SNAKE_CASE   )
      self.assertTrue(abs(char_error_rate - 0.4545454545   ) < 1E-6   )

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

      __lowerCAmelCase:  List[str]        = ['我能吞下玻璃而不伤身体']
      __lowerCAmelCase:  Tuple        = cer.compute(predictions=_SCREAMING_SNAKE_CASE     ,    references=_SCREAMING_SNAKE_CASE   )
      self.assertFalse(_SCREAMING_SNAKE_CASE     ,    0.0   )


     def     UpperCAmelCase    (				self     :						Tuple   )				->      Tuple:
      __lowerCAmelCase:  int        = ['']
      __lowerCAmelCase:  Dict        = ['Hypothesis']
      with self.assertRaises(_SCREAMING_SNAKE_CASE   ):
       cer.compute(predictions=_SCREAMING_SNAKE_CASE     ,    references=_SCREAMING_SNAKE_CASE   )


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













import numpy as np







def   snake_case		(				UpperCAmelCase						:							Any ):
				A									=   np.exp(UpperCAmelCase )

				# Add up the all the exponentials
				A									=   np.sum(UpperCAmelCase )

				# Divide every exponent by the sum of all exponents
				A									=   exponent_vector / sum_of_exponents

				return softmax_vector


if __name__ == "__main__":
					print(softmax((0,)))





