


from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_sentencepiece_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


_A							     =       {
    'configuration_big_bird': ['BIG_BIRD_PRETRAINED_CONFIG_ARCHIVE_MAP', 'BigBirdConfig', 'BigBirdOnnxConfig'],
}

try:
			if not is_sentencepiece_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			_A							     =       ['BigBirdTokenizer']

try:
			if not is_tokenizers_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			_A							     =       ['BigBirdTokenizerFast']

try:
			if not is_torch_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			_A							     =       [
			    'BIG_BIRD_PRETRAINED_MODEL_ARCHIVE_LIST',
			    'BigBirdForCausalLM',
			    'BigBirdForMaskedLM',
			    'BigBirdForMultipleChoice',
			    'BigBirdForPreTraining',
			    'BigBirdForQuestionAnswering',
			    'BigBirdForSequenceClassification',
			    'BigBirdForTokenClassification',
			    'BigBirdLayer',
			    'BigBirdModel',
			    'BigBirdPreTrainedModel',
			    'load_tf_weights_in_big_bird',
			]

try:
			if not is_flax_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			_A							     =       [
			    'FlaxBigBirdForCausalLM',
			    'FlaxBigBirdForMaskedLM',
			    'FlaxBigBirdForMultipleChoice',
			    'FlaxBigBirdForPreTraining',
			    'FlaxBigBirdForQuestionAnswering',
			    'FlaxBigBirdForSequenceClassification',
			    'FlaxBigBirdForTokenClassification',
			    'FlaxBigBirdModel',
			    'FlaxBigBirdPreTrainedModel',
			]

if TYPE_CHECKING:
			from .configuration_big_bird import BIG_BIRD_PRETRAINED_CONFIG_ARCHIVE_MAP, BigBirdConfig, BigBirdOnnxConfig

			try:
						if not is_sentencepiece_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .tokenization_big_bird import BigBirdTokenizer

			try:
						if not is_tokenizers_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .tokenization_big_bird_fast import BigBirdTokenizerFast

			try:
						if not is_torch_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .modeling_big_bird import (
						    BIG_BIRD_PRETRAINED_MODEL_ARCHIVE_LIST,
						    BigBirdForCausalLM,
						    BigBirdForMaskedLM,
						    BigBirdForMultipleChoice,
						    BigBirdForPreTraining,
						    BigBirdForQuestionAnswering,
						    BigBirdForSequenceClassification,
						    BigBirdForTokenClassification,
						    BigBirdLayer,
						    BigBirdModel,
						    BigBirdPreTrainedModel,
						    load_tf_weights_in_big_bird,
						)

			try:
						if not is_flax_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .modeling_flax_big_bird import (
						    FlaxBigBirdForCausalLM,
						    FlaxBigBirdForMaskedLM,
						    FlaxBigBirdForMultipleChoice,
						    FlaxBigBirdForPreTraining,
						    FlaxBigBirdForQuestionAnswering,
						    FlaxBigBirdForSequenceClassification,
						    FlaxBigBirdForTokenClassification,
						    FlaxBigBirdModel,
						    FlaxBigBirdPreTrainedModel,
						)

else:
			import sys

			_A							     =       _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)
import unittest

from cer import CER


lowerCAmelCase__      		=					CER()
class 							a_					(		unittest.TestCase		):






 '''simple docstring'''






 def 						__snake_case		(     self   :    Any):







        '''simple docstring'''



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




 def 						__snake_case		(     self   :    List[Any]):







        '''simple docstring'''



        lowerCAmelCase__	      =   ['were wolf']
        lowerCAmelCase__	      =   ['werewolf']
        # S = 0, D = 0, I = 1, N = 9, CER = 1 / 9
        lowerCAmelCase__	      =   cer.compute(predictions=lowercase__     ,       references=lowercase__)
        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=lowercase__     ,       references=lowercase__)
        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=lowercase__     ,       references=lowercase__)
        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=lowercase__     ,       references=lowercase__)
        self.assertTrue(abs(char_error_rate - 0.0) < 1e-6)




 def 						__snake_case		(     self   :    Optional[Any]):







        '''simple docstring'''



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




 def 						__snake_case		(     self   :    Tuple):







        '''simple docstring'''



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




 def 						__snake_case		(     self   :    Optional[int]):







        '''simple docstring'''



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




 def 						__snake_case		(     self   :    str):







        '''simple docstring'''



        lowerCAmelCase__	      =   ['werewolf']
        lowerCAmelCase__	      =   cer.compute(predictions=lowercase__     ,       references=lowercase__)
        self.assertEqual(lowercase__     ,       0.0)




 def 						__snake_case		(     self   :    Tuple):







        '''simple docstring'''



        lowerCAmelCase__	      =   ['werewolf', 'I am your father']
        lowerCAmelCase__	      =   cer.compute(predictions=lowercase__     ,       references=lowercase__)
        self.assertEqual(lowercase__     ,       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=lowercase__     ,       references=lowercase__)
        self.assertTrue(abs(char_error_rate - 0.03_571_428) < 1e-6)




 def 						__snake_case		(     self   :    Tuple):







        '''simple docstring'''



        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=lowercase__     ,       references=lowercase__     ,       concatenate_texts=lowercase__)
        self.assertTrue(abs(char_error_rate - 0.071_428) < 1e-6)




 def 						__snake_case		(     self   :    Dict):







        '''simple docstring'''



        lowerCAmelCase__	      =   ['我能吞下玻璃而不伤身体']
        lowerCAmelCase__	      =   [' 能吞虾玻璃而 不霜身体啦']
        # S = 3, D = 2, I = 0, N = 11, CER = 5 / 11
        lowerCAmelCase__	      =   cer.compute(predictions=lowercase__     ,       references=lowercase__)
        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=lowercase__     ,       references=lowercase__)
        self.assertTrue(abs(char_error_rate - 0.454_545_454_545) < 1e-6)

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




 def 						__snake_case		(     self   :    Dict):







        '''simple docstring'''



        lowerCAmelCase__	      =   ['']
        lowerCAmelCase__	      =   ['Hypothesis']
        with self.assertRaises(lowercase__):
               cer.compute(predictions=lowercase__     ,       references=lowercase__)


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