Instructions to use zeromodels/electra_small_discriminator with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- KerasFormers
How to use zeromodels/electra_small_discriminator with KerasFormers:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Keras
How to use zeromodels/electra_small_discriminator with Keras:
# Available backend options are: "jax", "torch", "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" import keras model = keras.saving.load_model("hf://zeromodels/electra_small_discriminator") - Notebooks
- Google Colab
- Kaggle
| pipeline_tag: feature-extraction | |
| license: apache-2.0 | |
| base_model: google/electra-small-discriminator | |
| library_name: kerasformers | |
| tags: | |
| - keras | |
| - kerasformers | |
| - electra | |
| - discriminator | |
| - text-encoder | |
| - feature-extraction | |
| - arxiv:2003.10555 | |
| - pytorch | |
| - jax | |
| - tf | |
| ## ***See [our collection](https://huggingface.co/collections/kerasformers/electra-6a8540d1f5831e07dc89d8d1) for all versions of ELECTRA.*** | |
| # Run ELECTRA with Keras 3: JAX, PyTorch, or TensorFlow | |
| [](https://github.com/IMvision12/KerasFormers) [](https://imvision12.github.io/KerasFormers/electra/) [](https://huggingface.co/collections/kerasformers/electra-6a8540d1f5831e07dc89d8d1) | |
| # kerasformers/electra_small_discriminator | |
| Paper: [ELECTRA: Pre-training Text Encoders as Discriminators Rather Than Generators (arXiv:2003.10555)](https://arxiv.org/abs/2003.10555) · [HF Papers](https://huggingface.co/papers/2003.10555) | |
| ELECTRA is Google's BERT-style bidirectional text encoder, pre-trained as a replaced-token **discriminator** (with a smaller **generator** producing the corrupted tokens). This repo is the **encoder / downstream** checkpoint. WordPiece tokenizer; mask token `[MASK]`. | |
| For more details on the model, please go to the upstream [model card](https://huggingface.co/google/electra-small-discriminator). | |
| Pure-**Keras 3** conversion of [`google/electra-small-discriminator`](https://huggingface.co/google/electra-small-discriminator) for [kerasformers](https://github.com/IMvision12/KerasFormers). One implementation runs unmodified on **TensorFlow / Torch / JAX**. | |
| ## ✨ Quick start (encoder / downstream) | |
| ```python | |
| import os | |
| os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow" | |
| from kerasformers.models.electra import ElectraModel, ElectraTokenizer | |
| model = ElectraModel.from_weights("kerasformers/electra_small_discriminator") | |
| tokenizer = ElectraTokenizer.from_weights("kerasformers/electra_small_discriminator") | |
| out = model(tokenizer("The quick brown fox."))["last_hidden_state"] # (1, L, H) | |
| ``` | |
| The same repo also serves the task heads, loaded the same way: `ElectraSequenceClassify`, `ElectraTokenClassify`, `ElectraQnA`, `ElectraMultipleChoice` (each takes the pretrained encoder and a randomly-initialized head, ready for fine-tuning). | |
| Load any ELECTRA variant the same way with `from_weights("kerasformers/<variant>")`: | |
| | Size | Discriminator (encoder / downstream) | Generator (masked-LM) | | |
| |---|---|---| | |
| | small | [`kerasformers/electra_small_discriminator`](https://huggingface.co/kerasformers/electra_small_discriminator) | [`kerasformers/electra_small_generator`](https://huggingface.co/kerasformers/electra_small_generator) | | |
| | base | [`kerasformers/electra_base_discriminator`](https://huggingface.co/kerasformers/electra_base_discriminator) | [`kerasformers/electra_base_generator`](https://huggingface.co/kerasformers/electra_base_generator) | | |
| | large | [`kerasformers/electra_large_discriminator`](https://huggingface.co/kerasformers/electra_large_discriminator) | [`kerasformers/electra_large_generator`](https://huggingface.co/kerasformers/electra_large_generator) | | |
| ## Available classes | |
| Load any of these from this repo with `from_weights("kerasformers/electra_small_discriminator")` (or on the fly via the `hf:` prefix). The pretrained backbone is shared; task heads not stored in this checkpoint start randomly initialized, ready for fine-tuning (or load a `hf:` fine-tune). | |
| | Class | Task | | |
| |---|---| | |
| | `ElectraModel` | Encoder backbone | | |
| | `ElectraSequenceClassify` | Sequence classification | | |
| | `ElectraTokenClassify` | Token classification (NER / POS) | | |
| | `ElectraQnA` | Extractive question answering | | |
| | `ElectraMultipleChoice` | Multiple choice | | |
| ```python | |
| from kerasformers.models.electra import ElectraSequenceClassify | |
| model = ElectraSequenceClassify.from_weights("kerasformers/electra_small_discriminator") | |
| ``` | |
| ## Tips | |
| - Set `KERAS_BACKEND` **before** importing Keras / kerasformers. | |
| - Prefer `ElectraTokenizer.from_weights(...)` so WordPiece tokenization matches. | |
| - Downstream tasks (classification / QA / NER) use the **discriminator** repos; the **generator** repos are the masked-LM. | |
| - See [ELECTRA docs](https://imvision12.github.io/KerasFormers/electra/) and [Loading Weights](https://imvision12.github.io/KerasFormers/loading_weights/). | |
| - Community / upstream safetensors still work via the `hf:` prefix, e.g. `ElectraModel.from_weights("hf:google/electra-small-discriminator")`. | |
| ## Special Thanks | |
| A huge thank you to the Google ELECTRA authors for creating and releasing these models. | |
| License: Apache 2.0. | |