Instructions to use zeromodels/roberta_base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- ZeroModels
How to use zeromodels/roberta_base 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/roberta_base") - Keras
How to use zeromodels/roberta_base 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/roberta_base") - Notebooks
- Google Colab
- Kaggle
Download README.md from zeromodels/roberta_base: direct link, hf CLI and curl.
- Browser
- Download file 3.86 kB
-
https://huggingface.co/zeromodels/roberta_base/resolve/main/README.md
- Command line
-
hf download hf://zeromodels/roberta_base/README.md
-
curl -L -o README.md https://huggingface.co/zeromodels/roberta_base/resolve/main/README.md
pipeline_tag: fill-mask
license: mit
base_model: FacebookAI/roberta-base
library_name: zeromodels
tags:
- keras
- zeromodels
- roberta
- fill-mask
- text-encoder
- arxiv:1907.11692
- pytorch
- jax
- tf
See our collection for all versions of RoBERTa.
Run RoBERTa with Keras 3: JAX, PyTorch, or TensorFlow
zeromodels/roberta_base
Paper: RoBERTa: A Robustly Optimized BERT Pretraining Approach (arXiv:1907.11692) · HF Papers
RoBERTa is a robustly optimized BERT encoder: more data/steps, no NSP, dynamic masking, byte-level BPE (mask token <mask>), and padding-offset position ids.
For more details on the model, please go to the upstream model card.
Pure-Keras 3 conversion of FacebookAI/roberta-base for zeromodels. One implementation runs unmodified on TensorFlow / Torch / JAX.
This is a fill-mask / encoder checkpoint (RobertaMaskedLM, base). Task heads load via hf: fine-tunes.
✨ Quick start (fill-mask)
import os
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
from zeromodels.models.roberta import RobertaMaskedLM, RobertaTokenizer
mlm = RobertaMaskedLM.from_weights("zeromodels/roberta_base")
tokenizer = RobertaTokenizer.from_weights("zeromodels/roberta_base")
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 RoBERTa variant the same way with from_weights("zeromodels/<variant>"):
| Variant | Hub |
|---|---|
roberta_base |
zeromodels/roberta_base |
roberta_large |
zeromodels/roberta_large |
Available classes
Load any of these from this repo with from_weights("zeromodels/roberta_base") (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 |
|---|---|
RobertaModel |
Encoder backbone |
RobertaMaskedLM |
Masked language modeling (fill-mask) |
RobertaSequenceClassify |
Sequence classification |
RobertaTokenClassify |
Token classification (NER / POS) |
RobertaQnA |
Extractive question answering |
RobertaMultipleChoice |
Multiple choice |
from zeromodels.models.roberta import RobertaSequenceClassify
model = RobertaSequenceClassify.from_weights("zeromodels/roberta_base")
Tips
- Set
KERAS_BACKENDbefore importing Keras / zeromodels. - Prefer
RobertaTokenizer.from_weights(...)so BPE vocab matches. - Use
<mask>(not[MASK]). - See RoBERTa docs and Loading Weights.
- Community / upstream safetensors still work via the
hf:prefix, e.g.RobertaMaskedLM.from_weights("hf:FacebookAI/roberta-base").
Special Thanks
A huge thank you to the Facebook AI RoBERTa authors for creating and releasing these models.
License: MIT.