See our collection for all versions of RoBERTa.

Run RoBERTa with Keras 3: JAX, PyTorch, or TensorFlow

GitHub Docs Collection

kerasformers/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 kerasformers. 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 kerasformers.models.roberta import RobertaMaskedLM, RobertaTokenizer

mlm = RobertaMaskedLM.from_weights("kerasformers/roberta_base")
tokenizer = RobertaTokenizer.from_weights("kerasformers/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("kerasformers/<variant>"):

Variant Hub
roberta_base kerasformers/roberta_base
roberta_large kerasformers/roberta_large

Tips

  • Set KERAS_BACKEND before importing Keras / kerasformers.
  • 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.

Downloads last month
-
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for kerasformers/roberta_base

Finetuned
(2376)
this model

Collection including kerasformers/roberta_base

Paper for kerasformers/roberta_base