


'''simple docstring'''







import math

import tensorflow as tf
from packaging import version






def       lowercase					(_A       ):







       """simple docstring"""







       _lowerCAmelCase     :				Tuple       =							tf.convert_to_tensor(_A       )
       _lowerCAmelCase     :				Union[str, Any]       =							0.5 * (1.0 + tf.math.erf(x / tf.cast(tf.sqrt(2.0       ) ,    x.dtype       )       ))

       return x * cdf






def       lowercase					(_A       ):







       """simple docstring"""







       _lowerCAmelCase     :				List[str]       =							tf.convert_to_tensor(_A       )
       _lowerCAmelCase     :				Optional[Any]       =							tf.cast(math.pi ,    x.dtype       )
       _lowerCAmelCase     :				List[Any]       =							tf.cast(0.044_715 ,    x.dtype       )
       _lowerCAmelCase     :				Tuple       =							0.5 * (1.0 + tf.tanh(tf.sqrt(2.0 / pi       ) * (x + coeff * tf.pow(_A ,    3       ))       ))

       return x * cdf






def       lowercase					(_A       ):







       """simple docstring"""







       _lowerCAmelCase     :				str       =							tf.convert_to_tensor(_A       )

       return x * tf.tanh(tf.math.softplus(_A       )       )






def       lowercase					(_A       ):







       """simple docstring"""







       _lowerCAmelCase     :				int       =							tf.convert_to_tensor(_A       )
       _lowerCAmelCase     :				Any       =							tf.cast(0.044_715 ,    x.dtype       )
       _lowerCAmelCase     :				Any       =							tf.cast(0.7_978_845_608 ,    x.dtype       )

       return 0.5 * x * (1.0 + tf.tanh(x * coeffa * (1.0 + coeffa * x * x)       ))






def       lowercase					(_A       ):







       """simple docstring"""







       _lowerCAmelCase     :				str       =							tf.convert_to_tensor(_A       )
       _lowerCAmelCase     :				int       =							tf.cast(1.702 ,    x.dtype       )
       return x * tf.math.sigmoid(coeff * x       )






def       lowercase					(_A       ):







       """simple docstring"""







       return tf.clip_by_value(_gelu(_A       ) ,    -1_0 ,    1_0       )






def       lowercase					(_A ,    _A=-1       ):







       """simple docstring"""







       _lowerCAmelCase      ,  _lowerCAmelCase     :				List[Any]       =							tf.split(_A ,    2 ,    axis=_A       )
       return a * tf.math.sigmoid(_A       )


if version.parse(tf.version.VERSION) >= version.parse("""2.4"""):






       def       lowercase					(_A       ):







              """simple docstring"""







              return tf.keras.activations.gelu(_A ,    approximate=_A       )

       lowerCAmelCase     :  str											=    tf.keras.activations.gelu
       lowerCAmelCase     :  Optional[int]											=    approximate_gelu_wrap
else:
       lowerCAmelCase     :  int											=    _gelu
       lowerCAmelCase     :  str											=    _gelu_new


lowerCAmelCase     :  Any											=    {
    """gelu""": gelu,
    """gelu_10""": gelu_aa,
    """gelu_fast""": gelu_fast,
    """gelu_new""": gelu_new,
    """glu""": glu,
    """mish""": mish,
    """quick_gelu""": quick_gelu,
    """relu""": tf.keras.activations.relu,
    """sigmoid""": tf.keras.activations.sigmoid,
    """silu""": tf.keras.activations.swish,
    """swish""": tf.keras.activations.swish,
    """tanh""": tf.keras.activations.tanh,
}






def       lowercase					(_A       ):







       """simple docstring"""







       if activation_string in ACTaFN:
              return ACTaFN[activation_string]
       else:
              raise KeyError(f'function {activation_string} not found in ACT2FN mapping {list(ACTaFN.keys()       )}'       )





'''simple docstring'''







from typing import TYPE_CHECKING

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


lowerCAmelCase     :  List[str]											=    {
    """configuration_electra""": ["""ELECTRA_PRETRAINED_CONFIG_ARCHIVE_MAP""", """ElectraConfig""", """ElectraOnnxConfig"""],
    """tokenization_electra""": ["""ElectraTokenizer"""],
}

try:
       if not is_tokenizers_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       lowerCAmelCase     :  Optional[Any]											=    ["""ElectraTokenizerFast"""]

try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       lowerCAmelCase     :  str											=    [
           """ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST""",
           """ElectraForCausalLM""",
           """ElectraForMaskedLM""",
           """ElectraForMultipleChoice""",
           """ElectraForPreTraining""",
           """ElectraForQuestionAnswering""",
           """ElectraForSequenceClassification""",
           """ElectraForTokenClassification""",
           """ElectraModel""",
           """ElectraPreTrainedModel""",
           """load_tf_weights_in_electra""",
       ]

try:
       if not is_tf_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       lowerCAmelCase     :  Tuple											=    [
           """TF_ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST""",
           """TFElectraForMaskedLM""",
           """TFElectraForMultipleChoice""",
           """TFElectraForPreTraining""",
           """TFElectraForQuestionAnswering""",
           """TFElectraForSequenceClassification""",
           """TFElectraForTokenClassification""",
           """TFElectraModel""",
           """TFElectraPreTrainedModel""",
       ]

try:
       if not is_flax_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       lowerCAmelCase     :  Union[str, Any]											=    [
           """FlaxElectraForCausalLM""",
           """FlaxElectraForMaskedLM""",
           """FlaxElectraForMultipleChoice""",
           """FlaxElectraForPreTraining""",
           """FlaxElectraForQuestionAnswering""",
           """FlaxElectraForSequenceClassification""",
           """FlaxElectraForTokenClassification""",
           """FlaxElectraModel""",
           """FlaxElectraPreTrainedModel""",
       ]


if TYPE_CHECKING:
       from .configuration_electra import ELECTRA_PRETRAINED_CONFIG_ARCHIVE_MAP, ElectraConfig, ElectraOnnxConfig
       from .tokenization_electra import ElectraTokenizer

       try:
              if not is_tokenizers_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .tokenization_electra_fast import ElectraTokenizerFast

       try:
              if not is_torch_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_electra import (
                  ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST,
                  ElectraForCausalLM,
                  ElectraForMaskedLM,
                  ElectraForMultipleChoice,
                  ElectraForPreTraining,
                  ElectraForQuestionAnswering,
                  ElectraForSequenceClassification,
                  ElectraForTokenClassification,
                  ElectraModel,
                  ElectraPreTrainedModel,
                  load_tf_weights_in_electra,
              )

       try:
              if not is_tf_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_tf_electra import (
                  TF_ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST,
                  TFElectraForMaskedLM,
                  TFElectraForMultipleChoice,
                  TFElectraForPreTraining,
                  TFElectraForQuestionAnswering,
                  TFElectraForSequenceClassification,
                  TFElectraForTokenClassification,
                  TFElectraModel,
                  TFElectraPreTrainedModel,
              )

       try:
              if not is_flax_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_flax_electra import (
                  FlaxElectraForCausalLM,
                  FlaxElectraForMaskedLM,
                  FlaxElectraForMultipleChoice,
                  FlaxElectraForPreTraining,
                  FlaxElectraForQuestionAnswering,
                  FlaxElectraForSequenceClassification,
                  FlaxElectraForTokenClassification,
                  FlaxElectraModel,
                  FlaxElectraPreTrainedModel,
              )

else:
       import sys

       lowerCAmelCase     :  int											=    _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)

