


"""simple docstring"""



import unittest

from cer import CER


SCREAMING_SNAKE_CASE       = CER()




class 			UpperCAmelCase_						(		unittest.TestCase							):




    def 							__magic_name__							(					self		: str   )   ->							Optional[Any]:




     '''simple docstring'''

     A__ =       ["White House"]
     A__ =       ["white house"]
     # S = 2, D = 0, I = 0, N = 11, CER = 2 / 11
     A__ =       cer.compute(predictions=a_			,				references=a_   )
     self.assertTrue(abs(char_error_rate - 0.18_1818_1818   ) < 1e-6   )




    def 							__magic_name__							(					self		: int   )   ->							int:




     '''simple docstring'''

     A__ =       ["were wolf"]
     A__ =       ["werewolf"]
     # S = 0, D = 0, I = 1, N = 9, CER = 1 / 9
     A__ =       cer.compute(predictions=a_			,				references=a_   )
     self.assertTrue(abs(char_error_rate - 0.111_1111   ) < 1e-6   )

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

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

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




    def 							__magic_name__							(					self		: Tuple   )   ->							List[Any]:




     '''simple docstring'''

     A__ =       ["werewolf"]
     A__ =       ["weaewolf"]
     # S = 1, D = 0, I = 0, N = 8, CER = 0.125
     A__ =       cer.compute(predictions=a_			,				references=a_   )
     self.assertTrue(abs(char_error_rate - 0.125   ) < 1e-6   )




    def 							__magic_name__							(					self		: Tuple   )   ->							List[Any]:




     '''simple docstring'''

     A__ =       ["werewolf"]
     A__ =       ["wereawolf"]
     # S = 0, D = 1, I = 0, N = 8, CER = 0.125
     A__ =       cer.compute(predictions=a_			,				references=a_   )
     self.assertTrue(abs(char_error_rate - 0.125   ) < 1e-6   )




    def 							__magic_name__							(					self		: Dict   )   ->							Optional[int]:




     '''simple docstring'''

     A__ =       ["werewolf"]
     A__ =       ["wereolf"]
     # S = 0, D = 0, I = 1, N = 8, CER = 0.125
     A__ =       cer.compute(predictions=a_			,				references=a_   )
     self.assertTrue(abs(char_error_rate - 0.125   ) < 1e-6   )




    def 							__magic_name__							(					self		: Any   )   ->							Optional[int]:




     '''simple docstring'''

     A__ =       ["werewolf"]
     A__ =       cer.compute(predictions=a_			,				references=a_   )
     self.assertEqual(a_			,				0.0   )




    def 							__magic_name__							(					self		: Dict   )   ->							List[str]:




     '''simple docstring'''

     A__ =       ["werewolf", "I am your father"]
     A__ =       cer.compute(predictions=a_			,				references=a_   )
     self.assertEqual(a_			,				0.0   )

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




    def 							__magic_name__							(					self		: str   )   ->							List[Any]:




     '''simple docstring'''

     A__ =       ["My hovercraft", "is full of eels"]
     A__ =       ["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
     A__ =       cer.compute(predictions=a_			,				references=a_			,				concatenate_texts=a_   )
     self.assertTrue(abs(char_error_rate - 0.07_1428   ) < 1e-6   )




    def 							__magic_name__							(					self		: Dict   )   ->							Optional[int]:




     '''simple docstring'''

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

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

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




    def 							__magic_name__							(					self		: Any   )   ->							Dict:




     '''simple docstring'''

     A__ =       [""]
     A__ =       ["Hypothesis"]
     with self.assertRaises(a_   ):
      cer.compute(predictions=a_			,				references=a_   )


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











"""simple docstring"""



from manim import *




class 			UpperCAmelCase_						(		A_							):




    def 							__magic_name__							(					self		: Any   )   ->							Optional[int]:




     '''simple docstring'''

     A__ =       Rectangle(height=0.5			,				width=0.5   )
     A__ =       Rectangle(height=0.46			,				width=0.46   ).set_stroke(width=0   )
     A__ =       Rectangle(height=0.25			,				width=0.25   )

     A__ =       [mem.copy() for i in range(6   )]
     A__ =       [mem.copy() for i in range(6   )]
     A__ =       VGroup(*snake_case_   ).arrange(snake_case_			,				buff=0   )
     A__ =       VGroup(*snake_case_   ).arrange(snake_case_			,				buff=0   )
     A__ =       VGroup(snake_case_			,				snake_case_   ).arrange(snake_case_			,				buff=0   )
     A__ =       Text("CPU"			,				font_size=24   )
     A__ =       Group(snake_case_			,				snake_case_   ).arrange(snake_case_			,				buff=0.5			,				aligned_edge=snake_case_   )
     cpu.move_to([-2.5, -0.5, 0]   )
     self.add(snake_case_   )

     A__ =       [mem.copy() for i in range(4   )]
     A__ =       VGroup(*snake_case_   ).arrange(snake_case_			,				buff=0   )
     A__ =       Text("GPU"			,				font_size=24   )
     A__ =       Group(snake_case_			,				snake_case_   ).arrange(snake_case_			,				buff=0.5			,				aligned_edge=snake_case_   )
     gpu.move_to([-1, -1, 0]   )
     self.add(snake_case_   )

     A__ =       [mem.copy() for i in range(6   )]
     A__ =       VGroup(*snake_case_   ).arrange(snake_case_			,				buff=0   )

     A__ =       Text("Model"			,				font_size=24   )
     A__ =       Group(snake_case_			,				snake_case_   ).arrange(snake_case_			,				buff=0.5			,				aligned_edge=snake_case_   )
     model.move_to([3, -1.0, 0]   )
     self.add(snake_case_   )

     A__ =       []
     A__ =       []

     for i, rect in enumerate(snake_case_   ):
      rect.set_stroke(snake_case_   )

      A__ =       Rectangle(height=0.46 / 4			,				width=0.46 / 3   ).set_stroke(width=0.0   ).set_fill(snake_case_			,				opacity=0.7   )

      if i == 0:
       cpu_target.next_to(cpu_left_col_base[0].get_corner(DOWN + LEFT   )			,				buff=0.02			,				direction=snake_case_   )
       cpu_target.set_x(cpu_target.get_x() + 0.1   )
      elif i == 3:
       cpu_target.next_to(model_cpu_arr[0]			,				direction=snake_case_			,				buff=0.0   )
      else:
       cpu_target.next_to(model_cpu_arr[i - 1]			,				direction=snake_case_			,				buff=0.0   )
      self.add(snake_case_   )
      model_cpu_arr.append(snake_case_   )

     self.add(*snake_case_			,				*snake_case_   )

     A__ =       [meta_mem.copy() for i in range(6   )]
     A__ =       [meta_mem.copy() for i in range(6   )]
     A__ =       VGroup(*snake_case_   ).arrange(snake_case_			,				buff=0   )
     A__ =       VGroup(*snake_case_   ).arrange(snake_case_			,				buff=0   )
     A__ =       VGroup(snake_case_			,				snake_case_   ).arrange(snake_case_			,				buff=0   )
     A__ =       Text("Disk"			,				font_size=24   )
     A__ =       Group(snake_case_			,				snake_case_   ).arrange(snake_case_			,				buff=0.5			,				aligned_edge=snake_case_   )
     disk.move_to([-4.0, -1.25, 0]   )
     self.add(snake_case_			,				snake_case_   )

     A__ =       []

     for i in range(6   ):
      A__ =       fill.copy().set_fill(snake_case_			,				opacity=0.8   )
      target.move_to(disk_left_col_base[i]   ).scale(0.5   )
      cpu_disk_arr.append(snake_case_   )

     self.add(*snake_case_   )

     A__ =       Square(side_length=2.2   )
     key.move_to([-5, 2, 0]   )

     A__ =       MarkupText(
         F"""<b>Key:</b>\n\n<span fgcolor='{YELLOW}'>●</span> Empty Model"""			,				font_size=18			,				)

     key_text.move_to([-5, 2.4, 0]   )

     self.add(snake_case_			,				snake_case_   )

     A__ =       MarkupText(
         F"""<span fgcolor='{BLUE}'>●</span> Checkpoint"""			,				font_size=18			,				)

     blue_text.next_to(snake_case_			,				DOWN * 2.4			,				aligned_edge=key_text.get_left()   )
     self.add(snake_case_   )

     A__ =       MarkupText(F"""The offloaded weights are all sent to the CPU."""			,				font_size=24   )
     step_a.move_to([2, 2, 0]   )

     self.play(Write(snake_case_			,				run_time=3   )   )

     for i in range(6   ):
      A__ =       cpu_disk_arr[i]
      A__ =       rect.copy().set_fill(snake_case_			,				opacity=0.8   ).scale(2.0   )
      cpa.generate_target()
      cpa.target.move_to(model_base[i]   )

      if i == 0:
       rect.set_fill(snake_case_			,				opacity=0.8   )
       rect.generate_target()
       rect.target.move_to(cpu_left_col_base[0]   ).scale(2.0   )

       self.remove(
           *snake_case_			,				*snake_case_			,				)

      else:
       rect.generate_target()
       rect.target.move_to(cpu_left_col_base[i]   ).scale(2.0   )
      self.play(MoveToTarget(snake_case_   )			,				MoveToTarget(snake_case_   )			,				model_base[i].animate.set_stroke(snake_case_   )   )
     self.play(FadeOut(snake_case_   )   )

     A__ =       MarkupText(
         F"""Finally, hooks are added to each weight in the model\nto transfer the weights from CPU to GPU\n\t\tand back when needed."""			,				font_size=24			,				)
     step_a.move_to([2, 2, 0]   )

     self.play(Write(snake_case_			,				run_time=3   )   )

     A__ =       []
     A__ =       []
     for i in range(6   ):
      A__ =       Arrow(start=snake_case_			,				end=snake_case_			,				color=snake_case_			,				buff=0.5   )
      a.next_to(model_base[i].get_left()			,				snake_case_			,				buff=0.2   )
      arrows.append(snake_case_   )
      animations.append(Write(snake_case_   )   )
     self.play(*snake_case_   )
     self.wait()





