

from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


lowercase_     =       logging.get_logger(__name__)

lowercase_     =       {
    'google/electra-small-generator': 'https://huggingface.co/google/electra-small-generator/resolve/main/config.json',
    'google/electra-base-generator': 'https://huggingface.co/google/electra-base-generator/resolve/main/config.json',
    'google/electra-large-generator': 'https://huggingface.co/google/electra-large-generator/resolve/main/config.json',
    'google/electra-small-discriminator': (
        'https://huggingface.co/google/electra-small-discriminator/resolve/main/config.json'
    ),
    'google/electra-base-discriminator': (
        'https://huggingface.co/google/electra-base-discriminator/resolve/main/config.json'
    ),
    'google/electra-large-discriminator': (
        'https://huggingface.co/google/electra-large-discriminator/resolve/main/config.json'
    ),
}





class 			__lowerCAmelCase					( SCREAMING_SNAKE_CASE							):
  _a						      =  """electra"""




  def __init__(    self							,       lowerCAmelCase=30_522							,       lowerCAmelCase=128							,       lowerCAmelCase=256							,       lowerCAmelCase=12							,       lowerCAmelCase=4							,       lowerCAmelCase=1_024							,       lowerCAmelCase="gelu"							,       lowerCAmelCase=0.1							,       lowerCAmelCase=0.1							,       lowerCAmelCase=512							,       lowerCAmelCase=2							,       lowerCAmelCase=0.02							,       lowerCAmelCase=1e-12							,       lowerCAmelCase="first"							,       lowerCAmelCase=True							,       lowerCAmelCase="gelu"							,       lowerCAmelCase=0.1							,       lowerCAmelCase=0							,       lowerCAmelCase="absolute"							,       lowerCAmelCase=True							,       lowerCAmelCase=None							,       **lowerCAmelCase							,       )  ->			int:
        '''simple docstring'''






        super().__init__(pad_token_id=lowerCAmelCase							,       **lowerCAmelCase )

        _lowercase     	=vocab_size
        _lowercase     	=embedding_size
        _lowercase     	=hidden_size
        _lowercase     	=num_hidden_layers
        _lowercase     	=num_attention_heads
        _lowercase     	=intermediate_size
        _lowercase     	=hidden_act
        _lowercase     	=hidden_dropout_prob
        _lowercase     	=attention_probs_dropout_prob
        _lowercase     	=max_position_embeddings
        _lowercase     	=type_vocab_size
        _lowercase     	=initializer_range
        _lowercase     	=layer_norm_eps

        _lowercase     	=summary_type
        _lowercase     	=summary_use_proj
        _lowercase     	=summary_activation
        _lowercase     	=summary_last_dropout
        _lowercase     	=position_embedding_type
        _lowercase     	=use_cache
        _lowercase     	=classifier_dropout





class 			__lowerCAmelCase					( SCREAMING_SNAKE_CASE							):




  @property
  def   A__					(    self )  ->			Mapping[str, Mapping[int, str]]:
        '''simple docstring'''






        if self.task == "multiple-choice":
              _lowercase     	={0: 'batch', 1: 'choice', 2: 'sequence'}
        else:
              _lowercase     	={0: 'batch', 1: 'sequence'}
        return OrderedDict(
            [
                ('input_ids', dynamic_axis),
                ('attention_mask', dynamic_axis),
                ('token_type_ids', dynamic_axis),
            ] )





import unittest

from cer import CER


lowercase_     =       CER()





class 			__lowerCAmelCase					( unittest.TestCase							):




  def   A__					(    self )  ->			Any:
        '''simple docstring'''






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




  def   A__					(    self )  ->			Dict:
        '''simple docstring'''






        _lowercase     	=['were wolf']
        _lowercase     	=['werewolf']
        # S = 0, D = 0, I = 1, N = 9, CER = 1 / 9
        _lowercase     	=cer.compute(predictions=lowerCAmelCase							,       references=lowerCAmelCase )
        self.assertTrue(abs(char_error_rate - 0.1111111 ) < 1e-6 )

        _lowercase     	=['werewolf']
        _lowercase     	=['weae     wolf']
        # S = 1, D = 1, I = 0, N = 8, CER = 0.25
        _lowercase     	=cer.compute(predictions=lowerCAmelCase							,       references=lowerCAmelCase )
        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=lowerCAmelCase							,       references=lowerCAmelCase )
        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=lowerCAmelCase							,       references=lowerCAmelCase )
        self.assertTrue(abs(char_error_rate - 0.0 ) < 1e-6 )




  def   A__					(    self )  ->			Optional[Any]:
        '''simple docstring'''






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




  def   A__					(    self )  ->			Union[str, Any]:
        '''simple docstring'''






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




  def   A__					(    self )  ->			Any:
        '''simple docstring'''






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




  def   A__					(    self )  ->			Any:
        '''simple docstring'''






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




  def   A__					(    self )  ->			List[Any]:
        '''simple docstring'''






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




  def   A__					(    self )  ->			str:
        '''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=lowerCAmelCase							,       references=lowerCAmelCase							,       concatenate_texts=lowerCAmelCase )
        self.assertTrue(abs(char_error_rate - 0.071428 ) < 1e-6 )




  def   A__					(    self )  ->			Union[str, Any]:
        '''simple docstring'''






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

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

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




  def   A__					(    self )  ->			List[str]:
        '''simple docstring'''






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


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


