--- pipeline_tag: fill-mask license: mit base_model: FacebookAI/roberta-large library_name: kerasformers tags: - keras - kerasformers - roberta - fill-mask - text-encoder - arxiv:1907.11692 - pytorch - jax - tf --- ## ***See [our collection](https://huggingface.co/collections/kerasformers/roberta-6a6e8d9b2f4c9253f4145f65) for all versions of RoBERTa.*** # Run RoBERTa with Keras 3: JAX, PyTorch, or TensorFlow [![GitHub](https://img.shields.io/badge/GitHub-KerasFormers-black?logo=github)](https://github.com/IMvision12/KerasFormers) [![Docs](https://img.shields.io/badge/Docs-RoBERTa-blue)](https://imvision12.github.io/KerasFormers/roberta/) [![Collection](https://img.shields.io/badge/HF-RoBERTa%20collection-yellow)](https://huggingface.co/collections/kerasformers/roberta-6a6e8d9b2f4c9253f4145f65) # kerasformers/roberta_large Paper: [RoBERTa: A Robustly Optimized BERT Pretraining Approach (arXiv:1907.11692)](https://arxiv.org/abs/1907.11692) · [HF Papers](https://huggingface.co/papers/1907.11692) RoBERTa is a robustly optimized BERT encoder: more data/steps, no NSP, dynamic masking, byte-level BPE (mask token ``), and padding-offset position ids. For more details on the model, please go to the upstream [model card](https://huggingface.co/FacebookAI/roberta-large). Pure-**Keras 3** conversion of [`FacebookAI/roberta-large`](https://huggingface.co/FacebookAI/roberta-large) for [kerasformers](https://github.com/IMvision12/KerasFormers). One implementation runs unmodified on **TensorFlow / Torch / JAX**. This is a **fill-mask / encoder** checkpoint (`RobertaMaskedLM`, large). Task heads load via `hf:` fine-tunes. ## ✨ Quick start (fill-mask) ```python import os os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow" from kerasformers.models.roberta import RobertaMaskedLM, RobertaTokenizer mlm = RobertaMaskedLM.from_weights("kerasformers/roberta_large") tokenizer = RobertaTokenizer.from_weights("kerasformers/roberta_large") inputs = tokenizer("The capital of France is .") 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 | Hub | |---|---| | `roberta_base` | [`kerasformers/roberta_base`](https://huggingface.co/kerasformers/roberta_base) | | `roberta_large` | [`kerasformers/roberta_large`](https://huggingface.co/kerasformers/roberta_large) | ## Tips - Set `KERAS_BACKEND` **before** importing Keras / kerasformers. - Prefer `RobertaTokenizer.from_weights(...)` so BPE vocab matches. - Use `` (not `[MASK]`). - See [RoBERTa docs](https://imvision12.github.io/KerasFormers/roberta/) and [Loading Weights](https://imvision12.github.io/KerasFormers/loading_weights/). - Community / upstream safetensors still work via the `hf:` prefix, e.g. `RobertaMaskedLM.from_weights("hf:FacebookAI/roberta-large")`. ## Special Thanks A huge thank you to the Facebook AI RoBERTa authors for creating and releasing these models. License: MIT.