import unittest

import numpy as np

from transformers import ElectraConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask


if is_flax_available():
    from transformers.models.electra.modeling_flax_electra import (
        FlaxElectraForCausalLM,
        FlaxElectraForMaskedLM,
        FlaxElectraForMultipleChoice,
        FlaxElectraForPreTraining,
        FlaxElectraForQuestionAnswering,
        FlaxElectraForSequenceClassification,
        FlaxElectraForTokenClassification,
        FlaxElectraModel,
    )
class 				a_ (						unittest.TestCase						):






 '''simple docstring'''






 def __init__(			self					:  str			,    lowercase__					:  Dict			,    lowercase__					:  int=13			,    lowercase__					:  Union[str, Any]=7			,    lowercase__					:  List[Any]=True			,    lowercase__					:  Dict=True			,    lowercase__					:  Any=True			,    lowercase__					:  Tuple=True			,    lowercase__					:  List[Any]=99			,    lowercase__					:  List[Any]=24			,    lowercase__					:  Union[str, Any]=32			,    lowercase__					:  Tuple=5			,    lowercase__					:  Dict=4			,    lowercase__					:  List[Any]=37			,    lowercase__					:  Optional[Any]="gelu"			,    lowercase__					:  Optional[int]=0.1			,    lowercase__					:  Any=0.1			,    lowercase__					:  int=512			,    lowercase__					:  Any=16			,    lowercase__					:  List[Any]=2			,    lowercase__					:  Optional[int]=0.02			,    lowercase__					:  Optional[int]=4			,    ):







        '''simple docstring'''



        lowerCAmelCase__     	=					parent
        lowerCAmelCase__     	=					batch_size
        lowerCAmelCase__     	=					seq_length
        lowerCAmelCase__     	=					is_training
        lowerCAmelCase__     	=					use_attention_mask
        lowerCAmelCase__     	=					use_token_type_ids
        lowerCAmelCase__     	=					use_labels
        lowerCAmelCase__     	=					vocab_size
        lowerCAmelCase__     	=					hidden_size
        lowerCAmelCase__     	=					embedding_size
        lowerCAmelCase__     	=					num_hidden_layers
        lowerCAmelCase__     	=					num_attention_heads
        lowerCAmelCase__     	=					intermediate_size
        lowerCAmelCase__     	=					hidden_act
        lowerCAmelCase__     	=					hidden_dropout_prob
        lowerCAmelCase__     	=					attention_probs_dropout_prob
        lowerCAmelCase__     	=					max_position_embeddings
        lowerCAmelCase__     	=					type_vocab_size
        lowerCAmelCase__     	=					type_sequence_label_size
        lowerCAmelCase__     	=					initializer_range
        lowerCAmelCase__     	=					num_choices




 def 		__snake_case						(			self					:  Optional[int]):







        '''simple docstring'''



        lowerCAmelCase__     	=					ids_tensor([self.batch_size, self.seq_length]			,    self.vocab_size)

        lowerCAmelCase__     	=					None
        if self.use_attention_mask:
               lowerCAmelCase__     	=					random_attention_mask([self.batch_size, self.seq_length])

        lowerCAmelCase__     	=					None
        if self.use_token_type_ids:
               lowerCAmelCase__     	=					ids_tensor([self.batch_size, self.seq_length]			,    self.type_vocab_size)

        lowerCAmelCase__     	=					ElectraConfig(
            vocab_size=self.vocab_size			,    hidden_size=self.hidden_size			,    embedding_size=self.embedding_size			,    num_hidden_layers=self.num_hidden_layers			,    num_attention_heads=self.num_attention_heads			,    intermediate_size=self.intermediate_size			,    hidden_act=self.hidden_act			,    hidden_dropout_prob=self.hidden_dropout_prob			,    attention_probs_dropout_prob=self.attention_probs_dropout_prob			,    max_position_embeddings=self.max_position_embeddings			,    type_vocab_size=self.type_vocab_size			,    initializer_range=self.initializer_range			,    )

        return config, input_ids, token_type_ids, attention_mask




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







        '''simple docstring'''



        lowerCAmelCase__     	=					self.prepare_config_and_inputs()
        lowerCAmelCase__	,					lowerCAmelCase__	,					lowerCAmelCase__	,					lowerCAmelCase__     	=					config_and_inputs
        lowerCAmelCase__     	=					{'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': attention_mask}
        return config, inputs_dict






@require_flax
class 				a_ (						SCREAMING_SNAKE_CASE       ,     unittest.TestCase						):






 '''simple docstring'''






 UpperCAmelCase_	 =					True

 UpperCAmelCase_	 =					(
     (
         FlaxElectraModel,
         FlaxElectraForCausalLM,
         FlaxElectraForMaskedLM,
         FlaxElectraForPreTraining,
         FlaxElectraForTokenClassification,
         FlaxElectraForQuestionAnswering,
         FlaxElectraForMultipleChoice,
         FlaxElectraForSequenceClassification,
     )
     if is_flax_available()
     else ()
 )




 def 		__snake_case						(			self					:  Optional[int]):







        '''simple docstring'''



        lowerCAmelCase__     	=					FlaxElectraModelTester(self)




 @slow
 def 		__snake_case						(			self					:  Optional[int]):







        '''simple docstring'''



        for model_class_name in self.all_model_classes:
               if model_class_name == FlaxElectraForMaskedLM:
                      lowerCAmelCase__     	=					model_class_name.from_pretrained('google/electra-small-generator')
               else:
                      lowerCAmelCase__     	=					model_class_name.from_pretrained('google/electra-small-discriminator')
               lowerCAmelCase__     	=					model(np.ones((1, 1)))
               self.assertIsNotNone(lowercase__)

