Instructions to use zeromodels/electra_base_generator with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- ZeroModels
How to use zeromodels/electra_base_generator with ZeroModels:
# pip install -U zeromodels # ZeroModels is pure Keras 3, so pick a backend: "jax", "torch" or "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" from zeromodels import AutoZModel # AutoZModel reads the repo's model_type and loads the matching class. # For a task head use the matching loader, e.g. AutoZMImageClassify / AutoZMDetect / # AutoZMSemanticSegment / AutoZMTextGenerate (see zeromodels.auto). model = AutoZModel.from_weights("zeromodels/electra_base_generator") - Keras
How to use zeromodels/electra_base_generator with Keras:
# !pip install -U keras tensorflow huggingface_hub # Keras needs TensorFlow installed to read "hf://" paths, so the tensorflow backend is selected here; # "jax" and "torch" also work for computation once TensorFlow is installed. import os os.environ["KERAS_BACKEND"] = "tensorflow" import keras model = keras.saving.load_model("hf://zeromodels/electra_base_generator") - Notebooks
- Google Colab
- Kaggle
|
Download README.md from zeromodels/electra_base_generator: direct link, hf CLI and curl.
- Browser
- Download file 4.34 kB
-
https://huggingface.co/zeromodels/electra_base_generator/resolve/main/README.md
- Command line
-
hf download hf://zeromodels/electra_base_generator/README.md
-
curl -L -o README.md https://huggingface.co/zeromodels/electra_base_generator/resolve/main/README.md
4.34 kB
| pipeline_tag: fill-mask | |
| license: apache-2.0 | |
| base_model: google/electra-base-generator | |
| library_name: zeromodels | |
| tags: | |
| - keras | |
| - zeromodels | |
| - electra | |
| - generator | |
| - text-encoder | |
| - fill-mask | |
| - arxiv:2003.10555 | |
| - pytorch | |
| - jax | |
| - tf | |
| ## ***See [our collection](https://huggingface.co/collections/zeromodels/electra-6a8eadf9dc472c12a679ebba) for all versions of ELECTRA.*** | |
| # Run ELECTRA with Keras 3: JAX, PyTorch, or TensorFlow | |
| [](https://github.com/IMvision12/ZeroModels) [](https://imvision12.github.io/ZeroModels/electra/) [](https://huggingface.co/collections/zeromodels/electra-6a8eadf9dc472c12a679ebba) | |
| # zeromodels/electra_base_generator | |
| 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 **masked-LM (fill-mask)** checkpoint. WordPiece tokenizer; mask token `[MASK]`. | |
| For more details on the model, please go to the upstream [model card](https://huggingface.co/google/electra-base-generator). | |
| Pure-**Keras 3** conversion of [`google/electra-base-generator`](https://huggingface.co/google/electra-base-generator) for [zeromodels](https://github.com/IMvision12/ZeroModels). One implementation runs unmodified on **TensorFlow / Torch / JAX**. | |
| ## ✨ Quick start (masked-LM (fill-mask)) | |
| ```python | |
| import os | |
| os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow" | |
| from zeromodels.models.electra import ElectraMaskedLM, ElectraTokenizer | |
| mlm = ElectraMaskedLM.from_weights("zeromodels/electra_base_generator") | |
| tokenizer = ElectraTokenizer.from_weights("zeromodels/electra_base_generator") | |
| inputs = tokenizer("The capital of France is [MASK].") | |
| logits = mlm(inputs) # (1, L, vocab_size) | |
| mask = int((inputs["input_ids"][0] == tokenizer.mask_token_id).argmax()) | |
| print(tokenizer.decode([int(logits[0, mask].argmax())])) | |
| ``` | |
| Load any ELECTRA variant the same way with `from_weights("zeromodels/<variant>")`: | |
| | Size | Discriminator (encoder / downstream) | Generator (masked-LM) | | |
| |---|---|---| | |
| | small | [`zeromodels/electra_small_discriminator`](https://huggingface.co/zeromodels/electra_small_discriminator) | [`zeromodels/electra_small_generator`](https://huggingface.co/zeromodels/electra_small_generator) | | |
| | base | [`zeromodels/electra_base_discriminator`](https://huggingface.co/zeromodels/electra_base_discriminator) | [`zeromodels/electra_base_generator`](https://huggingface.co/zeromodels/electra_base_generator) | | |
| | large | [`zeromodels/electra_large_discriminator`](https://huggingface.co/zeromodels/electra_large_discriminator) | [`zeromodels/electra_large_generator`](https://huggingface.co/zeromodels/electra_large_generator) | | |
| ## Available classes | |
| Load any of these from this repo with `from_weights("zeromodels/electra_base_generator")` (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 | | |
| |---|---| | |
| | `ElectraMaskedLM` | Masked language modeling (fill-mask) | | |
| ```python | |
| from zeromodels.models.electra import ElectraMaskedLM | |
| model = ElectraMaskedLM.from_weights("zeromodels/electra_base_generator") | |
| ``` | |
| ## Tips | |
| - Set `KERAS_BACKEND` **before** importing Keras / zeromodels. | |
| - 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/ZeroModels/electra/) and [Loading Weights](https://imvision12.github.io/ZeroModels/loading_weights/). | |
| - Community / upstream safetensors still work via the `hf:` prefix, e.g. `ElectraModel.from_weights("hf:google/electra-base-generator")`. | |
| ## Special Thanks | |
| A huge thank you to the Google ELECTRA authors for creating and releasing these models. | |
| License: Apache 2.0. | |