code: 
  
  
  '''simple docstring'''
  
  import unittest
  
  from cer import CER
  
  
  lowerCamelCase							:     List[Any]								=			CER()
  class 						__lowerCAmelCase		(unittest.TestCase  ):
  
  
  
  
  
        '''simple docstring'''
  
  
  
  
  
  
        def    UpperCamelCase__	(self					:					int				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               lowercase__       =				['''White House''']
               lowercase__       =				['''white house''']
               # S = 2, D = 0, I = 0, N = 11, CER = 2 / 11
               lowercase__       =				cer.compute(predictions=UpperCamelCase     ,		references=UpperCamelCase				)
               self.assertTrue(abs(char_error_rate - 0.18_18_18_18_18				) < 1E-6				)
  
  
  
        def    UpperCamelCase__	(self					:					str				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               lowercase__       =				['''were wolf''']
               lowercase__       =				['''werewolf''']
               # S = 0, D = 0, I = 1, N = 9, CER = 1 / 9
               lowercase__       =				cer.compute(predictions=UpperCamelCase     ,		references=UpperCamelCase				)
               self.assertTrue(abs(char_error_rate - 0.1_11_11_11				) < 1E-6				)
  
               lowercase__       =				['''werewolf''']
               lowercase__       =				['''weae     wolf''']
               # S = 1, D = 1, I = 0, N = 8, CER = 0.25
               lowercase__       =				cer.compute(predictions=UpperCamelCase     ,		references=UpperCamelCase				)
               self.assertTrue(abs(char_error_rate - 0.25				) < 1E-6				)
  
               # consecutive whitespaces case 1
               lowercase__       =				['''were wolf''']
               lowercase__       =				['''were               wolf''']
               # S = 0, D = 0, I = 0, N = 9, CER = 0
               lowercase__       =				cer.compute(predictions=UpperCamelCase     ,		references=UpperCamelCase				)
               self.assertTrue(abs(char_error_rate - 0.0				) < 1E-6				)
  
               # consecutive whitespaces case 2
               lowercase__       =				['''were   wolf''']
               lowercase__       =				['''were               wolf''']
               # S = 0, D = 0, I = 0, N = 9, CER = 0
               lowercase__       =				cer.compute(predictions=UpperCamelCase     ,		references=UpperCamelCase				)
               self.assertTrue(abs(char_error_rate - 0.0				) < 1E-6				)
  
  
  
        def    UpperCamelCase__	(self					:					Tuple				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               lowercase__       =				['''werewolf''']
               lowercase__       =				['''weaewolf''']
               # S = 1, D = 0, I = 0, N = 8, CER = 0.125
               lowercase__       =				cer.compute(predictions=UpperCamelCase     ,		references=UpperCamelCase				)
               self.assertTrue(abs(char_error_rate - 0.1_25				) < 1E-6				)
  
  
  
        def    UpperCamelCase__	(self					:					Dict				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               lowercase__       =				['''werewolf''']
               lowercase__       =				['''wereawolf''']
               # S = 0, D = 1, I = 0, N = 8, CER = 0.125
               lowercase__       =				cer.compute(predictions=UpperCamelCase     ,		references=UpperCamelCase				)
               self.assertTrue(abs(char_error_rate - 0.1_25				) < 1E-6				)
  
  
  
        def    UpperCamelCase__	(self					:					str				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               lowercase__       =				['''werewolf''']
               lowercase__       =				['''wereolf''']
               # S = 0, D = 0, I = 1, N = 8, CER = 0.125
               lowercase__       =				cer.compute(predictions=UpperCamelCase     ,		references=UpperCamelCase				)
               self.assertTrue(abs(char_error_rate - 0.1_25				) < 1E-6				)
  
  
  
        def    UpperCamelCase__	(self					:					Union[str, Any]				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               lowercase__       =				['''werewolf''']
               lowercase__       =				cer.compute(predictions=UpperCamelCase     ,		references=UpperCamelCase				)
               self.assertEqual(UpperCamelCase     ,		0.0				)
  
  
  
        def    UpperCamelCase__	(self					:					Optional[Any]				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               lowercase__       =				['''werewolf''', '''I am your father''']
               lowercase__       =				cer.compute(predictions=UpperCamelCase     ,		references=UpperCamelCase				)
               self.assertEqual(UpperCamelCase     ,		0.0				)
  
               lowercase__       =				['''werewolf''', '''I am your father''', '''doge''']
               lowercase__       =				['''werxwolf''', '''I       am your father''', '''doge''']
               # S = 1, D = 0, I = 0, N = 28, CER = 1 / 28
               lowercase__       =				cer.compute(predictions=UpperCamelCase     ,		references=UpperCamelCase				)
               self.assertTrue(abs(char_error_rate - 0.03_57_14_28				) < 1E-6				)
  
  
  
        def    UpperCamelCase__	(self					:					Optional[Any]				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               lowercase__       =				['''My hovercraft''', '''is full of eels''']
               lowercase__       =				['''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
               lowercase__       =				cer.compute(predictions=UpperCamelCase     ,		references=UpperCamelCase     ,		concatenate_texts=UpperCamelCase				)
               self.assertTrue(abs(char_error_rate - 0.07_14_28				) < 1E-6				)
  
  
  
        def    UpperCamelCase__	(self					:					int				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               lowercase__       =				['''我能吞下玻璃而不伤身体''']
               lowercase__       =				[''' 能吞虾玻璃而 不霜身体啦''']
               # S = 3, D = 2, I = 0, N = 11, CER = 5 / 11
               lowercase__       =				cer.compute(predictions=UpperCamelCase     ,		references=UpperCamelCase				)
               self.assertTrue(abs(char_error_rate - 0.45_45_45_45_45				) < 1E-6				)
  
               lowercase__       =				['''我能吞下玻璃''', '''而不伤身体''']
               lowercase__       =				['''我    能 吞 下 玻 璃''', '''而不伤身体''']
               # S = 0, D = 5, I = 0, N = 11, CER = 5 / 11
               lowercase__       =				cer.compute(predictions=UpperCamelCase     ,		references=UpperCamelCase				)
               self.assertTrue(abs(char_error_rate - 0.45_45_45_45_45_45				) < 1E-6				)
  
               lowercase__       =				['''我能吞下玻璃而不伤身体''']
               lowercase__       =				cer.compute(predictions=UpperCamelCase     ,		references=UpperCamelCase				)
               self.assertFalse(UpperCamelCase     ,		0.0				)
  
  
  
  
  
  
        def    UpperCamelCase__	(self					:					List[Any]				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               lowercase__       =				['''''']
               lowercase__       =				['''Hypothesis''']
               with self.assertRaises(UpperCamelCase				):
                      cer.compute(predictions=UpperCamelCase     ,		references=UpperCamelCase				)
  
  
  if __name__ == "__main__":
   unittest.main()
  
  
  
  
  
style_context: 
  
  
  '''simple docstring'''
  
  import torch
  
  from accelerate import Accelerator, DistributedType
  class 						__lowerCAmelCase		:
  
  
  
  
  
        '''simple docstring'''
  
  
  
  
  
  
        def __enter__(self					:					List[Any]				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               if self.enabled:
                      lowercase__       =				self.model.no_sync()
                      self.model_sync_obj.__enter__()
  
               return self
  
  
  
        def __exit__(self					:					List[str]     ,		UpperCamelCase					:					List[Any]     ,		UpperCamelCase					:					Optional[int]     ,		UpperCamelCase					:					Optional[int]				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               if self.enabled:
                      # Average all models on exit
                      self._sync_and_avg_model_params()
                      self.model_sync_obj.__exit__(UpperCamelCase     ,		UpperCamelCase     ,		UpperCamelCase				)
  
  
  
        def __init__(self					:					Dict     ,		UpperCamelCase					:					Accelerator     ,		UpperCamelCase					:					torch.nn.Module     ,		UpperCamelCase					:					int     ,		UpperCamelCase					:					bool = True				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               if accelerator.distributed_type not in [
                   DistributedType.NO,
                   DistributedType.MULTI_CPU,
                   DistributedType.MULTI_GPU,
               ]:
                      raise NotImplementedError('''LocalSGD is supported only for CPUs and GPUs (no DeepSpeed or MegatronLM)'''				)
               lowercase__       =				enabled and accelerator.distributed_type != DistributedType.NO
               lowercase__       =				0
               if self.enabled:
                      lowercase__       =				accelerator
                      lowercase__       =				model
                      lowercase__       =				local_sgd_steps
  
  
  
        def    UpperCamelCase__	(self					:					List[str]				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               self.num_steps += 1
               if not self.enabled:
                      return
  
               if self.num_steps % self.local_sgd_steps == 0:
                      self._sync_and_avg_model_params()
  
  
  
  
  
  
        def    UpperCamelCase__	(self					:					Any				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               self.accelerator.wait_for_everyone()
               with self.accelerator.autocast():
                      for param in self.model.parameters():
                             lowercase__       =				self.accelerator.reduce(param.data     ,		reduction='''mean'''				)
  
  
  
  
  