import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils import AddedToken
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_mpnet import MPNetTokenizer


lowerCAmelCase__							= logging.get_logger(__name__)

lowerCAmelCase__							= {'vocab_file': 'vocab.txt', 'tokenizer_file': 'tokenizer.json'}

lowerCAmelCase__							= {
    'vocab_file': {
        'microsoft/mpnet-base': 'https://huggingface.co/microsoft/mpnet-base/resolve/main/vocab.txt',
    },
    'tokenizer_file': {
        'microsoft/mpnet-base': 'https://huggingface.co/microsoft/mpnet-base/resolve/main/tokenizer.json',
    },
}

lowerCAmelCase__							= {
    'microsoft/mpnet-base': 512,
}

lowerCAmelCase__							= {
    'microsoft/mpnet-base': {'do_lower_case': True},
}
class 				a_ (						SCREAMING_SNAKE_CASE						):






 '''simple docstring'''






 UpperCAmelCase_	 =					VOCAB_FILES_NAMES
 UpperCAmelCase_	 =					PRETRAINED_VOCAB_FILES_MAP
 UpperCAmelCase_	 =					PRETRAINED_INIT_CONFIGURATION
 UpperCAmelCase_	 =					PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
 UpperCAmelCase_	 =					MPNetTokenizer
 UpperCAmelCase_	 =					['input_ids', 'attention_mask']




 def __init__(			self					:  Dict			,    lowercase__					:  Optional[int]=None			,    lowercase__					:  Tuple=None			,    lowercase__					:  str=True			,    lowercase__					:  int="<s>"			,    lowercase__					:  List[str]="</s>"			,    lowercase__					:  Tuple="</s>"			,    lowercase__					:  Tuple="<s>"			,    lowercase__					:  Dict="[UNK]"			,    lowercase__					:  int="<pad>"			,    lowercase__					:  Union[str, Any]="<mask>"			,    lowercase__					:  Tuple=True			,    lowercase__					:  int=None			,    **lowercase__					:  Union[str, Any]			,    ):







        '''simple docstring'''



        super().__init__(
            lowercase__			,    tokenizer_file=lowercase__			,    do_lower_case=lowercase__			,    bos_token=lowercase__			,    eos_token=lowercase__			,    sep_token=lowercase__			,    cls_token=lowercase__			,    unk_token=lowercase__			,    pad_token=lowercase__			,    mask_token=lowercase__			,    tokenize_chinese_chars=lowercase__			,    strip_accents=lowercase__			,    **lowercase__			,    )

        lowerCAmelCase__     	=					json.loads(self.backend_tokenizer.normalizer.__getstate__())
        if (
            pre_tok_state.get('lowercase'			,    lowercase__) != do_lower_case
            or pre_tok_state.get('strip_accents'			,    lowercase__) != strip_accents
        ):
               lowerCAmelCase__     	=					getattr(lowercase__			,    pre_tok_state.pop('type'))
               lowerCAmelCase__     	=					do_lower_case
               lowerCAmelCase__     	=					strip_accents
               lowerCAmelCase__     	=					pre_tok_class(**lowercase__)

        lowerCAmelCase__     	=					do_lower_case




 @property
 def 		__snake_case						(			self					:  Tuple):







        '''simple docstring'''



        if self._mask_token is None:
               if self.verbose:
                      logger.error('Using mask_token, but it is not set yet.')
               return None
        return str(self._mask_token)




 @mask_token.setter
 def 		__snake_case						(			self					:  Optional[int]			,    lowercase__					:  str):







        '''simple docstring'''



        lowerCAmelCase__     	=					AddedToken(lowercase__			,    lstrip=lowercase__			,    rstrip=lowercase__) if isinstance(lowercase__			,    lowercase__) else value
        lowerCAmelCase__     	=					value




 def 		__snake_case						(			self					:  Tuple			,    lowercase__					:  Union[str, Any]			,    lowercase__					:  Any=None):







        '''simple docstring'''



        lowerCAmelCase__     	=					[self.bos_token_id] + token_ids_a + [self.eos_token_id]
        if token_ids_a is None:
               return output

        return output + [self.eos_token_id] + token_ids_a + [self.eos_token_id]




 def 		__snake_case						(			self					:  Optional[int]			,    lowercase__					:  List[int]			,    lowercase__					:  Optional[List[int]] = None):







        '''simple docstring'''



        lowerCAmelCase__     	=					[self.sep_token_id]
        lowerCAmelCase__     	=					[self.cls_token_id]

        if token_ids_a is None:
               return len(cls + token_ids_a + sep) * [0]
        return len(cls + token_ids_a + sep + sep + token_ids_a + sep) * [0]




 def 		__snake_case						(			self					:  Tuple			,    lowercase__					:  str			,    lowercase__					:  Optional[str] = None):







        '''simple docstring'''



        lowerCAmelCase__     	=					self._tokenizer.model.save(lowercase__			,    name=lowercase__)
        return tuple(lowercase__)
