


'''simple docstring'''

import unittest

from cer import CER


__lowercase:		Tuple    						=  CER()







class 			UpperCAmelCase			(							unittest.TestCase):

 def 		lowercase_    (			self			:						int       ):





    """simple docstring"""



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

 def 		lowercase_    (			self			:						List[Any]       ):





    """simple docstring"""



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

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

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

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

 def 		lowercase_    (			self			:						Optional[Any]       ):





    """simple docstring"""



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

 def 		lowercase_    (			self			:						Dict       ):





    """simple docstring"""



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

 def 		lowercase_    (			self			:						List[str]       ):





    """simple docstring"""



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

 def 		lowercase_    (			self			:						str       ):





    """simple docstring"""



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

 def 		lowercase_    (			self			:						List[Any]       ):





    """simple docstring"""



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

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

 def 		lowercase_    (			self			:						List[Any]       ):





    """simple docstring"""



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

 def 		lowercase_    (			self			:						Optional[Any]       ):





    """simple docstring"""



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

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

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

 def 		lowercase_    (			self			:						Union[str, Any]       ):





    """simple docstring"""



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


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



'''simple docstring'''

from dataclasses import dataclass
from enum import Enum
from typing import List, Optional, Union

import numpy as np
import PIL
from PIL import Image

from ...utils import BaseOutput, is_torch_available, is_transformers_available


@dataclass
class    a__					(			__A   ):







				"""simple docstring"""



				__UpperCamelCase     :		Tuple						=						{
				    'sld_warmup_steps': 15,
				    'sld_guidance_scale': 20,
				    'sld_threshold': 0.0,
				    'sld_momentum_scale': 0.0,
				    'sld_mom_beta': 0.0,
				}
				__UpperCamelCase     :		Optional[Any]						=						{
				    'sld_warmup_steps': 10,
				    'sld_guidance_scale': 1_000,
				    'sld_threshold': 0.01,
				    'sld_momentum_scale': 0.3,
				    'sld_mom_beta': 0.4,
				}
				__UpperCamelCase     :		Tuple						=						{
				    'sld_warmup_steps': 7,
				    'sld_guidance_scale': 2_000,
				    'sld_threshold': 0.025,
				    'sld_momentum_scale': 0.5,
				    'sld_mom_beta': 0.7,
				}
				__UpperCamelCase     :		str						=						{
				    'sld_warmup_steps': 0,
				    'sld_guidance_scale': 5_000,
				    'sld_threshold': 1.0,
				    'sld_momentum_scale': 0.5,
				    'sld_mom_beta': 0.7,
				}


@dataclass
class    a__					(			__A   ):







				"""simple docstring"""



				__UpperCamelCase     :		Union[List[PIL.Image.Image], np.ndarray]
				__UpperCamelCase     :		Optional[List[bool]]
				__UpperCamelCase     :		Optional[Union[List[PIL.Image.Image], np.ndarray]]
				__UpperCamelCase     :		Optional[str]


if is_transformers_available() and is_torch_available():
	from .pipeline_stable_diffusion_safe import StableDiffusionPipelineSafe
	from .safety_checker import SafeStableDiffusionSafetyChecker

